Answer the question
In order to leave comments, you need to log in
detach() not working correctly in laravel 5.7?
Good day. Which day I fight over a bug.
In general, there are models of users and payments. A many-to-many relationship is used. The payment is attached to the user in the pivot table.
Communication with the user model
/*
* Связь с таблицей платежей пользователей
*
*/
public function pays(){
return $this->belongsToMany(Pay::class,
'pay_users',
'user_id',
'pays_id'
)->withPivot('id', 'date', 'summ', 'doc');
}
Communication with the payment model
public function users(){
$this->belongsToMany(User::class,
'pay_users',
'pays_id',
'user_id')->withPivot('id', 'date', 'summ', 'doc');
}
Removal
public function destroy($id, $value)
{
$user = User::find($id);
$user->pays()->detach($value);
return redirect()->route('admin.user-pays.index', $id);
}
php artisan migrate:reset. After this rollback - deletes, but not all, selectively. I checked the id that come, everything is correct. There are no errors in the console or logs. What could be?
Answer the question
In order to leave comments, you need to log in
Made it rough and rude
DB::table('pay_users')
->where('id', $payId)
->take(1)
->delete();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question