Monday, March 6, 2017

Table Bring all comments for one article using yajra/laravel-datatables

when try to get all comment for one Article by Article::first() but first() Bring just the first article i try use find() like

$comments = Article::find()-> commentsArticle()->with('articles');
return Datatables::of($comments)

i get error so how i can Pass a value to view all comments for one article or my be there is way without using find()

Article model

class Article extends Model{

 public $table = 'articles';

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

 }

controller

enter code here

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Yajra\Datatables\Datatables;

use App\Article;
use App\Comment;


class CommentController extends Controller{


   public function commentsForOne Article()
  {
    $comments = Article::all()->commentsArticle->with('articles');

            return Datatables::of($comments)->make(true);
  }

}

last error i get

ErrorException (E_DEPRECATED)
Non-static method Yajra\Datatables\Datatables::collection() should       
not be called statically

I hope find any idea or example like that will help me to learn



via Mahdi

Advertisement