DEV Community

Discussion on: Setting up Vue in Laravel 8

Collapse
 
mounirb profile image
Mounir Bennacer • Edited

Great article Graham,

there is room for improvement in your code. So instead of

php artisan make:controller PagesController
Enter fullscreen mode Exit fullscreen mode

you could use the invokable flag so you don't use the index

php artisan make:controller PagesController --invokable
Enter fullscreen mode Exit fullscreen mode

and then use this route:

Route::get('/{any?}', App\Http\Controllers\PagesController::class);
Enter fullscreen mode Exit fullscreen mode

it tells Laravel routing to respond to any route provided or nothing with the question mark "?" and responds with an invokable controller

//
    public function __invoke()
    {
        return view('welcome');
    }
Enter fullscreen mode Exit fullscreen mode

Great tutorial my friend.

Collapse
 
yfktn profile image
yfktn

Hi, I got an error with this code, because Laravel on the RouteServiceProvider, while reading web.php to get our Route, it has already set up the namespace for us.

So, for this code at web.php:

Route::get('/{any?}', App\Http\Controllers\PagesController::class);
Enter fullscreen mode Exit fullscreen mode

need change to:

Route::get('/{any?}', 'PagesController');
Enter fullscreen mode Exit fullscreen mode

Thank you for the invoke parameters information.

Collapse
 
grahammorby profile image
Graham Morby

Thank you, I'm always learning so I hope to help folks and in turn, learn myself, so I will differently try this way out!

Collapse
 
mounirb profile image
Mounir Bennacer

As i do my friend, we are all learning, we progress by sharing knowledge :)