dousi1875 2019-07-12 14:47
浏览 257

如何使用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');
});
  • 写回答

2条回答 默认 最新

  • drzfnr0275 2019-07-12 14:50
    关注

    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');
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度