154 lines
4.6 KiB
PHP
154 lines
4.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Bo\BannedIps\StoreBannedIpRequest;
|
|
use App\Http\Requests\Bo\BannedIps\UpdateBannedIpRequest;
|
|
use App\Models\BannedIp;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
|
|
class BannedIpController extends Controller
|
|
{
|
|
/**
|
|
* Create the controller instance.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->authorizeResource(BannedIp::class);
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index(Request $request): View
|
|
{
|
|
/** @var Builder $bannedipModels */
|
|
$bannedipModels = BannedIp::query();
|
|
|
|
/** @var string $search Search field */
|
|
$search = $request->search;
|
|
if ($search) {
|
|
$this->searchQuery(
|
|
$bannedipModels,
|
|
$search,
|
|
null,
|
|
'ip',
|
|
);
|
|
}
|
|
$searchFields = trans('validation.custom.ip');
|
|
|
|
/** Sort columns with a query */
|
|
$this->sortQuery($bannedipModels);
|
|
|
|
/** Custom pagination */
|
|
$bannedipModels = $this->paginate($bannedipModels);
|
|
|
|
/** @var view-string $view */
|
|
$view = 'back::pages.banned-ips.index';
|
|
|
|
return view($view, ['bannedipModels' => $bannedipModels, 'search' => $search, 'searchFields' => $searchFields]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create(BannedIp $banned_ip): View
|
|
{
|
|
/** @var view-string $view */
|
|
$view = 'back::pages.banned-ips.create';
|
|
|
|
return view($view, [
|
|
'bannedipModel' => $banned_ip,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(StoreBannedIpRequest $request): RedirectResponse
|
|
{
|
|
return DB::transaction(function () use ($request) {
|
|
$banned_ip = new BannedIp();
|
|
$banned_ip->fill($request->validated());
|
|
if ($banned_ip->saveOrFail()) {
|
|
return to_route('bo.banned_ips.edit', $banned_ip)
|
|
->with('success', trans(
|
|
'crud.messages.has_been_created',
|
|
['model' => Str::singular(trans('models.classes.banned_ips'))]
|
|
));
|
|
}
|
|
|
|
return back()
|
|
->with('error', trans(
|
|
'crud.messages.cannot_be_created',
|
|
['model' => Str::singular(trans('models.classes.banned_ips'))]
|
|
));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit(BannedIp $banned_ip): View
|
|
{
|
|
/** @var view-string $view */
|
|
$view = 'back::pages.banned-ips.edit';
|
|
|
|
return view($view, [
|
|
'bannedipModel' => $banned_ip,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(UpdateBannedIpRequest $request, BannedIp $banned_ip): RedirectResponse
|
|
{
|
|
return DB::transaction(function () use ($request, $banned_ip) {
|
|
$banned_ip->fill($request->validated());
|
|
if ($banned_ip->saveOrFail()) {
|
|
return to_route('bo.banned_ips.edit', $banned_ip)
|
|
->with('success', trans(
|
|
'crud.messages.has_been_updated',
|
|
['model' => Str::singular(trans('models.classes.banned_ips'))]
|
|
));
|
|
}
|
|
|
|
return back()
|
|
->with('error', trans(
|
|
'crud.messages.cannot_be_updated',
|
|
['model' => Str::singular(trans('models.classes.banned_ips'))]
|
|
));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(BannedIp $banned_ip): RedirectResponse
|
|
{
|
|
return DB::transaction(function () use ($banned_ip) {
|
|
if ($banned_ip->deleteOrFail()) {
|
|
return to_route('bo.banned_ips.index')
|
|
->with('success', __(
|
|
'crud.messages.has_been_deleted',
|
|
['model' => Str::singular(trans('models.classes.banned_ips'))]
|
|
));
|
|
}
|
|
|
|
return back()
|
|
->with('error', __(
|
|
':crud.messages.cannot_be_deleted',
|
|
['model' => Str::singular(trans('models.classes.banned_ips'))]
|
|
));
|
|
});
|
|
}
|
|
}
|