Hellow 開發(fā)人員,我的控制器有問題,當(dāng)我嘗試訪問斜杠路由時(shí),我收到了這個(gè)錯(cuò)誤 get_the_recent_post (View: C:\xampp\htdocs\staging_project\resources\views\index.blade.php) 當(dāng)我的帳戶已注銷。但是,如果我的帳戶已登錄,則沒有發(fā)現(xiàn)錯(cuò)誤。為了更好地理解,如果我訪問此鏈接http://localhost:8000/并且我的帳戶已關(guān)閉,我收到此錯(cuò)誤未定義變量:get_the_recent_post,但是如果我訪問我的帳戶,我在數(shù)據(jù)庫(kù)中獲取的數(shù)據(jù)正在顯示。目標(biāo):如果我的路由是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
3 回答
肥皂起泡泡
TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超6個(gè)贊
為了解決我的問題:
我注釋掉這個(gè)函數(shù)
// public function __construct()
// {
// $this->middleware('auth');
// }
楊魅力
TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超6個(gè)贊
只需像下面共享的代碼片段一樣更改您的路線。
Route::get('/', function () {
return redirect()->route('index');
});
茅侃侃
TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超22個(gè)贊
改變你的路線,然后點(diǎn)擊。
例子:-Route::get('/', 'HomeController@index');
如果這個(gè)不起作用,則需要調(diào)試。
- 3 回答
- 0 關(guān)注
- 139 瀏覽
添加回答
舉報(bào)
0/150
提交
取消
