【发布时间】:2017-03-06 22:52:30
【问题描述】:
当尝试获取Article::first() 但first() 的一篇文章的所有评论时
只带第一篇文章
我尝试使用find() 像
$comments = Article::find()-> commentsArticle()->with('articles');
return Datatables::of($comments)
我得到错误,所以我如何传递一个值来查看一篇文章的所有 cmets
要么
我有办法不用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
我希望找到任何类似的想法或例子可以帮助我学习
【问题讨论】: