Alexander Solonik
Alexander Solonik

Reputation: 10250

Route not defined error in laravel , even though route is defined

I have the followning method in my controller:

public function showQualityResult($qualityData) {
        return $qualityData;
}

When clicked on a link , i want that method to be invoked , so i have the following in my view file:

<a href="{{ route('showQualityResult' , Session::get('quality-data')) }}">Submited Quality Check</a>

Also, I have the following route setup:

Route::get('/showQualityResult', 'QualityCheckController@showQualityResult');

But having the below line of code:

<a href="{{ route('showQualityResult' , Session::get('quality-data')) }}">Submited Quality Check</a>

Does't really work , i get the following error in the frontEnd:

enter image description here

Now how can i solve this problem , and why am i getting this error of Route not defined , even though i have the route defined ??

Upvotes: 3

Views: 14161

Answers (3)

supernifty
supernifty

Reputation: 4281

In my case I had simply made a stupid mistake.

Further down in my code I had another named route (properly named with a unique name) but an identical path to the one Laravel told me it couldn't find.

A quick update to the path fixed it.

Upvotes: 0

Devon Bessemer
Devon Bessemer

Reputation: 35357

The route() helper looks for a named route, not the path.

https://laravel.com/docs/5.3/routing#named-routes

Route::get('/showQualityResult', 'QualityCheckController@showQualityResult')
    ->name('showQualityResult');

Should fix the issue for you.

Upvotes: 2

Alexey Mezenin
Alexey Mezenin

Reputation: 163968

route() helper uses route name to build URL, so you need to use it like this:

route('quality-result.show', session('quality-data'));

And set a name for the route:

Route::get('/showQualityResult', ['as' => 'quality-result.show', 'uses' => 'QualityCheckController@showQualityResult']);

Or:

Route::get('/showQualityResult', 'QualityCheckController@showQualityResult')->name('quality-result.show');

The route function generates a URL for the given named route

https://laravel.com/docs/5.3/routing#named-routes

If you don't want to use route names, use url() instead of route()

Upvotes: 6

Related Questions