sammyukavi
sammyukavi

Reputation: 1511

Laravel 5.4 route name not working

In my routes on web.php I have the following line

Route::get('/', 'DashboardController@create')->name('dashboard');

In my DashboardController.php I have a create function with the following line like I saw on a Laracast tutorial but it's not working.

return redirect()->dashboard();

I get the following error

(1/1) FatalThrowableError
Call to undefined method Illuminate\Routing\Redirector::dashboard()

What could I be doing wrong?

Upvotes: 2

Views: 1258

Answers (3)

Niket Joshi
Niket Joshi

Reputation: 738

Instead of:

return redirect()->dashboard();

Try:

return redirect()->route('your-route-name');

Upvotes: 0

Mr. Pyramid
Mr. Pyramid

Reputation: 3935

return redirect()->dashboard(); calls a method named as dashboard inside your controller and that's what error is saying

(1/1) FatalThrowableError

Call to undefined method Illuminate\Routing\Redirector::dashboard()

You need to call named routes like this

return redirect()->route('dashboard');

For deep insight always trust laravel docs

Upvotes: 0

qadirpervez
qadirpervez

Reputation: 174

You should use

return redirect()->route('dashboard');

this is the way to do it.

visit Named Routes for more info

Upvotes: 5

Related Questions