Skip to content
Advertisement

Route is redirecting to wrong page

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.

I’m new to Laravel. I want that when I click the “Total Applications” page it should redirect to the page designated for it.

I’m sharing the codes below:

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', 'FrontendEmployersController@totalApplications')->name('employers.total');
Route::get('/{status}', 'FrontendEmployersController@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'));
}

Advertisement

Answer

Ok. let’s explain this

Route::get('/{status}', 'FrontendEmployersController@candidatesDisplay')->name('employers.candidate');

this route accepts a parameter status like

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

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

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

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

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement