Explorar o código

Add soft deletes to everything

axkuhta hai 1 ano
pai
achega
8ceb64d644

+ 3 - 0
app/Models/Author.php

@@ -3,9 +3,12 @@
 namespace App\Models;
 
 use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
 
 class Author extends Model
 {
+	use SoftDeletes;
+
 	function books() {
 		return $this->hasMany(Book::class);
 	}

+ 3 - 0
app/Models/Book.php

@@ -3,9 +3,12 @@
 namespace App\Models;
 
 use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
 
 class Book extends Model
 {
+	use SoftDeletes;
+
 	function author() {
 		return $this->belongsTo(Author::class);
 	}

+ 3 - 0
app/Models/Comment.php

@@ -3,9 +3,12 @@
 namespace App\Models;
 
 use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
 
 class Comment extends Model
 {
+	use SoftDeletes;
+
 	// Наличие fillable требуется только при использовании mass assignment, т.е. создание записи из ассоциативного массива
 	protected $fillable = [
 		"name",

+ 1 - 0
database/migrations/2023_11_02_092818_create_authors_table.php

@@ -16,6 +16,7 @@ return new class extends Migration
             $table->timestamps();
             $table->string("name");
             $table->text("description")->nullable();
+            $table->softDeletes();
         });
     }
 

+ 1 - 0
database/migrations/2023_11_02_093534_create_books_table.php

@@ -20,6 +20,7 @@ return new class extends Migration
             $table->smallInteger("pagecount")->unsigned()->nullable();
             $table->foreignId("author_id")->constrained();
             $table->timestamps();
+            $table->softDeletes();
         });
     }
 

+ 1 - 0
database/migrations/2023_11_28_191724_create_comments_table.php

@@ -18,6 +18,7 @@ return new class extends Migration
             $table->string("email");
             $table->text("content");
             $table->morphs("commentable");
+            $table->softDeletes();
         });
     }