Filipe Picoito
Filipe Picoito

Reputation: 695

Laravel PHP ALIAS on Model?

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.

Upvotes: 0

Views: 180

Answers (2)

Filipe Picoito
Filipe Picoito

Reputation: 695

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

Laravel 4 Eloquent Column Alias

Upvotes: 0

Joseph Silber
Joseph Silber

Reputation: 220076

Use the selectRaw method:

AdventureHeader::find($adhID)
               ->selectRaw('adhID, adhTitle AS title, adhDescription AS description')->get()

Upvotes: 1

Related Questions