laravel delete data from database code example
Example 1: laravel delete where
DB::table('users')->where('id', $id)->delete();
Example 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...
});
}
}