[开发人员,我在控制器上遇到问题,当我尝试访问斜线时,出现此错误get_the_recent_post(视图: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');
HomeController:
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
帮助开发人员,我在控制器上遇到问题,当我尝试访问斜线时,出现此错误get_the_recent_post(查看:C:\ xampp \ htdocs \ staging_project \ resources \ views \ index.blade ....
@@ SoulAiker请更改您的路线,然后点击示例:-路线:: get('/','HomeController @ index');如果此命令不起作用,则需要调试。