Francisunoxx Francisunoxx - 1 month ago 5
PHP Question

Why SoftDelete won't fake the deleted row?

Can somebody tell me why using

delete()
method won't delete the selected row in table?
SoftDelete
works well but the row that has been soft delete is still exist in the table. I'm expecting my table row will be hide or deleted but it can't. Any tips or help would appreciated! :) I
SoftDelete
my table like this.

Controller:

public function hideApprovalsDocument(Request $request, Document $id)
{
//Getting the request in the View.
$id = $request->get('softDelete');
$hide = Document::findOrFail($id)->where('id', '=', $id);
$hide->delete();

return redirect()->back();

}

public function documentsSentForApproval()
{

$pendingDocuments = DB::table('approvals_document')
->select('documents.title', 'documents.content', 'documents.id as documentId',
'categories.category_type',
'users.username', 'approvals_document.created_at',
'approvals_document.id', 'approvals_document.approver_id', 'approvals_document.requestedBy')
->join('documents', 'documents.id', '=', 'approvals_document.document_id')
->join('categories', 'categories.id', '=', 'documents.category_id')
->join('users', 'users.id', '=', 'approvals_document.approver_id')
->where('approver_id', '=', Auth::id())
->where('documents.deleted_at', '=', null)
->orWhere('requestedBy', '=', Auth::id())
->orderBy('approvals_document.id', '=', 'desc')
->paginate(10);

return view ('document.pending')
->with('pendingDocuments', $pendingDocuments);

}

Answer

Can you please change the join query to below

->join('documents', function ($join) `{ $join->on('documents.id', '=','approvals_document.document_id') 
->whereNull('documents.deleted_at'); })`