[英]Route is redirecting to wrong page
我正在研究 Laravel 5 並且我已經為所有頁面設置了路由。 我有一個儀表板,其中包含某些圖標,單擊這些圖標會重定向到不同的頁面。 現在,當單擊此特定圖標“Total Applications”時,它不會重定向到與其關聯的頁面,即total.blade.php,而是重定向到另一個頁面candidate.blade.php。
我是 Laravel 的新手。 我希望當我單擊“總應用程序”頁面時,它應該重定向到為其指定的頁面。
我正在分享以下代碼:
dashboard.blade.php 文件:
<div class="col-md-4">
<div class="single-dashboard-link card card-default p-3 text-center" onclick="location.href='{{route('employers.total')}}'">
<i class="fa fa-file-text font30"></i>
<h6>
{{ $user->employerJobApplications()->count() }} Total
</h6>
<p>
Applications
</p>
</div>
</div>
包含兩個頁面的路由的路由文件:-
Route::get('/total-applications', 'Frontend\EmployersController@totalApplications')->name('employers.total');
Route::get('/{status}', 'Frontend\EmployersController@candidatesDisplay')->name('employers.candidate');
我的 controller 包含 Total Applications 頁面的邏輯:-
public function totalApplications() {
if (!Auth::check()) {
session()->flash('error', 'Sorry !! You are not an authenticated Employer !!');
return back();
}
$user = Auth::user();
$user_id = $user->id;
$applicant = JobActivity::where('user_id',$user_id)->get();
return view('frontend.pages.employers.total', compact('user', 'applicant'));
}
好的。 讓我們解釋一下
Route::get('/{status}', 'Frontend\EmployersController@candidatesDisplay')->name('employers.candidate');
這條路線接受一個參數status
,如
example.com/pending
example.com/active
example.com/suspended
total-applications
怎么樣?它可能是參數嗎? 是的,這可能是為什么不這樣的路線
example.com/total-applications
重定向到Frontend\EmployersController@candidatesDisplay
candidate.blade.php
Candidate.blade.php not total.blade.php
您可以通過在{status}
之前添加任何前綴來解決它
請注意,您調用它的任何端點都將落入該路由/{status}
因為該路由接受您將命中的任何路徑。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.