May 8, 2018
17
Level 4
Help to find a problem
I have 3 tables users, documents, document_user(pivot table).
I already have attach() method that works great, and trying to figure out detach() method. I created it as I see should work, but it detach() only last record in document_user, but I need to detach exactly $userId that sends from form request. Kind of confused, because my method send exact userId.
So how my method looks:
public function unshare(Request $request, $company_id, $id)
{
$document = Document::find($id);
$userId = $request['id'];
$user = User::findOrFail($userId);
$document->users()->detach($userId);
flash('Document access has been updated!');
return back();
}
My form:
<form id="unsahre" method="POST" action="/company/{{ $company->id }}/document/{{ $document->id }}/unshare">
{{ csrf_field() }}
<input type="hidden" name="id" value="{{ $user->id }}">
<a href="javascript:{}" style="color: #f0506e" onclick="document.getElementById('unsahre').submit(); return false;"><i class="fas fa-times"></i></a>
</form>
Please or to participate in this conversation.