路线重定向到错误的页面

时间:2020-08-05 20:09:27

标签: php laravel laravel-5 eloquent

我正在使用Laravel 5,并且已经为所有页面设置了路由。我有一个带有某些图标的仪表板,单击该图标可将其重定向到其他页面。现在,当点击该特定图标“ Total Applications”时,它不会重定向到与之关联的页面,即total.blade.php,而是重定向到另一个页面候选人。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');

我的控制器包含“总计应用程序”页面的逻辑:-

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'));
}

1 个答案:

答案 0 :(得分:3)

好的。让我们解释一下

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而不是total.blade.php,您可以通过在{status}之前添加任何前缀来解决它

请注意,您调用的任何端点都将落入该路由/{status},因为该路由接受您将要命中的任何路径。