我试图使一个网页的网站,但我不能通过论证文章在考虑
我的控制器是:
public function single(Article $article)
{
$article->increment('viewCount');
$comments = $article->comments()->where('approved' , 1)->where('parent_id', 0)->latest()->with(['comments' => function($query) {$query->where('approved' , 1)->latest();}])->get();
return view('Home.articles.single' , compact('article' , 'comments'));
}我的观点是
<div class="subject_head">
<div class="subject_head--title"><h1 class="title">
{{$article->title}}
</h1>
</div>
</div>但是我不能通过文章标题。我的模型是
protected $table='articles';
protected $casts= [
'images'=>'array'
];
protected $fillable= ['title','slug','description','body','images','tags'];
public function comments()
{
return $this->morphMany(Comment::class, 'commentable');
}
public function user()
{
return $this->belongsTo(User::class);
}我通过了这个并且在使用的时候
$article->all()这传递了所有数据

但在使用时
$article->title此方法为null,并且在使用
dd($article)

发布于 2020-05-15 02:37:06
它已经改变了。
现在您需要将其作为数组名称=> 'James‘传递。
在你的情况下
public function single(Article $article)
{
$article->increment('viewCount');
$comments = $article->comments()->where('approved' , 1)->where('parent_id', 0)->latest()->with(['comments' => function($query) {$query->where('approved' , 1)->latest();}])->get();
return view('Home.articles.single' ,['article'=>$article,'comments'=$comments]));
}发布于 2020-05-15 14:15:34
我更改了路由
Route::get('/articles/{articleSlug}' , 'ArticleController@single');
Route::get('/series/{courseSlug}' , 'CourseController@single');至
Route::get('/articles/{article:Slug}' , 'ArticleController@single');
Route::get('/series/{course:Slug}' , 'CourseController@single');并解决了问题。
谢谢你们所有人。
https://stackoverflow.com/questions/61804738
复制相似问题