laravel_quick_start.md 977 B

  1. 建立表 php artisan make:model Lesson -m

  2. 修改迁移文件,添加列

  3. 升级数据库 php artisan migrate

  4. 降级

php artisan migrate:rollback --step=1

  1. 升级数据库 php artisan migrate

  2. 建立控制器

php artisan make:controller --api --model=Lesson LessonController

  1. 数据库查询

    $table = new Tag();
    $table = $table->where('name','aaa');
    $count = $table->count();
    // select count(*) where name = 'aaa';
    
    $data = $table->select(['name','id'])->get();
    // select name,id where name = 'aaa';
    return $this->ok($data);
    
    /*
    ['rows'=>$data,'count'=>$count]
    {
        rows: data,
        count: count,
    }
    */
    
    /**
    
    • GET tag/ -> index()
    • GET tag/:id -> show()
    • POST tag -> store()
    • PUT tag/:id -> update()
    • DELETE tag/:id -> destroy() */

前端 api 配置

.env

REACT_APP_API_HOST=http://127.0.0.1:8000/api/v2

前端调用