Hellow 开发人员,我的控制器有问题,当我尝试访问斜杠路由时,我收到了这个错误 get_the_recent_post (View: C:\xampp\htdocs\staging_project\resources\views\index.blade.php) 当我的帐户已注销。但是,如果我的帐户已登录,则没有发现错误。
为了更好地理解,如果我访问此链接http://localhost:8000/并且我的帐户已关闭,我收到此错误未定义变量:get_the_recent_post,但是如果我访问我的帐户,我在数据库中获取的数据正在显示。
目标:如果我的路由是http://localhost:8000/ 我的输出必须与http://localhost:8000/index上的相同
我的路线:
Route::get('/', function () {
return view('/index');
});
Route::get('/index', 'HomeController@index')->name('index');
家庭控制器:
/**
* Create a new controller instance.
*
* @return void
*/
// public function __construct()
// {
// $this->middleware('auth');
// }
/**
* Show the application dashboard.
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
{
$get_the_recent_post = DB::select('SELECT content_id,content_title,content_desc,when_created,content_author FROM icweb_content WHERE content_status = ? AND MONTH(when_created) = MONTH(CURDATE()) ORDER BY when_created DESC LIMIT 3',[
'Approved'
]);
$get_the_upcoming_event = DB::select('SELECT ic_content.content_id,content_title,content_desc,content_author,start_event,end_event,when_created FROM icweb_content as ic_content
WHERE content_status = ? AND start_event = CURDATE() AND end_event >= CURDATE() ORDER BY when_created DESC LIMIT 3
',[
'Approved'
]);
return view('/index')
->with('get_the_recent_post',$get_the_recent_post)
->with('get_the_upcoming_event',$get_the_upcoming_event);
}
index.blade.php:
@foreach($get_the_recent_post as $data_recent_post)
<a href="" style="text-decoration: none;">
<div style="line-height: 2px;">
<h5 class="card-title" style="font-weight: 500; font-size:13px; color:black;">{{$data_recent_post->content_title}}</h5>
<p class="card-text" style="color:#757a91; font-size:12px; font-weight: 500;">{{strip_tags($data_recent_post->content_desc)}} </p>
</div>
</a>
@endforeach
肥皂起泡泡
杨魅力
茅侃侃