Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Xinecraft committed Sep 17, 2023
1 parent 96f325c commit f6946d3
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
43 changes: 40 additions & 3 deletions app/Http/Controllers/DownloadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,42 @@
namespace App\Http\Controllers;

use App\Models\Download;
use App\Queries\Filters\FilterMultipleFields;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Spatie\QueryBuilder\AllowedFilter;
use Spatie\QueryBuilder\QueryBuilder;

class DownloadController extends Controller
{
public function index(Request $request)
public function index(Request $request): \Inertia\Response
{
$isAuthenticated = $request->user() ? true : false;
$isAuthenticated = (bool) $request->user();

$perPage = request()->input('perPage', 10);
if ($perPage > 100) {
$perPage = 100;
}

$fields = [
'id',
'name',
'slug',
'is_active',
'download_count',
'created_at',
'updated_at',
];
$downloads = QueryBuilder::for(Download::class)
->select($fields)
->allowedFilters([
...$fields,
AllowedFilter::custom('q', new FilterMultipleFields(['id', 'name', 'description'])),
])
->allowedSorts($fields)
->defaultSort('-download_count')
->paginate($perPage)
->withQueryString();

return Inertia::render('Download/IndexDownload', [
'downloads' => $downloads,
Expand All @@ -23,7 +51,16 @@ public function show(Request $request, Download $download)
$this->authorize('download', $download);

return Inertia::render('Download/ShowDownload', [
'download' => $download,
'download' => $download->only([
'id',
'name',
'slug',
'description',
'is_active',
'download_count',
'created_at',
'updated_at',
]),
]);
}

Expand Down
9 changes: 9 additions & 0 deletions resources/js/Pages/Download/IndexDownload.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script setup>
</script>

<template />

<style scoped>
</style>
9 changes: 9 additions & 0 deletions resources/js/Pages/Download/ShowDownload.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script setup>
</script>

<template />

<style scoped>
</style>

0 comments on commit f6946d3

Please sign in to comment.