dimanche 25 février 2018

give column name an alias when using with eloquent relation, query scope - Laravel 5+

I want to do something like below:

$output = Model::with(['Relation2' => function ($query) {

             // This does not work. I want to select only specific columns if possible and give them a alias name
             $query->select('col1 AS aliasName', 'col2 AS aliasName2'); 
             $query->where('col3', 'value3');

         }])->findOrFail($id);



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2F2GsaN
via IFTTT

Aucun commentaire:

Enregistrer un commentaire