Song::where('user_id', auth()->id())->paginate(10), ]); } public function store(Request $request): JsonResponse { Gate::authorize("create", Song::class); $validated = $request->validate([ 'song' => 'max:108826630', ]); $song = new Song(); $song->user_id = auth()->id(); $file = $request->song; $path = $file->store('songs'); $song->title = $file->getClientOriginalName(); $song->path = $path; $song->artist = $file->getClientOriginalName(); $ret = $song->save(); return response()->json([ 'data' => $ret ? "Guardado " . $song->title : 'sin archivo' ]); } /** * @return void * @param mixed $id */ public function update(Request $request, $id):void { // Update specified song } /** * @param int $id */ public function destroy($id) { $song = Song::find($id); $user = User::find(auth()->id()); //Gate::authorize('delete', $user , $song); $this->authorize('delete', $song); if ($song) { // Delete the related file if (Storage::exists($song->path)) { Storage::delete($song->path); } Song::destroy($id); } return response()->noContent(200); } /** * @return void * @param mixed $id */ public function stream($id):void { // Stream specified song } }