make:authとした後、先にViewファイル, migration, modelを作ってから、Controllerを作成して挙動を確認する
$ php artisan migrate
$ php artisan make:auth
resourcesにファイルを作成
./resources/views/admin/index.blade.php
./resources/views/admin/users/index.blade.php
./resources/views/admin/users/create.blade.php
./resources/views/admin/users/edit.blade.php
./resources/views/admin/posts/index.blade.php
./resources/views/admin/posts/create.blade.php
./resources/views/admin/posts/edit.blade.php
./resources/views/admin/categories/index.blade.php
./resources/views/admin/categories/edit.blade.php
migration file:user
Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->integer('role_id')->index()->unsigned()->nullable(); $table->integer('is_active')->default(0); $table->string('name'); $table->string('email')->unique(); $table->string('password'); $table->rememberToken(); $table->timestamps(); });
$ php artisan make:model Role -m
migration file: role
Schema::create('roles', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->timestamps(); });
Model: Role.php
public function role(){ return $this->belongsTo('App\Role'); }
$ php artisan migrate:refresh
insert into roles (name) values (‘administrator’);
insert into roles (name) values (‘author’);
insert into roles (name) values (‘subscriber’);
update users set role_id=1 where id=1;
$ php artisan tinker
Psy Shell v0.7.2 (PHP 7.1.7 — cli) by Justin Hileman
>>> $user = App\User::find(1);
=> App\User {#647
id: 1,
role_id: 1,
is_active: 0,
name: “peter”,
email: “peter@gmail.com”,
created_at: “2019-12-13 13:52:49”,
updated_at: “2019-12-13 13:52:49”,
}
>>> $user->role
=> App\Role {#637
id: 1,
name: “administrator”,
created_at: null,
updated_at: null,
}
Route
Route::resource('admin/users', 'AdminUsersController');
$ php artisan make:controller –resource Adm inUsersController
Controller: AdminUsersController.php
public function index() { // return view('admin.users.index'); }
フロントのテンプレートファイルを流し込んで、controllerを作り、ログイン機能は後から実装するのかと思っていましたが、そうではなくmake:authは一番最初に実行し、ユーザモデルを先に作ってしまうんですね👻