get()->toJson(); } /** * Show the form for creating a new resource. */ public function create() { // } /** * Store a newly created resource in storage. */ public function store(StoreListingRequest $request) { $attrs = $request->safe()->merge([ 'user_id' => $request->user()->id ]); return Listing::create($attrs->all())->toJson(); } /** * Display the specified resource. */ public function show(Listing $listing) { return $listing->with('poster')->get()->toJson(); } /** * Show the form for editing the specified resource. */ public function edit(Listing $listing) { // } /** * Update the specified resource in storage. */ public function update(UpdateListingRequest $request, Listing $listing) { return $listing->update($request->validated()); } /** * Remove the specified resource from storage. */ 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); } } }