some progress

This commit is contained in:
2025-06-13 23:06:13 +03:00
parent 621398978a
commit 71dd328431
25 changed files with 594 additions and 126 deletions
+2 -2
View File
@@ -81,12 +81,12 @@ class GameController extends Controller
}
}
$games = $query->paginate(12)->withQueryString();
$games = $query->paginate(36)->withQueryString();
// Get data for filter dropdowns
$platforms = \App\Models\Platform::orderBy('name')->get();
$genres = \App\Models\Genre::orderBy('name')->get();
// Get unique years from games
$years = Game::selectRaw('YEAR(first_release_date) as year')
->whereNotNull('first_release_date')
+6 -4
View File
@@ -6,12 +6,13 @@ use App\Models\Game;
use App\Models\GameList;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
class GameListController extends Controller
{
public function __construct()
{
$this->middleware('auth');
//$this->middleware('auth');
}
/**
@@ -54,8 +55,9 @@ class GameListController extends Controller
*/
public function show(GameList $list)
{
$this->authorize('view', $list);
//$this->authorize('view', $list);
Gate::authorize('view', $list);
$games = $list->games()->paginate(12);
return view('lists.show', compact('list', 'games'));
}
@@ -106,7 +108,7 @@ class GameListController extends Controller
public function addGame(Request $request, GameList $list)
{
$this->authorize('update', $list);
Gate::authorize('update', $list);
$request->validate([
'game_id' => 'required|exists:games,id'
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class HomeController extends Controller
{
public function index()
{
return view('index');
}
}
@@ -0,0 +1,39 @@
<?php
namespace App\Listeners;
use App\Models\Wishlist;
use Illuminate\Auth\Events\Registered;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class CreateDefaultUsersListListener
{
public const DEFAULT_LISTS = [
'played',
'playing',
'backlog',
'wishlist',
];
/**
* Create the event listener.
*/
public function __construct()
{
//
}
/**
* Handle the event.
*/
public function handle(Registered $event): void
{
foreach (self::DEFAULT_LISTS as $listName) {
Wishlist::create([
'user_id' => $event->user->id,
'name' => $listName,
]);
}
}
}
+3 -1
View File
@@ -40,6 +40,8 @@ class GameList extends Model
public function games(): BelongsToMany
{
return $this->belongsToMany(Game::class)->withTimestamps();
return $this->belongsToMany(Game::class)
->with(['platforms'])
->withTimestamps();
}
}
+2 -1
View File
@@ -14,6 +14,7 @@ class Rating extends Model
'user_id',
'game_id',
'rating',
'platform',
];
protected $casts = [
@@ -29,4 +30,4 @@ class Rating extends Model
{
return $this->belongsTo(Game::class);
}
}
}
+1
View File
@@ -16,6 +16,7 @@ class Review extends Model
'content',
'recommended',
'rating',
'platform',
];
protected $casts = [
+25
View File
@@ -0,0 +1,25 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Wishlist extends Model
{
public const VISIBILITY_PUBLIC = 'public';
public const VISIBILITY_PRIVATE = 'private';
public const VISIBILITY_FRIENDS_ONLY = 'friends_only';
public const VISIBILITIES = [
self::VISIBILITY_PUBLIC,
self::VISIBILITY_PRIVATE,
self::VISIBILITY_FRIENDS_ONLY,
];
protected $fillable = [
'user_id',
'name',
'description',
'visibility',
];
}
+4 -2
View File
@@ -16,15 +16,17 @@ class GameListPolicy
*/
public function viewAny(User $user): bool
{
// check if list is public
return false;
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, GameList $list)
public function view(User $user, GameList $list): bool
{
return $user->id === $list->user_id;
//return $user->id === $list->user_id;
return true;
}
/**
+4
View File
@@ -2,7 +2,10 @@
namespace App\Providers;
use App\Models\GameList;
use App\Policies\GameListPolicy;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
@@ -21,5 +24,6 @@ class AppServiceProvider extends ServiceProvider
public function boot(): void
{
Paginator::useBootstrap();
Gate::policy(GameList::class, GameListPolicy::class);
}
}