Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
310 views
in Technique[技术] by (71.8m points)

php - 如何从Laravel 6中的包覆盖应用路由(How to override an app route from a package in Laravel 6)

I am attempting to create a composer package for Laravel 6 but I can not get my main route / to override the default / route included with the base Laravel installation.

(我正在尝试为Laravel 6创建一个composer软件包,但是我无法获取主路径/来覆盖基本Laravel安装中包含的默认/路径。)

My package route does works when I comment out the base / route provided by laravel so it is being registered by the package.

(当我注释掉laravel提供的基础/路由时,我的包裹路线确实有效,因此包裹正在对其进行注册。)

It doesn't make any different if I include my package's service provider before or after the RouteServiceProvider in the config/app.php file.

(如果我在config/app.php文件中的RouteServiceProvider之前或之后包含程序包的服务提供程序,则没有什么不同。)

What am I missing here?

(我在这里想念什么?)

How do I ensure my package routes have priority?

(如何确保包裹路线优先?)

Here are the relevant bits of code:

(以下是相关的代码位:)

config/app.php

/*
 * Application Service Providers...
 */
AppProvidersAppServiceProvider::class,
AppProvidersAuthServiceProvider::class,
// AppProvidersBroadcastServiceProvider::class,
AppProvidersEventServiceProvider::class,
WheelmakerLaravueSpaLaravueSpaServiceProvider::class,  // MY SERVICE PROVIDER
AppProvidersRouteServiceProvider::class,

The relevant section of LaravueSpaServiceProvider

(LaravueSpaServiceProvider的相关部分)

public function boot()
{
  $this->loadRoutesFrom(__DIR__.'/routes/web.php');
  ...
}

My Package's web.php route file:

(我的包裹的web.php路由文件:)

<?php
Route::get('/', function(){
  $initData = [
    'appName' => config('app.name'),
    'user' => Auth::user(),
];
  return view('laravue-spa::app', compact('initData'));
})->middleware(['web']);
  ask by wheelmaker translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...