分类:PHP 发布时间:2019-05-06 14:19:44
通过创建 Artisan Command 来实现 生成类 app/Console/Commands/CallRoute.php ``` php artisan make:console CallRoute ``` 修改文件内容,修改后如下 ``` <?php namespace App\Console\Commands; use Illuminate\Console\Command; use Illuminate\Http\Request; class CallRoute extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'route:call {uri}'; /** * The console command description. * * @var string */ protected $description = 'php artsian route:call /route'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return mixed */ public function handle() { $request = Request::create($this->argument('uri'), 'GET'); $this->info(app()->make(\Illuminate\Contracts\Http\Kernel::class)->handle($request)); } } ``` 修改 app/Console/Kernel.php 文件,添加命令 ``` protected $commands = [ ..., 'App\Console\Commands\CallRoute', ]; ``` 然后就可以直接在cli模式下访问了,例如(path为域名后url地址) ``` php artisan route:call /path ```
搜索
文章分类
最新文章