urlsnail/app/Http/Controllers/BookmarkController.php

102 lines
2.3 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Bookmark;
use App\Models\Tag;
use Illuminate\Http\Request;
class BookmarkController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
return view(
'bookmarks.index', [
'bookmarks' => Bookmark::orderByDesc('created_at')->paginate(20),
]
);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
return view('bookmarks.edit', ['bookmark' => null]);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$bookmark = new Bookmark;
$bookmark->title = $request->post('title');
$bookmark->description = $request->post('description', '');
$bookmark->href = $request->post('href');
$bookmark->save();
$bookmark->syncTagsFromString($request->post('tags', ''));
return redirect()->action(
[self::class, "show"], [
"bookmark" => $bookmark,
]
);
}
/**
* Display the specified resource.
*/
public function show(Bookmark $bookmark)
{
return view(
'bookmarks.show', [
'bookmark' => $bookmark,
]
);
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Bookmark $bookmark)
{
return view(
'bookmarks.edit', [
'bookmark' => $bookmark,
]
);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, Bookmark $bookmark)
{
$bookmark->title = $request->post('title');
$bookmark->description = $request->post('description', '');
$bookmark->href = $request->post('href');
$bookmark->save();
$bookmark->syncTagsFromString($request->post('tags', ''));
return redirect()->action(
[self::class, "show"], [
"bookmark" => $bookmark,
]
);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}