generated from Flycro/laravel-nuxt
feat: BookRecommendation Functionality
This commit is contained in:
@@ -14,10 +14,16 @@ class BookRecommendationController extends Controller
|
||||
public function index()
|
||||
{
|
||||
$relations = [];
|
||||
$bookRecommendations = BookRecommendation::query();
|
||||
if (request()->has('with')) {
|
||||
$relations = explode(',', request()->with);
|
||||
$bookRecommendations->with($relations);
|
||||
}
|
||||
return BookRecommendation::with($relations)->get();
|
||||
if(request()->has('status')) {
|
||||
$bookRecommendations->where('status', request()->status);
|
||||
}
|
||||
|
||||
return $bookRecommendations->get();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,7 +56,7 @@ class BookRecommendationController extends Controller
|
||||
$data['cover_image'] = $imagePath;
|
||||
}
|
||||
|
||||
$bookRecommendation = BookRecommendation::create([...$request->all(), 'recommended_by' => auth()->id()]);
|
||||
$bookRecommendation = BookRecommendation::create([...$data, 'recommended_by' => auth()->id()]);
|
||||
return response()->json($bookRecommendation, 201);
|
||||
}
|
||||
|
||||
@@ -124,6 +130,9 @@ class BookRecommendationController extends Controller
|
||||
if ($bookRecommendation->recommended_by !== auth()->id() && !(auth()->user()->hasRole('admin')) ) {
|
||||
return response()->json(['message' => 'Keine Berechtigung.'], 403);
|
||||
}
|
||||
if ($bookRecommendation->cover_image) {
|
||||
Storage::delete($bookRecommendation->cover_image);
|
||||
}
|
||||
$bookRecommendation->delete();
|
||||
return response()->json(null, 204);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user