samedi 17 novembre 2018

Get specific columns using “only()” function in Laravel Eloquent

I have two tables user and post.

in my posts method I want to load users posts with custom fileds. none of below solutions dose not works

class UserController
{
  public function posts(User $user)
  {
    return $user->load(['username', 'name', 'posts.body' // solution one

    return $user->load(['username', 'name', 'posts'=>function($q){
       $q->select(['body']
   }])// solution two

Does anyone have a work around?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire