- Review system: ReviewController (store/update/destroy), ReviewPolicy, Review model boot() hooks, review form with Alpine.js (spoiler toggle, edit/delete UX) - Search autocomplete: Alpine.js searchWidget in nav with 300ms debounce, keyboard navigation, 6-result dropdown - SEO: og:image, twitter:card in layout; og sections + Schema.org VideoGame JSON-LD on game show pages - Custom lists: UserList/UserListGame models, ListController, ListPolicy, lists index/show views, Add-to-List button on game pages Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
92 lines
2.4 KiB
PHP
92 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Game;
|
|
use App\Models\UserList;
|
|
use App\Models\UserListGame;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Str;
|
|
|
|
class ListController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth')->except('show');
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$lists = auth()->user()->lists()->withCount('listGames')->latest()->get();
|
|
return view('lists.index', compact('lists'));
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$data = $request->validate([
|
|
'title' => 'required|string|max:100',
|
|
'description' => 'nullable|string|max:1000',
|
|
'is_public' => 'boolean',
|
|
]);
|
|
|
|
$slug = Str::slug($data['title']);
|
|
$base = $slug;
|
|
$i = 1;
|
|
while (auth()->user()->lists()->where('slug', $slug)->exists()) {
|
|
$slug = $base . '-' . $i++;
|
|
}
|
|
|
|
$list = UserList::create([
|
|
'user_id' => auth()->id(),
|
|
'title' => $data['title'],
|
|
'slug' => $slug,
|
|
'description' => $data['description'] ?? null,
|
|
'is_public' => $data['is_public'] ?? true,
|
|
]);
|
|
|
|
return redirect()->route('lists.show', $list)->with('success', 'List created!');
|
|
}
|
|
|
|
public function show(UserList $list)
|
|
{
|
|
if (!$list->is_public && (!auth()->check() || auth()->id() !== $list->user_id)) {
|
|
abort(403);
|
|
}
|
|
|
|
$list->load(['listGames.game', 'user']);
|
|
|
|
return view('lists.show', compact('list'));
|
|
}
|
|
|
|
public function addGame(Request $request, UserList $list)
|
|
{
|
|
$this->authorize('manage', $list);
|
|
|
|
$data = $request->validate(['game_id' => 'required|exists:games,id']);
|
|
|
|
UserListGame::firstOrCreate([
|
|
'user_list_id' => $list->id,
|
|
'game_id' => $data['game_id'],
|
|
], ['order' => $list->listGames()->count()]);
|
|
|
|
return response()->json(['success' => true]);
|
|
}
|
|
|
|
public function removeGame(UserList $list, Game $game)
|
|
{
|
|
$this->authorize('manage', $list);
|
|
|
|
$list->listGames()->where('game_id', $game->id)->delete();
|
|
|
|
return response()->json(['success' => true]);
|
|
}
|
|
|
|
public function destroy(UserList $list)
|
|
{
|
|
$this->authorize('manage', $list);
|
|
$list->delete();
|
|
|
|
return redirect()->route('lists.index')->with('success', 'List deleted.');
|
|
}
|
|
}
|