当试图获得一篇文章的所有评论Article::first()
但first()
只带来我尝试使用的第一篇文章find()
时
$comments = Article::find()-> commentsArticle()->with('articles');
return Datatables::of($comments)
我收到错误,所以我如何传递一个值来查看一篇文章的所有评论,或者我有办法不使用find()
文章型号
class Article extends Model{
public $table = 'articles';
public function commentsArticle() {
return $this->hasMany('App\Comment');
}
}
控制器
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);
}
}
我得到的最后一个错误
ErrorException (E_DEPRECATED)
Non-static method Yajra\Datatables\Datatables::collection() should
not be called statically
我希望找到任何类似的想法或例子可以帮助我学习