Answers for "laravel delete relationship data"

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

Code answers related to "laravel delete relationship data"

Browse Popular Code Answers by Language