mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 22:46:16 +00:00
#591 - tags
This commit is contained in:
64
app/Http/Controllers/TagController.php
Normal file
64
app/Http/Controllers/TagController.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Actions\Tag\CreateTag;
|
||||
use App\Actions\Tag\DeleteTag;
|
||||
use App\Actions\Tag\EditTag;
|
||||
use App\Http\Resources\TagResource;
|
||||
use App\Models\Tag;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Spatie\RouteAttributes\Attributes\Delete;
|
||||
use Spatie\RouteAttributes\Attributes\Get;
|
||||
use Spatie\RouteAttributes\Attributes\Middleware;
|
||||
use Spatie\RouteAttributes\Attributes\Patch;
|
||||
use Spatie\RouteAttributes\Attributes\Post;
|
||||
use Spatie\RouteAttributes\Attributes\Prefix;
|
||||
|
||||
#[Prefix('settings/tags')]
|
||||
#[Middleware(['auth'])]
|
||||
class TagController extends Controller
|
||||
{
|
||||
#[Get('/', name: 'tags')]
|
||||
public function index(): Response
|
||||
{
|
||||
$this->authorize('viewAny', Tag::class);
|
||||
|
||||
return Inertia::render('tags/index', [
|
||||
'tags' => TagResource::collection(Tag::getByProjectId(user()->current_project_id)->simplePaginate(config('web.pagination_size'))),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Post('/', name: 'tags.store')]
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$this->authorize('create', Tag::class);
|
||||
|
||||
app(CreateTag::class)->create(user(), $request->input());
|
||||
|
||||
return back()->with('success', 'Tag created.');
|
||||
}
|
||||
|
||||
#[Patch('/{tag}', name: 'tags.update')]
|
||||
public function update(Request $request, Tag $tag): RedirectResponse
|
||||
{
|
||||
$this->authorize('update', $tag);
|
||||
|
||||
app(EditTag::class)->edit($tag, $request->input());
|
||||
|
||||
return back()->with('success', 'Tag updated.');
|
||||
}
|
||||
|
||||
#[Delete('/{tag}', name: 'tags.destroy')]
|
||||
public function destroy(Tag $tag): RedirectResponse
|
||||
{
|
||||
$this->authorize('delete', $tag);
|
||||
|
||||
app(DeleteTag::class)->delete($tag);
|
||||
|
||||
return back()->with('success', 'Tag deleted.');
|
||||
}
|
||||
}
|
26
app/Http/Resources/TagResource.php
Normal file
26
app/Http/Resources/TagResource.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Models\Tag;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
/** @mixin Tag */
|
||||
class TagResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'project_id' => $this->project_id,
|
||||
'name' => $this->name,
|
||||
'color' => $this->color,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user