forge/app/Http/Controllers/ModController.php
Refringe 1783a683ed
Semvar & Automatic Resolution - Remix
- Updated the SptVersion and ModVersion dependancies to resolve *all* compatible versions and introduced new relationships to pull just the latest compatible version. Had to rewrite a *bunch*, but it should be much more capable now. It can be expensive to resolve these properties when iterated over, so *make sure they're eager loaded using the `with` method when you're building the queries*.
- Updated the mod listing Livewire component to save the filter options within the PHP session instead of in browser local storage. *Much* cleaner.
- Removed caching from homepage queries to see how they preform on production. Will add back later.
- Updated ModVersion factory to create SptVersions if there are none specified.
- Probably lots of other changes too... I need to make smaller commits. :(
2024-08-29 15:46:10 -04:00

69 lines
1.6 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Http\Requests\ModRequest;
use App\Http\Resources\ModResource;
use App\Models\Mod;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class ModController extends Controller
{
use AuthorizesRequests;
public function index()
{
$this->authorize('viewAny', Mod::class);
return view('mod.index');
}
public function store(ModRequest $request)
{
$this->authorize('create', Mod::class);
return new ModResource(Mod::create($request->validated()));
}
public function show(int $modId, string $slug)
{
$mod = Mod::withTotalDownloads()
->with([
'versions',
'versions.latestSptVersion:id,version,color_class',
'versions.latestResolvedDependencies',
'versions.latestResolvedDependencies.mod:id,name,slug',
'users:id,name',
'license:id,name,link',
])
->whereHas('latestVersion')
->findOrFail($modId);
if ($mod->slug !== $slug) {
abort(404);
}
$this->authorize('view', $mod);
return view('mod.show', compact(['mod']));
}
public function update(ModRequest $request, Mod $mod)
{
$this->authorize('update', $mod);
$mod->update($request->validated());
return new ModResource($mod);
}
public function destroy(Mod $mod)
{
$this->authorize('delete', $mod);
$mod->delete();
return response()->json();
}
}