add bookmark back
This commit is contained in:
57
app/Http/Controllers/BookmarkController.php
Normal file
57
app/Http/Controllers/BookmarkController.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\BookmarkRequest;
|
||||
use App\Http\Resources\BookmarkCollection;
|
||||
use App\Models\Bookmark;
|
||||
use App\Http\Resources\Bookmark as BookmarkResource;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class BookmarkController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$this->authorize('viewAny', Bookmark::class);
|
||||
|
||||
return new BookmarkCollection(request()->user()->bookmarks);
|
||||
}
|
||||
|
||||
public function store(BookmarkRequest $request)
|
||||
{
|
||||
$this->authorize('create', Bookmark::class);
|
||||
|
||||
$bookmark = request()->user()->bookmarks()->create($request->all());
|
||||
|
||||
return (new BookmarkResource($bookmark))
|
||||
->response()
|
||||
->setStatusCode(201);
|
||||
}
|
||||
|
||||
public function show(Bookmark $bookmark)
|
||||
{
|
||||
$this->authorize('view', $bookmark);
|
||||
|
||||
return new BookmarkResource($bookmark);
|
||||
}
|
||||
|
||||
public function update(BookmarkRequest $request, Bookmark $bookmark)
|
||||
{
|
||||
$this->authorize('update', $bookmark);
|
||||
|
||||
$bookmark->update($request->all());
|
||||
|
||||
return (new BookmarkResource($bookmark))
|
||||
->response()
|
||||
->setStatusCode(200);
|
||||
}
|
||||
|
||||
public function destroy(Bookmark $bookmark)
|
||||
{
|
||||
$this->authorize('delete', $bookmark);
|
||||
|
||||
$bookmark->delete();
|
||||
|
||||
return response([], 204);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user