Reputation: 1384
Can anyone tell me why this will not return show.blade.php data?
ROUTE
Route::resource('news', 'NewsController', ['except' => ['create', 'store', 'edit', 'update', 'destroy']]);
MODEL
public function categories()
{
return $this->belongsToMany(ContentCategory::class);
}
public function tags()
{
return $this->belongsToMany(ContentTag::class);
}
CONTROLLER
public function show(News $news)
{
$news->load('categories', 'tags', 'product_press_releases', 'section');
return view('site.news.show', compact('news'));
}
VIEW show.blade.php
@section('content')
{{ $news->title ?? '' }}
{{ $news->id ?? '' }}
@foreach($news->categories as $key => $category)
<span class="label label-info">{{ $category->name }}</span>
@endforeach
@endcontent
For the life of me I cannot get why no data is being returned. I do these all the time and never ran into this.
Upvotes: 0
Views: 65
Reputation: 835
I believe that your are not extending it to app.blade.php
.
Add - @extends('YOUR_APP_LINK')
.
In your case -
@extends('YOUR_APP_LINK')
@section('content')
{{ $news->title ?? '' }}
{{ $news->id ?? '' }}
@foreach($news->categories as $key => $category)
<span class="label label-info">{{ $category->name }}</span>
@endforeach
@endcontent
Hope this will help you.
Upvotes: 1