laravel写脚本执行

参考:https://www.cnblogs.com/aipiaoborensheng/p/9254364.html

先新建/app/Console/Commands/CollectInfo.php这个文件
或者php artisan make:console CollectInfo

<?php

namespace App\Console\Commands;
/**
 * Created by wt.
 * User: Administrator
 * Date: 2019/1/2
 * Time: 16:59
 */

use App\Http\Model\User;
use Illuminate\Console\Command;

class CollectInfo extends Command
{
    protected $name = 'collect:info';
    protected $description = '描述一下吧';

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

    public function handle()
    {
        $user = new User();
        $user->name = '大哥';
        $user->age = 33;
        $user->save();

        echo "<pre>";
        print_r('haole');die;
    }
}

然后执行php artisan collect:info这样就插入成功啦

Parse error: syntax error, unexpected T_VARIABLE报这个错
其实就是我的php7.0不够了,laravel5.5要7.1的了

posted @ 2019-01-07 14:13  蜗牛使劲冲  阅读(15)  评论(0)    收藏  举报  来源