Answers for "how to handle delete data between relationship in laravel"

PHP
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

get relationship data from soft delete laravel

I already fixed it. In my model history I add withtrashed.

public function history()
{
    return $this->hasMany(History::class)->withTrashed();
}
Posted by: Guest on January-10-2022

Code answers related to "how to handle delete data between relationship in laravel"

Browse Popular Code Answers by Language