路线重定向到错误的页面 [英] Route is redirecting to wrong page

查看:52
本文介绍了路线重定向到错误的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Laravel 5,并且已经为所有页面设置了路由.我有一个带有某些图标的仪表板,单击该图标可将其重定向到其他页面.现在,该特定图标"Total Applications"(总应用程序)是指单击时不重定向到与其关联的页面,即total.blade.php,而是重定向到另一个页面候选人.blade.php.

I'm working on Laravel 5 and I've set up the routes for all the pages. I have a dashboard that has certain icons which when clicked redirects to different pages. Now, this particular icon "Total Applications" is when clicked doesn't redirect to the page associated with it, i.e., total.blade.php but instead redirects to another page candidate.blade.php.

我是Laravel的新手.当我单击总应用程序"时,我想要页面,它应该重定向到为其指定的页面.

I'm new to Laravel. I want that when I click the "Total Applications" page it should redirect to the page designated for it.

我正在分享以下代码:

dashboard.blade.php文件:

dashboard.blade.php file:

<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 file containing routes for both the pages:-

Route::get('/total-applications', 'Frontend\EmployersController@totalApplications')->name('employers.total');
Route::get('/{status}', 'Frontend\EmployersController@candidatesDisplay')->name('employers.candidate');

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

My controller containing the logic for Total Applications page:-

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

此路由接受参数状态之类的

example.com/pending
example.com/active
example.com/suspended

total-applications 大概是什么?是的,这可能就是为什么不这样,所以路线会

what about total-applications could it be the parameter? yes it could be why not so the route will be

example.com/total-applications 重定向到 Frontend \ EmployersController @ candidatesDisplay ,从而导致 candidate.blade.php 而不是 total.blade.php ,您可以通过在 {status}

example.com/total-applications which redirects to Frontend\EmployersController@candidatesDisplay which leads to candidate.blade.php not total.blade.php you can solve it by adding any prefix before {status}

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

Note that any endpoint you call it will fall into that route /{status} as this route accepts any path you will hit.

这篇关于路线重定向到错误的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆