Answers for "laravel cascade delete"

PHP
2

how work cascade laravel

Schema::create('posts', function (Blueprint $table) {
    $table->increments('id');
    $table->integer('author')->unsigned();
    $table->timestamps();
    $table->foreign('author')->references('id')->on('users')->onUpdate('cascade');
});
Posted by: Guest on July-19-2021
1

cascade laravel

Schema::create('posts', function (Blueprint $table) {
    $table->id();
    $table->foreignId('author')->constrained('users')->onDelete('cascade')->onUpdate('cascade');
    $table->timestamps();
});
Posted by: Guest on July-25-2021
2

laravel delete relationship data

class User extends Eloquent
{
    public function photos()
    {
        return $this->has_many('Photo');
    }

    // this is a recommended way to declare event handlers
    public static function boot() {
        parent::boot();

        static::deleting(function($user) { // before delete() method call this
             $user->photos()->delete();
             // do the rest of the cleanup...
        });
    }
}
Posted by: Guest on November-08-2020
0

how set cascade on delete and update in same time in laravel

$table->foreign('user_id')->references('id')->on('users')
->onDelete('SET NULL')
->onUpdate('SET NULL'); // also available CASCADE, RESTRICT, DO NOTHING, NO ACTION
Posted by: Guest on July-22-2021

Browse Popular Code Answers by Language