Skip to content

Instantly share code, notes, and snippets.

@bmadigan
Last active May 29, 2017 16:13
Show Gist options
  • Save bmadigan/c89762f5aa7735c7827a78c8e427530d to your computer and use it in GitHub Desktop.
Save bmadigan/c89762f5aa7735c7827a78c8e427530d to your computer and use it in GitHub Desktop.
Remove Multiple Assets
<?php
public function destroy(Request $request, $id = null)
{
abort_unless($this->authUser->hasPermissionTo('manage assets'), 403);
$requestData = $id ?
[$request->all() + ['id' => $id]] :
json_decode($request->getContent(), true);
$assets = Asset::findOrFail(collect($requestData)->pluck('id')->toArray());
foreach ($requestData as $data) {
$asset = $assets->find($data['id']);
$asset->delete();
}
return response()->json(['message' => 'asset removed'], 204);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment