Home > OS >  Laravel route returning error 404 when attempt is made to pass value to controller function
Laravel route returning error 404 when attempt is made to pass value to controller function

Time:05-05

I have a button in my blade like this

@can('customer_show')
                <a class = "btn btn-primary" href = "{{ route('admin.loan-applications.showCustView', $loanApplication->user_id) }}">
                    View Applicant 
                </a>
            @endcan

And this is the route:

Route::get('loan-applications/{loan_application}/showCustView', 'loanApplicationsController@showCust')->name('loan-applications.showCustView');

And in my controller, i did:

public function showCust(LoanApplication $loanApplication)
{
    
    
    $customerInformation = customerInfoModel::where('Cust_id', $loanApplication->user_id));
     
    return view('admin.loanApplictions.showCustView', compact(['customerInformation', 'loanApplication']));
}

What i am trying to do is fetch the row from the database attached to customerInfoModel where the the Cust_id field equals the loanApplication->user_id of the loan being viewed currently in the blade above. When the button "view Applicant" is hit, i get an error 404 page. Why is that so?

CodePudding user response:

Check it out the route list using this command

php artisan route:list

//this command will show all the routes in your application

If your route not listed on that route list checkout for routes with same Url on your route manually on routes file.

if you found change the url & use this command to clear cache

php artisan optimize:clear

i have found the comment of you on last answer. check out for route model binding . i think you have to add a

public function showCust( $loanApplicationCustId)
{
    
    $customerInformation = customerInfoModel::where('Cust_id', $loanApplicationCustId));
     
    return view('admin.loanApplictions.showCustView', compact(['customerInformation', 'loanApplication']));
}

It should be like this .. i hope it works for you...... else share your project git repo link

CodePudding user response:

I think it should be like following:

@can('customer_show')
                <a class = "btn btn-primary" href = "{{ route('loan-applications.showCustView', $loanApplication->user_id) }}">
                    View Applicant 
                </a>
            @endcan

try that

  • Related