2026-04-14 21:04:41 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\App;
|
|
|
|
|
|
|
|
|
|
use App\Http\Requests\App\Brand\StoreBrandRequest;
|
|
|
|
|
use App\Http\Requests\App\Brand\UpdateBrandRequest;
|
|
|
|
|
use App\Models\Brand;
|
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Inertia\Inertia;
|
|
|
|
|
use Inertia\Response;
|
|
|
|
|
|
|
|
|
|
class BrandController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function index(Request $request): Response|RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
$workspace = $request->user()->currentWorkspace;
|
|
|
|
|
|
|
|
|
|
if (! $workspace) {
|
|
|
|
|
return redirect()->route('app.workspaces.create');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->authorize('viewAny', [Brand::class, $workspace]);
|
|
|
|
|
|
|
|
|
|
$brands = $workspace->brands()
|
|
|
|
|
->withCount('socialAccounts')
|
|
|
|
|
->latest()
|
|
|
|
|
->paginate(config('app.pagination.default'));
|
|
|
|
|
|
|
|
|
|
return Inertia::render('brands/Index', [
|
|
|
|
|
'brands' => Inertia::scroll(fn () => $brands),
|
|
|
|
|
'canCreate' => $request->user()->can('create', [Brand::class, $workspace]),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function store(StoreBrandRequest $request): RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
$workspace = $request->user()->currentWorkspace;
|
|
|
|
|
|
|
|
|
|
if (! $workspace) {
|
|
|
|
|
return redirect()->route('app.workspaces.create');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->authorize('create', [Brand::class, $workspace]);
|
|
|
|
|
|
|
|
|
|
$workspace->brands()->create([
|
|
|
|
|
'name' => data_get($request->validated(), 'name'),
|
|
|
|
|
]);
|
|
|
|
|
|
2026-04-14 22:14:41 +00:00
|
|
|
session()->flash('flash.banner', __('brands.flash.created'));
|
2026-04-14 21:04:41 +00:00
|
|
|
session()->flash('flash.bannerStyle', 'success');
|
|
|
|
|
|
|
|
|
|
return redirect()->route('app.brands.index');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function update(UpdateBrandRequest $request, Brand $brand): RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
$workspace = $request->user()->currentWorkspace;
|
|
|
|
|
|
|
|
|
|
if (! $workspace) {
|
|
|
|
|
return redirect()->route('app.workspaces.create');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->authorize('update', $brand);
|
|
|
|
|
|
|
|
|
|
$brand->update([
|
|
|
|
|
'name' => data_get($request->validated(), 'name'),
|
|
|
|
|
]);
|
|
|
|
|
|
2026-04-14 22:14:41 +00:00
|
|
|
session()->flash('flash.banner', __('brands.flash.updated'));
|
2026-04-14 21:04:41 +00:00
|
|
|
session()->flash('flash.bannerStyle', 'success');
|
|
|
|
|
|
|
|
|
|
return redirect()->route('app.brands.index');
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-14 21:44:47 +00:00
|
|
|
public function destroy(Request $request, Brand $brand): RedirectResponse
|
2026-04-14 21:04:41 +00:00
|
|
|
{
|
2026-04-14 21:44:47 +00:00
|
|
|
$workspace = $request->user()->currentWorkspace;
|
2026-04-14 21:04:41 +00:00
|
|
|
|
|
|
|
|
if (! $workspace) {
|
|
|
|
|
return redirect()->route('app.workspaces.create');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->authorize('delete', $brand);
|
|
|
|
|
|
|
|
|
|
$brand->delete();
|
|
|
|
|
|
2026-04-14 22:14:41 +00:00
|
|
|
session()->flash('flash.banner', __('brands.flash.deleted'));
|
2026-04-14 21:04:41 +00:00
|
|
|
session()->flash('flash.bannerStyle', 'success');
|
|
|
|
|
|
|
|
|
|
return redirect()->route('app.brands.index');
|
|
|
|
|
}
|
|
|
|
|
}
|