質問編集履歴
2
ソースコードの提示
title
CHANGED
File without changes
|
body
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
以上、よろしくお願い致します。
|
19
19
|
|
20
20
|
※以下、コーディングした内容です。
|
21
|
-
|
21
|
+
マイグレーションファイルの作成、マイグレートの実行
|
22
22
|
$ php artisan make:migration add_column_softDeletes_users_table --table=users
|
23
23
|
$ view 2018_07_12_045301_add_column_soft_deletes_users_table.php
|
24
24
|
> <?php
|
@@ -54,7 +54,7 @@
|
|
54
54
|
> }
|
55
55
|
> }
|
56
56
|
|
57
|
-
|
57
|
+
モデルの作成
|
58
58
|
$ php artisan make:model Models/Users
|
59
59
|
$ view Users.php
|
60
60
|
> <?php
|
@@ -72,7 +72,7 @@
|
|
72
72
|
> protected $dates = ['deleted_at'];
|
73
73
|
> }
|
74
74
|
|
75
|
-
|
75
|
+
下記SQL文にて、ユーザをソフトデリートしました。
|
76
76
|
> update users set deleted_at = '2018-07-12 01:03:26' where id = 1;
|
77
77
|
|
78
|
-
|
78
|
+
前項でソフトデリートしたユーザでログインを試みるとログインできてしまいます。
|
1
ソースコードの提示
title
CHANGED
File without changes
|
body
CHANGED
@@ -15,4 +15,64 @@
|
|
15
15
|
PHP 7.2.7
|
16
16
|
MySQL 5.7.22
|
17
17
|
|
18
|
-
以上、よろしくお願い致します。
|
18
|
+
以上、よろしくお願い致します。
|
19
|
+
|
20
|
+
※以下、コーディングした内容です。
|
21
|
+
1. マイグレーションファイルの作成、マイグレートの実行
|
22
|
+
$ php artisan make:migration add_column_softDeletes_users_table --table=users
|
23
|
+
$ view 2018_07_12_045301_add_column_soft_deletes_users_table.php
|
24
|
+
> <?php
|
25
|
+
>
|
26
|
+
> use Illuminate\Support\Facades\Schema;
|
27
|
+
> use Illuminate\Database\Schema\Blueprint;
|
28
|
+
> use Illuminate\Database\Migrations\Migration;
|
29
|
+
>
|
30
|
+
> class AddColumnSoftDeletesUsersTable extends Migration
|
31
|
+
> {
|
32
|
+
> /**
|
33
|
+
> * Run the migrations.
|
34
|
+
> *
|
35
|
+
> * @return void
|
36
|
+
> */
|
37
|
+
> public function up()
|
38
|
+
> {
|
39
|
+
> Schema::table('users', function (Blueprint $table) {
|
40
|
+
> $table->softDeletes();
|
41
|
+
> });
|
42
|
+
> }
|
43
|
+
>
|
44
|
+
> /**
|
45
|
+
> * Reverse the migrations.
|
46
|
+
> *
|
47
|
+
> * @return void
|
48
|
+
> */
|
49
|
+
> public function down()
|
50
|
+
> {
|
51
|
+
> Schema::table('users', function (Blueprint $table) {
|
52
|
+
> $table->dropColumn('deleted_at');
|
53
|
+
> });
|
54
|
+
> }
|
55
|
+
> }
|
56
|
+
|
57
|
+
2. モデルの作成
|
58
|
+
$ php artisan make:model Models/Users
|
59
|
+
$ view Users.php
|
60
|
+
> <?php
|
61
|
+
>
|
62
|
+
> namespace App\Models;
|
63
|
+
>
|
64
|
+
> use Illuminate\Database\Eloquent\Model;
|
65
|
+
> use Illuminate\Database\Eloquent\SoftDeletes;
|
66
|
+
>
|
67
|
+
> class Users extends Model
|
68
|
+
> {
|
69
|
+
> use SoftDeletes;
|
70
|
+
>
|
71
|
+
> protected $table = 'users';
|
72
|
+
> protected $dates = ['deleted_at'];
|
73
|
+
> }
|
74
|
+
|
75
|
+
3. 下記SQL文にて、ユーザをソフトデリートしました。
|
76
|
+
> update users set deleted_at = '2018-07-12 01:03:26' where id = 1;
|
77
|
+
|
78
|
+
4. 前項でソフトデリートしたユーザでログインを試みるとログインできてしまいます。
|