Cristian
Cristian

Reputation: 382

Is there a way to return a view from controller by his route name?

I have on my web.php this route

Route::get('/manager/posts/create', 'PostController@index')->name('createArticle');

is there a way to call this route from controller on return view instead of his route return view('manager.posts.crear');

something like return view('createArticle')?

Upvotes: 2

Views: 1602

Answers (3)

Jesus Galvan
Jesus Galvan

Reputation: 576

You are looking for named routes:

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

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

Upvotes: 2

Davit Zeynalyan
Davit Zeynalyan

Reputation: 8618

Try this

use Illuminate\Support\Facades\Route;


public function index(Request $request)
{
    $routeName  = Route::currentRouteName();
    // or $routeName = $request->route()->getName();
    return view($routeName);
}

Upvotes: 2

Michał Haracewiat
Michał Haracewiat

Reputation: 488

Perhaps you're looking for view routes.

Upvotes: 1

Related Questions