Привет, разработчики, у меня проблема с моим контроллером, когда я пытался получить доступ к маршруту sla sh, я получил эту ошибку get_the_recent_post (View: C: \ xampp \ htdocs \ staging_project \ resources \ views \ index.blade . php) эта ошибка возникает, когда моя учетная запись выходит из системы. однако, если мой аккаунт вошел в систему, ошибка не найдена.
Чтобы понять, если я захожу по этой ссылке http://localhost: 8000 / и мой аккаунт off я получил эту ошибку Неопределенная переменная: 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