There seems to be an issue with the generated query when trying to delete a record from a pivot table with Eloquent. Getting the follow error:
Connection->handleQueryException(object(PDOException), 'delete from `users` where `department_user`.`department_id` = ? and `deleted_at` is null', array('3')) in /Users/gstjohn/Dropbox/Projects/echo_api/vendor/laravel/framework/src/Illuminate/Database/Connection.php line 467
As you can see, it seems to be trying to run the delete on the related table ('users') rather than on the pivot table ('department_user').
The User model has a return $this->belongsToMany('Department')->whereNull('deleted_at')->withTimestamps(); within the departments() method.
The Department model has a return $this->belongsToMany('User')->whereNull('deleted_at')->withTimestamps(); within the users() method.
The line executing the delete is $this->users()->delete(); within the Department model's overridden delete() method.
Any advice or direction would be appreciated!
$this->users()->detach()
Well, son of a... That's what I get for leaving my docs open for too long without refreshing on a dev branch :)
Thanks @taylorotwell!
Most helpful comment
$this->users()->detach()