一个laravel文件中创建多个应用
来源:互联网 发布:安卓输入法开发源码 编辑:程序博客网 时间:2024/05/16 07:44
服务器采用nginx
在nginx下配置路径
首先会找到laravel文件中的public下的index.php
这里重新创建一个admin(和public在同一个目录)文件,nginx配置路径到admin下的index.php文件,开始模拟在laravel中的另一个应用
将public下的所有文件复制到admin下,并修改index.php
$app = require_once __DIR__.'/../bootstrap/admin.app.php';
此时加载bootstrap下的admin.app.php文件
bootstrap下有app.php文件,复制并且重命名为admin.app.php
修改admin.app.php
$app = new App\Admin\Application(
realpath(__DIR__.'/../')
);
$app->loadEnvironmentFrom('.env.admin');
$app->singleton(
Illuminate\Contracts\Http\Kernel::class,
App\Http\Admin\Kernel::class
);
通过对这个文件的修改,我们与原来的app.php文件对比
原来的app.php文件:
$app = new Illuminate\Foundation\Application(
realpath(__DIR__.'/../')
);
$app->singleton(
Illuminate\Contracts\Http\Kernel::class,
App\Http\Kernel::class
);
因此我们需要在app目录下添加一个Admin文件,文件下建立继承Illuminate\Foundation\Application的类Application:
<?php
namespace App\Admin;
use Illuminate\Foundation\Application as LaravelApplication;
class Application extends LaravelApplication
{
/**
* Get the path to the public / web directory.
*
* @return string
*/
公共路径,用来区分访问的是admin还是public,可以在该路径下添加公共资源,css,js,imgaes等
public function publicPath()
{
return $this->basePath . DIRECTORY_SEPARATOR . 'admin';
}
/**
* Get the path to the application configuration files.
*
* @return string
*/
由此可发现应该在config目录下配置一份admin,和一份public/web目录
public function configPath()
{
return $this->basePath . DIRECTORY_SEPARATOR . 'config' .
DIRECTORY_SEPARATOR . 'admin';
}
/**
* Get the path to the language files.
*
* @return string
*/
由此可见resources下的lang也需要配置一个admin,一个public/web
public function langPath()
{
return $this->basePath . DIRECTORY_SEPARATOR . 'resources' .
DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . 'admin';
}
/**
* Get the path to the storage directory.
*
* @return string
*/
storage目录下需要配置admin和web
public function storagePath()
{
return $this->storagePath ?: $this->basePath . DIRECTORY_SEPARATOR . 'storage' .
DIRECTORY_SEPARATOR . 'admin';
}
/**
* Get the path to the configuration cache file.
*
* @return string
*/
public function getCachedConfigPath()
{
return $this->basePath().'/bootstrap/admin/cache/config.php';
}
/**
* Get the path to the routes cache file.
*
* @return string
*/
public function getCachedRoutesPath()
{
return $this->basePath().'/bootstrap/admin/cache/routes.php';
}
/**
* Get the path to the cached "compiled.php" file.
*
* @return string
*/
public function getCachedCompilePath()
{
return $this->basePath().'/bootstrap/admin/cache/compiled.php';
}
/**
* Get the path to the cached services.json file.
*
* @return string
*/
public function getCachedServicesPath()
{
return $this->basePath().'/bootstrap/admin/cache/services.json';
}
}
同时在http下添加Admin文件,建立Kernel.php文件:
复制原有的Kernel.php文件,该文件包含了middleware的路径,admin与public不同
因为不同应用之间的serviceProvider有所不同,所以在Provider目录下创建一个Admin,一个Web目录,分别加载provider,
于此同时,需要修改config下面不同路径中的app.php中serviceprovider类的路径.
因为加载了不同的config配置文件并且不同应用的视图是不相同的,所以试图需要分开建立
在resources/views目录下创建admin文件,这里存放admin应用的视图模板.
于此同时需要修改config/admin下的view.php:
'paths' => [
realpath(base_path('resources/views/admin')),
],
告诉请求应访问那一个文件下的视图.
不同的应用,使用不同的路由,应此需要创建属于应用自己的路由文件admin.routes.php:
在RouterServiceProvider中提供了访问哪一个路由的映射,该映射函数map中,需要找到应用的routes.php文件,并且需要找到
该应用的路由对应即将访问的controller控制器.
protected $namespace = 'App\Http\Controllers\Admin';
public function map(Router $router)
{
$router->group(['namespace' => $this->namespace], function ($router) {
require app_path('Http/admin.routes.php');
});
}
对应的可以重写artisan文件,新建一个artisan.admin文件:
修改内容
$app = require_once __DIR__.'/bootstrap/admin.app.php';
在nginx下配置路径
首先会找到laravel文件中的public下的index.php
这里重新创建一个admin(和public在同一个目录)文件,nginx配置路径到admin下的index.php文件,开始模拟在laravel中的另一个应用
将public下的所有文件复制到admin下,并修改index.php
$app = require_once __DIR__.'/../bootstrap/admin.app.php';
此时加载bootstrap下的admin.app.php文件
bootstrap下有app.php文件,复制并且重命名为admin.app.php
修改admin.app.php
$app = new App\Admin\Application(
realpath(__DIR__.'/../')
);
$app->loadEnvironmentFrom('.env.admin');
$app->singleton(
Illuminate\Contracts\Http\Kernel::class,
App\Http\Admin\Kernel::class
);
通过对这个文件的修改,我们与原来的app.php文件对比
原来的app.php文件:
$app = new Illuminate\Foundation\Application(
realpath(__DIR__.'/../')
);
$app->singleton(
Illuminate\Contracts\Http\Kernel::class,
App\Http\Kernel::class
);
因此我们需要在app目录下添加一个Admin文件,文件下建立继承Illuminate\Foundation\Application的类Application:
<?php
namespace App\Admin;
use Illuminate\Foundation\Application as LaravelApplication;
class Application extends LaravelApplication
{
/**
* Get the path to the public / web directory.
*
* @return string
*/
公共路径,用来区分访问的是admin还是public,可以在该路径下添加公共资源,css,js,imgaes等
public function publicPath()
{
return $this->basePath . DIRECTORY_SEPARATOR . 'admin';
}
/**
* Get the path to the application configuration files.
*
* @return string
*/
由此可发现应该在config目录下配置一份admin,和一份public/web目录
public function configPath()
{
return $this->basePath . DIRECTORY_SEPARATOR . 'config' .
DIRECTORY_SEPARATOR . 'admin';
}
/**
* Get the path to the language files.
*
* @return string
*/
由此可见resources下的lang也需要配置一个admin,一个public/web
public function langPath()
{
return $this->basePath . DIRECTORY_SEPARATOR . 'resources' .
DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . 'admin';
}
/**
* Get the path to the storage directory.
*
* @return string
*/
storage目录下需要配置admin和web
public function storagePath()
{
return $this->storagePath ?: $this->basePath . DIRECTORY_SEPARATOR . 'storage' .
DIRECTORY_SEPARATOR . 'admin';
}
/**
* Get the path to the configuration cache file.
*
* @return string
*/
public function getCachedConfigPath()
{
return $this->basePath().'/bootstrap/admin/cache/config.php';
}
/**
* Get the path to the routes cache file.
*
* @return string
*/
public function getCachedRoutesPath()
{
return $this->basePath().'/bootstrap/admin/cache/routes.php';
}
/**
* Get the path to the cached "compiled.php" file.
*
* @return string
*/
public function getCachedCompilePath()
{
return $this->basePath().'/bootstrap/admin/cache/compiled.php';
}
/**
* Get the path to the cached services.json file.
*
* @return string
*/
public function getCachedServicesPath()
{
return $this->basePath().'/bootstrap/admin/cache/services.json';
}
}
同时在http下添加Admin文件,建立Kernel.php文件:
复制原有的Kernel.php文件,该文件包含了middleware的路径,admin与public不同
因为不同应用之间的serviceProvider有所不同,所以在Provider目录下创建一个Admin,一个Web目录,分别加载provider,
于此同时,需要修改config下面不同路径中的app.php中serviceprovider类的路径.
因为加载了不同的config配置文件并且不同应用的视图是不相同的,所以试图需要分开建立
在resources/views目录下创建admin文件,这里存放admin应用的视图模板.
于此同时需要修改config/admin下的view.php:
'paths' => [
realpath(base_path('resources/views/admin')),
],
告诉请求应访问那一个文件下的视图.
不同的应用,使用不同的路由,应此需要创建属于应用自己的路由文件admin.routes.php:
在RouterServiceProvider中提供了访问哪一个路由的映射,该映射函数map中,需要找到应用的routes.php文件,并且需要找到
该应用的路由对应即将访问的controller控制器.
protected $namespace = 'App\Http\Controllers\Admin';
public function map(Router $router)
{
$router->group(['namespace' => $this->namespace], function ($router) {
require app_path('Http/admin.routes.php');
});
}
对应的可以重写artisan文件,新建一个artisan.admin文件:
修改内容
$app = require_once __DIR__.'/bootstrap/admin.app.php';
0 0
- 一个laravel文件中创建多个应用
- laravel中创建帮助函数文件
- 在 Laravel 中通过 Artisan View 扩展包创建及删除应用视图文件
- 在 Laravel 中通过 Artisan View 扩展包创建及删除应用视图文件
- 在laravel中大家有没有遇到多个应用中数据库连接错乱问题?
- IOS中可以一个多个xib文件对应一个类。当然也可以在一个Xib中创建多个view然后也是用一个类控制
- xib文件中创建多个视图
- Laravel中创建Model
- 对象序列化的应用,一个文件中存储多个对象
- EXCEL:为一个EXCEL文件创建多个工作表
- plupload:在一个jsp中创建多个上传控件
- angular中薇一个module创建多个controller
- 使用 IDEA 在一个 Project 中创建多个 module
- 一个apk多个入口,在桌面上创建多个应用图标
- 一个apk多个入口,在桌面上创建多个应用图标的桌面快捷方式
- 复制多个文件到一个文件中
- Python: 合并多个文件内容到一个文件中
- Android系统中的一个应用中启动多个进程
- Gson JsonString to Map
- 【51Nod】1101 - 换零钱(完全背包)
- java IO流之一 IO流介绍
- 一个简单的哈希表实现
- FMDB的一些特别使用
- 一个laravel文件中创建多个应用
- 内核与驱动文件的version magic匹配问题
- SVN
- Centos 环境搭建之Maven私服nexus
- 【JEECG dubbo专题】Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)
- EventBus使用详解
- laraval的分页
- install Composer fail from xampp in windows
- Android AsyncTask源码分析