Laravel-artisan

一、command

1.命令创建

#1.artisan 命令创建
#2.php artisan Hello 运行
php artisan make:command Demo1 --command=Hello

2.手动创建

#1.新建文件 app/Console/Commands
namespace App\Console\Commands;


use Illuminate\Console\Command;

class Demo2 extends Command
{

    protected $signature = 'Hello2';

    public function __construct()
    {
        parent::__construct();
    }

    public function handle()
    {
        echo 4;
    }
}


#2.注册命令 app/Console/Commands/Kernel.php
    protected $commands = [
        Commands\Demo2::class
    ];

3.交互Demo

    public function handle()
    {
        //接收用户名
        $name = $this->ask('what is you name?');
        //选择年龄段
        $age = $this->choice('how old are you?', [10, 20, 30, 40, 50], 0);
        //输入密码
        $password = $this->secret('please input a password');
        //判断密码是否正确
        if ($password != '123456') {
            $this->info($password);
            $this->error('password error!');
            exit(-1);
        }
        //是否继续
        if ($this->confirm('are you sure?')) {
            $this->info($name . ':' . $age);
        } else {
            exit(0);
        }
    }

4.演示效果

在这里插入图片描述

二、交互控制台

1.tinker交互界面

#1.数据库模型交互
[root@localhost project2]# php artisan tinker
Psy Shell v0.10.5 (PHP 7.3.25 ?.cli) by Justin Hileman
>>> $user=new App\Model\User
=> App\Model\User {#4258}
>>> $user->name=1
=> 1
>>> $user->password=2
=> 2
>>> $user->api_token=3
=> 3
>>> $user->save()
=> true
>>> $user=new App\Model\User
=> App\Model\User {#4255}
>>> $u_4=$user->find(4)    
=> App\Model\User {#4254
     id: 4,
     name: "1",
     password: "2",
     api_token: "3",
     created_at: "2021-02-19 03:52:30",
     updated_at: "2021-02-19 03:52:30",
   }
>>> $u_4->delete()
=> true

#2.查看文档
>>> doc dd       
function dd($vars = unknown)

PHP manual not found
    To document core PHP functionality, download the PHP reference manual:
    https://github.com/bobthecow/psysh/wiki/PHP-manual
>>> show dd
35:     function dd(...$vars)
36:     {
37:         foreach ($vars as $v) {
38:             VarDumper::dump($v);
39:         }
40: 
41:         exit(1);
42:     }

>>> 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值