Tuesday, April 11, 2017

Relationship using yajra/laravel-datatables

when try to get all comment for one Article with the name of user how write the comment everything is ok but there is error with name of user how write the comment

{ data: 'user.name', name: 'user.name'}

public function commentsForOneArticle($id){ $article = Article::with('user')->find($id); return Datatables::of(Comment::where('article_id', $article->id))->make(true); }

Article model

public function commentsArticle() { return $this->hasMany('App\Comment'); }

Comments model

public function usersName() { return $this->belongsTo('App\User'); }



via Mahdi

Advertisement