Hi This is the content of the post (the paragraph inside). Thanks.
Nov 30, 2019
36
Level 1
Undefined variable Laravel
Hi guys!!
I am m having this annoying problem. Can anyone give a hand to sort out it?
This is my controller
class DashboardsController extends Controller
{
public function indexA()
{
return view('dashboards.admin-dashboard');
}
public function indexS()
{
$id = Auth::user()->id;
$courses = DB::table('registered__courses')->select('user_id')->where('user_id', '=', $id)->count();
$posts = Post::all();
return view('dashboards.student-dashboard', compact('id', 'courses', 'posts'));
}
public function indexT()
{
return view('dashboards.teacher-dashboard');
}
This is a fragment of the blade view
<div class="col-md-12">
<div class="card">
<div class="card-header">
<h3 class="card-title">Posts</h3>
</div>
<div class="card-body">
<div class="tab-content">
<div class="active tab-pane" id="activity">
<!-- Post -->
<!--forEACH-->
@foreach ($posts as $post)
<div class="post">
<div class="user-block">
<span class="username">
<a href="#">{{$post->title}} | {{$post->author}}</a>
</span>
<span class="description">{{optional($post->created_at)->format('d-m-Y')}}</span>
</div>
<!-- /.user-block -->
<p>
{{$post->content}}
</p>
</div>
@endforeach
</div>
</div>
</div>
</div>
</div>
</div>
</div>
And this is the routes
Route::group([
'prefix' => 'dashboard',
], function () {
Route::get('/admin', 'DashboardsController@indexA')
->name('dashboards.indexA');
Route::get('/teacher', 'DashboardsController@indexT')
->name('dashboards.indexT');
Route::get('/student', 'DashboardsController@indexS')
->name('dashboards.indexS');
});
I tried to pass al the variable to the view and I always have the same problem. ("Undefined variable"). Any sugestions?
Thank you very much.
Please or to participate in this conversation.