2026-04-30 15:42:04 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Back;
|
|
|
|
|
|
|
|
|
|
use App\Http\Requests\Back\InvoicePackages\StoreInvoicePackageRequest;
|
|
|
|
|
use App\Http\Requests\Back\InvoicePackages\UpdateInvoicePackageRequest;
|
|
|
|
|
use App\Models\InvoicePackage;
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
use Uwil\LaravelBackend\Controllers\BackendController;
|
|
|
|
|
use Uwil\LaravelBackend\Resources\CommonResource;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handles CRUD operations for InvoicePackage in the backend.
|
|
|
|
|
*/
|
|
|
|
|
class InvoicePackageController extends BackendController
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Create the controller instance.
|
|
|
|
|
*/
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->authorizeResource(InvoicePackage::class);
|
|
|
|
|
$this->modelName = InvoicePackage::modelName();
|
|
|
|
|
$this->modelPage = InvoicePackage::modelPage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
|
* @return \Inertia\Response
|
|
|
|
|
*/
|
|
|
|
|
public function index(Request $request): \Inertia\Response
|
|
|
|
|
{
|
|
|
|
|
/** @var \Illuminate\Database\Eloquent\Builder<\App\Models\InvoicePackage> $query */
|
|
|
|
|
$query = InvoicePackage::query();
|
|
|
|
|
|
|
|
|
|
if ($request->routeIs("back.$this->modelName.trash")) {
|
|
|
|
|
$query = $query->onlyTrashed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @var string $search Search field */
|
|
|
|
|
$search = $request->search;
|
|
|
|
|
if ($search) {
|
|
|
|
|
$this->searchQuery(
|
|
|
|
|
$query,
|
|
|
|
|
$search,
|
|
|
|
|
null,
|
2026-05-19 12:25:21 +02:00
|
|
|
'name',
|
2026-04-30 15:42:04 +02:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
$searchFields = \implode(', ', [
|
2026-05-19 12:25:21 +02:00
|
|
|
trans('validation.attributes.name'),
|
2026-04-30 15:42:04 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
/** Sort columns with a query */
|
|
|
|
|
$this->sortQuery($query);
|
|
|
|
|
|
|
|
|
|
/** Custom pagination */
|
|
|
|
|
$models = $this->paginate($query);
|
|
|
|
|
|
|
|
|
|
return $this->inertiaRender("back/Pages/$this->modelPage/Index", [
|
|
|
|
|
'models' => CommonResource::collection($models),
|
|
|
|
|
'search' => $search,
|
|
|
|
|
'searchFields' => $searchFields,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
|
*
|
|
|
|
|
* @param \App\Models\InvoicePackage $invoice_package
|
|
|
|
|
* @return \Inertia\Response
|
|
|
|
|
*/
|
|
|
|
|
public function create(InvoicePackage $invoice_package): \Inertia\Response
|
|
|
|
|
{
|
|
|
|
|
return $this->inertiaRender("back/Pages/$this->modelPage/Create", [
|
|
|
|
|
'data' => CommonResource::make($invoice_package),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show a specific resource.
|
|
|
|
|
*
|
|
|
|
|
* @param \App\Models\InvoicePackage $invoice_package
|
|
|
|
|
* @return \Inertia\Response
|
|
|
|
|
*/
|
|
|
|
|
public function show(InvoicePackage $invoice_package): \Inertia\Response
|
|
|
|
|
{
|
|
|
|
|
return $this->inertiaRender("back/Pages/$this->modelPage/Show", [
|
|
|
|
|
'data' => CommonResource::make($invoice_package),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Store a newly created resource.
|
|
|
|
|
*
|
|
|
|
|
* @param \App\Http\Requests\Back\InvoicePackages\StoreInvoicePackageRequest $request
|
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
|
*/
|
|
|
|
|
public function store(StoreInvoicePackageRequest $request): \Illuminate\Http\RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
return DB::transaction(function () use ($request) {
|
|
|
|
|
$invoice_package = new InvoicePackage();
|
2026-05-19 12:25:21 +02:00
|
|
|
$invoice_package->fill($request->validated());
|
2026-04-30 15:42:04 +02:00
|
|
|
|
|
|
|
|
if ($invoice_package->saveOrFail()) {
|
|
|
|
|
return redirect()->route("back.$this->modelName.edit", $invoice_package)
|
|
|
|
|
->with('success', trans('uwil-backend::crud.messages.has_been_created', [
|
|
|
|
|
'model' => Str::ucfirst(trans_choice("models.classes.$this->modelName", 1)),
|
|
|
|
|
]));
|
|
|
|
|
}
|
|
|
|
|
return redirect()->back()
|
|
|
|
|
->with('error', trans('uwil-backend::crud.messages.cannot_be_created', [
|
|
|
|
|
'model' => Str::ucfirst(trans_choice("models.classes.$this->modelName", 1)),
|
|
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
|
*
|
|
|
|
|
* @param \App\Models\InvoicePackage $invoice_package
|
|
|
|
|
* @return \Inertia\Response
|
|
|
|
|
*/
|
|
|
|
|
public function edit(InvoicePackage $invoice_package): \Inertia\Response
|
|
|
|
|
{
|
|
|
|
|
return $this->inertiaRender("back/Pages/$this->modelPage/Edit", [
|
|
|
|
|
'data' => CommonResource::make($invoice_package),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the specified resource.
|
|
|
|
|
*
|
|
|
|
|
* @param \App\Http\Requests\Back\InvoicePackages\UpdateInvoicePackageRequest $request
|
2026-05-19 12:25:21 +02:00
|
|
|
* @param \App\Models\InvoicePackage $invoice_package
|
2026-04-30 15:42:04 +02:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
|
*/
|
|
|
|
|
public function update(
|
|
|
|
|
UpdateInvoicePackageRequest $request,
|
|
|
|
|
InvoicePackage $invoice_package
|
|
|
|
|
): \Illuminate\Http\RedirectResponse {
|
|
|
|
|
return DB::transaction(function () use ($request, $invoice_package) {
|
2026-05-19 12:25:21 +02:00
|
|
|
$invoice_package->fill($request->validated());
|
2026-04-30 15:42:04 +02:00
|
|
|
|
|
|
|
|
if ($invoice_package->saveOrFail()) {
|
|
|
|
|
return redirect()->route("back.$this->modelName.edit", $invoice_package)
|
|
|
|
|
->with('success', trans('uwil-backend::crud.messages.has_been_updated', [
|
|
|
|
|
'model' => Str::ucfirst(trans_choice("models.classes.$this->modelName", 1)),
|
|
|
|
|
]));
|
|
|
|
|
}
|
|
|
|
|
return redirect()->route("back.$this->modelName.edit", $invoice_package)
|
|
|
|
|
->with('error', trans('uwil-backend::crud.messages.cannot_be_updated', [
|
|
|
|
|
'model' => Str::ucfirst(trans_choice("models.classes.$this->modelName", 1)),
|
|
|
|
|
]));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Duplicate the specified resource.
|
|
|
|
|
*
|
|
|
|
|
* @param \App\Models\InvoicePackage $invoice_package
|
|
|
|
|
* @return \Inertia\Response
|
|
|
|
|
*/
|
|
|
|
|
public function duplicate(InvoicePackage $invoice_package): \Inertia\Response
|
|
|
|
|
{
|
|
|
|
|
return $this->create($invoice_package->replicate());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Restore the specified resource.
|
|
|
|
|
*
|
|
|
|
|
* @param integer $invoice_package
|
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
|
*/
|
|
|
|
|
public function restore(int $invoice_package): \Illuminate\Http\RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
$invoice_package = InvoicePackage::withTrashed()->findOrFail($invoice_package);
|
|
|
|
|
/** @var array<string,string> */
|
|
|
|
|
$previousQueries = [];
|
|
|
|
|
\parse_str(\parse_url(url()->previous(), \PHP_URL_QUERY), $previousQueries);
|
|
|
|
|
if ($invoice_package->restore()) {
|
|
|
|
|
return redirect()->route("back.$this->modelName.trash", $previousQueries)
|
|
|
|
|
->with('success', trans('uwil-backend::crud.messages.has_been_restored', [
|
|
|
|
|
'model' => Str::ucfirst(trans_choice("models.classes.$this->modelName", 1)),
|
|
|
|
|
]));
|
|
|
|
|
}
|
|
|
|
|
return redirect()->back()
|
|
|
|
|
->with('error', trans('uwil-backend::crud.messages.cannot_be_restored', [
|
|
|
|
|
'model' => Str::ucfirst(trans_choice("models.classes.$this->modelName", 1)),
|
|
|
|
|
]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Destroy the specified resource.
|
|
|
|
|
*
|
|
|
|
|
* @param \App\Models\InvoicePackage $invoice_package
|
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
|
*/
|
|
|
|
|
public function destroy(InvoicePackage $invoice_package): \Illuminate\Http\RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
/** @var array<string,string> */
|
|
|
|
|
$previousQueries = [];
|
|
|
|
|
\parse_str(\parse_url(url()->previous(), \PHP_URL_QUERY), $previousQueries);
|
|
|
|
|
if ($invoice_package->delete()) {
|
|
|
|
|
return redirect()->route("back.$this->modelName.index", $previousQueries)
|
|
|
|
|
->with('success', trans('uwil-backend::crud.messages.has_been_deleted', [
|
|
|
|
|
'model' => Str::ucfirst(trans_choice("models.classes.$this->modelName", 1)),
|
|
|
|
|
]));
|
|
|
|
|
}
|
|
|
|
|
return redirect()->back()
|
|
|
|
|
->with('error', trans('uwil-backend::crud.messages.cannot_be_deleted', [
|
|
|
|
|
'model' => Str::ucfirst(trans_choice("models.classes.$this->modelName", 1)),
|
|
|
|
|
]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Destroy the specified resource.
|
|
|
|
|
*
|
|
|
|
|
* @param \App\Models\InvoicePackage|integer $invoice_package
|
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
|
*/
|
|
|
|
|
public function forceDestroy(InvoicePackage|int $invoice_package): \Illuminate\Http\RedirectResponse
|
|
|
|
|
{
|
|
|
|
|
if (is_int($invoice_package)) {
|
|
|
|
|
$invoice_package = InvoicePackage::withTrashed()->findOrFail($invoice_package);
|
|
|
|
|
}
|
|
|
|
|
/** @var array<string,string> */
|
|
|
|
|
$previousQueries = [];
|
|
|
|
|
\parse_str(\parse_url(url()->previous(), \PHP_URL_QUERY), $previousQueries);
|
|
|
|
|
if ($invoice_package->forceDelete()) {
|
|
|
|
|
return redirect()->route("back.$this->modelName.trash", $previousQueries)
|
|
|
|
|
->with('success', trans('uwil-backend::crud.messages.has_been_deleted', [
|
|
|
|
|
'model' => Str::ucfirst(trans_choice("models.classes.$this->modelName", 1)),
|
|
|
|
|
]));
|
|
|
|
|
}
|
|
|
|
|
return redirect()->back()
|
|
|
|
|
->with('error', trans('uwil-backend::crud.messages.cannot_be_deleted', [
|
|
|
|
|
'model' => Str::ucfirst(trans_choice("models.classes.$this->modelName", 1)),
|
|
|
|
|
]));
|
|
|
|
|
}
|
|
|
|
|
}
|