0

I've been tackling on Laravel and I haven't found a few answers to minor questions.

Is there anyway that in the model I can create ALIASES for columns?

If not, I've been trying a few variations for my queries but none seem to give me what I want.

public function getEditHeader($adhID){
    return View::make('adventures.editHeader')
        ->with('adventureheader', AdventureHeader::find($adhID)->select('adhID', 'adhTitle AS title', 'adhDescription AS description')->get())
        ->with('adventuretypes', AdventureType::orderBy('adtDescription')->lists('adtDescription', 'adtID'));
}

I've tried many variants but I feel like i'm not comprehending what I'm actually attempting with Laravel. I just want my queries to come out with alias because i dont have my tables prefix in the form's input names.

Filipe Picoito
  • 673
  • 6
  • 23

2 Answers2

1

Use the selectRaw method:

AdventureHeader::find($adhID)
               ->selectRaw('adhID, adhTitle AS title, adhDescription AS description')->get()
Joseph Silber
  • 214,931
  • 59
  • 362
  • 292
  • Hello Joseph. I'm actually out of time to test it, although a friend of mine sent me this: http://stackoverflow.com/questions/17174837/laravel-4-eloquent-column-alias Thank you for your answer I will try it tomorrow first chance I get and get back to this post. – Filipe Picoito Dec 09 '14 at 22:51
  • The link I provided is also correct. What I wanted was more in the lines of model so it is more correct than yours although yours is also a viable way, thank you so much for your contribution. – Filipe Picoito Dec 10 '14 at 22:09
0

Whoever is looking to achieve ALIASES please take a look into this link:

Laravel 4 Eloquent Column Alias

Community
  • 1
  • 1
Filipe Picoito
  • 673
  • 6
  • 23