basic CRUD for listings
This commit is contained in:
@@ -13,7 +13,7 @@ class ListingController extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
return Listing::with('poster')->get()->toJson();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,7 +29,10 @@ class ListingController extends Controller
|
||||
*/
|
||||
public function store(StoreListingRequest $request)
|
||||
{
|
||||
//
|
||||
$attrs = $request->safe()->merge([
|
||||
'user_id' => $request->user()->id
|
||||
]);
|
||||
return Listing::create($attrs->all())->toJson();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,7 +40,7 @@ class ListingController extends Controller
|
||||
*/
|
||||
public function show(Listing $listing)
|
||||
{
|
||||
//
|
||||
return $listing->with('poster')->get()->toJson();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +56,7 @@ class ListingController extends Controller
|
||||
*/
|
||||
public function update(UpdateListingRequest $request, Listing $listing)
|
||||
{
|
||||
//
|
||||
return $listing->update($request->validated());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,6 +64,15 @@ class ListingController extends Controller
|
||||
*/
|
||||
public function destroy(Listing $listing)
|
||||
{
|
||||
//
|
||||
if (request()->user()->can('delete', $listing)) {
|
||||
$listing->delete();
|
||||
return response()->json([
|
||||
'deleted_at' => $listing->deleted_at,
|
||||
], 200);
|
||||
} else {
|
||||
return response()->json([
|
||||
'error' => 'You are not authorized to delete this listing.',
|
||||
], 403);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user