Mass changes
This commit is contained in:
@@ -1121,4 +1121,53 @@ public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a document that belongs either directly to the client case or to one of its (even soft deleted) contracts.
|
||||
*/
|
||||
public function deleteDocument(ClientCase $clientCase, Document $document, Request $request)
|
||||
{
|
||||
// Ownership check: direct case document?
|
||||
$belongsToCase = $document->documentable_type === ClientCase::class && $document->documentable_id === $clientCase->id;
|
||||
|
||||
// Or document of a contract that belongs to this case (include trashed contracts)
|
||||
$belongsToContractOfCase = false;
|
||||
if ($document->documentable_type === Contract::class) {
|
||||
$belongsToContractOfCase = Contract::withTrashed()
|
||||
->where('id', $document->documentable_id)
|
||||
->where('client_case_id', $clientCase->id)
|
||||
->exists();
|
||||
}
|
||||
|
||||
if (! ($belongsToCase || $belongsToContractOfCase)) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
// (Optional future) $this->authorize('delete', $document);
|
||||
|
||||
$document->delete(); // soft delete
|
||||
|
||||
return $request->wantsJson()
|
||||
? response()->json(['status' => 'ok'])
|
||||
: back()->with('success', 'Document deleted.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a document accessed through a contract route binding.
|
||||
*/
|
||||
public function deleteContractDocument(Contract $contract, Document $document, Request $request)
|
||||
{
|
||||
$belongs = $document->documentable_type === Contract::class && $document->documentable_id === $contract->id;
|
||||
if (! $belongs) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
// (Optional future) $this->authorize('delete', $document);
|
||||
|
||||
$document->delete();
|
||||
|
||||
return $request->wantsJson()
|
||||
? response()->json(['status' => 'ok'])
|
||||
: back()->with('success', 'Document deleted.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user