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);



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire