laravel自带命令的实现方法及过程是什么
Admin 2022-07-25 群英技术资讯 767 次浏览
关于“laravel自带命令的实现方法及过程是什么”的知识有一些人不是很理解,对此小编给大家总结了相关内容,具有一定的参考借鉴价值,而且易于学习与理解,希望能对大家有所帮助,有这个方面学习需要的朋友就继续往下看吧。
在PHP的框架学习中,我们已经对laravel的安装和配置有所掌握,那么除此之外,在该框架中有一种自带命令,不知道小伙伴们有没有在使用的时候留意过呢?之前没有接触过artisan的也不要着急,本篇就laravel框架自带命令会带来使用的步骤介绍,一起来看看接下来的命令实现吧。
1、作为服务提供者,加载到程序中。
// config/app.php 中。 'providers' => [ // 这个便是laravel自带的artisan命令提供者 Illuminate\Foundation\Providers\ArtisanServiceProvider::class, ]
2、然后找到 Up/Down命令入口
/**
* Register the command.
*
* @return void
*/
protected function registerUpCommand()
{
$this->app->singleton('command.up', function () {
return new UpCommand;
});
}
3、DownCommand实现
class DownCommand extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'down';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Put the application into maintenance mode';
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
// 关键点: 在当前存储目录/framework 下面创建一个 down文件
touch($this->laravel->storagePath().'/framework/down');
$this->comment('Application is now in maintenance mode.');
}
}
// touch() 函数php文档解释
/**
* Sets access and modification time of file
* @link http://php.net/manual/en/function.touch.php
* @param string $filename <p>
* The name of the file being touched.
* </p>
* @param int $time [optional] <p>
* The touch time. If time is not supplied,
* the current system time is used.
* </p>
* @param int $atime [optional] <p>
* If present, the access time of the given filename is set to
* the value of atime. Otherwise, it is set to
* time.
* </p>
* @return bool true on success or false on failure.
* @since 4.0
* @since 5.0
*/
function touch ($filename, $time = null, $atime = null) {}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
你清楚关于PHP如何判断函数的有没有被定义的方法是什么吗?其实这个方法很简单。为了帮助大家解决问题,下面请看看爱站技术频道小编所整理的文章。
本文给大家介绍一种PHP特有的方法,我们利用内置函数date()来判断闰年,然后找出21世纪的所有闰年并打印出来。
区别:1、表单提交时,Laravel需要在表单中加入“@csrf”来防止跨域攻击,而TP5不用;2、Laravel在请求之前会有中间件,Tp5会有前置操作和钩子;3、操作数据库的原生查询方式不同。
用PHP怎样实现堆排序?要解决这个问题,首先我们需要了解关于堆,完成二叉树以及堆排序的原理,本文后面有堆排序的PHP实现代码,有需要的朋友可以参考一下。
本篇文章小编给大家分享一下基于Python实现配置热加载代码方法解析,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
成为群英会员,开启智能安全云计算之旅
立即注册关注或联系群英网络
7x24小时售前:400-678-4567
7x24小时售后:0668-2555666
24小时QQ客服
群英微信公众号
CNNIC域名投诉举报处理平台
服务电话:010-58813000
服务邮箱:service@cnnic.cn
投诉与建议:0668-2555555
Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008