basic CRUD for listings

This commit is contained in:
2025-11-05 14:47:19 -08:00
parent 8355d57fc4
commit 4c3eb027ea
8 changed files with 107 additions and 18 deletions

View File

@@ -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);
}
}
}