I am m having this annoying problem.
(我有这个烦人的问题。)
Can anyone give a hand to sort out it? (谁能帮忙解决一下吗?)
I read all posts and I cannot find the solution. (我阅读了所有帖子,但找不到解决方案。)
This is my controller
(这是我的控制器)
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
use Auth;
use DB;
use AppPost;
use AppRegisteredCourse;
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.
(这是刀片视图的一部分。)
The name of the view is dashboards.student-dashboard (视图的名称是dashboards.student-dashboard)
<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>
And these are 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").It seems like blocked the possibility to pass variable to the blade view. ((“未定义的变量”)。似乎阻止了将变量传递到刀片视图的可能性。)
What I did before:
(我之前做过的事情:)
1-dd($posts) It does not working, it appears the exception "Undefined variable: posts".
(1-dd($ posts)无效,出现“未定义变量:posts”异常。)
2- I remove the whole content of the blade file and I tried with a simple varible and it stills appearing the exception "Undefined variable". (2-我删除了刀片文件的全部内容,并尝试使用一个简单的变量,它仍然出现异常“ Undefined variable”。)
3- I ran php artisan view:clear and restarted the server. (3-我运行php artisan view:clear并重新启动服务器。)
Any sugestions?
(有任何建议吗?)
Thank you very much.
(非常感谢你。)
ask by Noel translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…