dakim236
dakim236

Reputation: 75

How to create multiple route with laravel 5.8

I'm using version 5.8 of laravel and I'm trying to initialize the routes. It is not possible to access the route created after the default route:

Route::get('/', function () {
    return view('welcome');
});

I try to add a parameter in the second route:

Route::get('/page', ['as' => 'home', function (/page) {return view('page1') ;}]);

I got 404 error. How can I use multiple routes ?

This is my web.php file:

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/page', function() { return view('page1'); })->name('home');
Route::get('/', function () {
    return view('welcome');
});

Upvotes: 0

Views: 272

Answers (1)

nakov
nakov

Reputation: 14268

Did you copied the second route, or what are you trying to do with this?

You can try this one instead as your syntax is wrong:

Route::get('/page', function() { return view('page1'); })->name('home');

-- EDIT

You can also return just the views from your routes if you don't plan to use a controller, like this:

Route::view('/', 'welcome');
Route::view('/page', 'page1');

Upvotes: 1

Related Questions