2020-10-23 12:14:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
2022-01-10 14:02:25 +01:00
|
|
|
namespace App\Http\Controllers\Bo;
|
2020-10-23 12:14:07 +02:00
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
2023-08-21 10:15:14 +00:00
|
|
|
use App\Http\Requests\Bo\BannedIps\StoreBannedIpRequest;
|
|
|
|
|
use App\Http\Requests\Bo\BannedIps\UpdateBannedIpRequest;
|
2022-01-11 12:39:28 +01:00
|
|
|
use App\Models\BannedIp;
|
2020-10-23 12:14:07 +02:00
|
|
|
use Illuminate\Http\Request;
|
2023-08-21 10:15:14 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
use Illuminate\Support\Str;
|
2020-10-23 12:14:07 +02:00
|
|
|
|
2022-01-11 12:39:28 +01:00
|
|
|
class BannedIpController extends Controller
|
2020-10-23 12:14:07 +02:00
|
|
|
{
|
2023-12-05 12:33:25 +01:00
|
|
|
/**
|
|
|
|
|
* Create the controller instance.
|
|
|
|
|
*/
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->authorizeResource(BannedIp::class);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-21 10:15:14 +00:00
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
|
*/
|
|
|
|
|
public function index(Request $request): \Illuminate\Contracts\View\View
|
2021-08-18 17:08:02 +02:00
|
|
|
{
|
2023-08-21 10:15:14 +00:00
|
|
|
/** @var \Illuminate\Database\Eloquent\Builder $bannedipModels */
|
|
|
|
|
$bannedipModels = BannedIp::query();
|
|
|
|
|
|
|
|
|
|
/** @var string $search Search field */
|
|
|
|
|
$search = $request->search;
|
|
|
|
|
if ($search) {
|
|
|
|
|
$this->searchQuery(
|
|
|
|
|
$bannedipModels,
|
|
|
|
|
$search,
|
|
|
|
|
null,
|
|
|
|
|
'ip',
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-11-23 17:31:28 +01:00
|
|
|
$searchFields = trans('validation.custom.ip');
|
2023-08-21 10:15:14 +00:00
|
|
|
|
|
|
|
|
/** Sort columns with a query */
|
|
|
|
|
$this->sortQuery($bannedipModels);
|
|
|
|
|
|
|
|
|
|
/** Custom pagination */
|
2023-11-23 17:31:28 +01:00
|
|
|
$bannedipModels = $this->paginate($bannedipModels);
|
2023-08-21 10:15:14 +00:00
|
|
|
|
2023-11-20 17:22:24 +01:00
|
|
|
return view('back::pages.banned-ips.index', compact('bannedipModels', 'search', 'searchFields'));
|
2023-08-21 10:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
|
*
|
2023-11-30 14:46:08 +01:00
|
|
|
* @param \App\Models\BannedIp $banned_ip
|
2023-08-21 10:15:14 +00:00
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
|
*/
|
2023-11-30 14:46:08 +01:00
|
|
|
public function create(BannedIp $banned_ip): \Illuminate\Contracts\View\View
|
2023-08-21 10:15:14 +00:00
|
|
|
{
|
2023-11-20 17:22:24 +01:00
|
|
|
return view('back::pages.banned-ips.create', [
|
2023-11-30 14:46:08 +01:00
|
|
|
'bannedipModel' => $banned_ip,
|
2023-08-21 10:15:14 +00:00
|
|
|
]);
|
2020-10-23 12:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-21 10:15:14 +00:00
|
|
|
/**
|
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
|
*
|
|
|
|
|
* @param \App\Http\Requests\Bo\BannedIps\StoreBannedIpRequest $request
|
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
|
*/
|
|
|
|
|
public function store(StoreBannedIpRequest $request): \Illuminate\Http\RedirectResponse
|
2021-08-18 17:08:02 +02:00
|
|
|
{
|
2023-08-21 10:15:14 +00:00
|
|
|
return DB::transaction(function () use ($request) {
|
2023-11-30 14:46:08 +01:00
|
|
|
$banned_ip = new BannedIp();
|
|
|
|
|
$banned_ip->fill($request->validated());
|
|
|
|
|
if ($banned_ip->saveOrFail()) {
|
2023-08-21 10:15:14 +00:00
|
|
|
return redirect()
|
2023-11-30 14:46:08 +01:00
|
|
|
->route('bo.banned_ips.edit', $banned_ip)
|
2023-08-21 10:15:14 +00:00
|
|
|
->with('success', trans(
|
|
|
|
|
'crud.messages.has_been_created',
|
2023-11-30 14:46:08 +01:00
|
|
|
['model' => Str::singular(trans('models.classes.banned_ips'))]
|
2023-08-21 10:15:14 +00:00
|
|
|
));
|
2020-10-23 12:14:07 +02:00
|
|
|
}
|
2023-08-21 10:15:14 +00:00
|
|
|
return redirect()
|
|
|
|
|
->back()
|
|
|
|
|
->with('error', trans(
|
|
|
|
|
'crud.messages.cannot_be_created',
|
2023-11-30 14:46:08 +01:00
|
|
|
['model' => Str::singular(trans('models.classes.banned_ips'))]
|
2023-08-21 10:15:14 +00:00
|
|
|
));
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-10-23 12:14:07 +02:00
|
|
|
|
2023-08-21 10:15:14 +00:00
|
|
|
/**
|
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
|
*
|
2023-11-30 14:46:08 +01:00
|
|
|
* @param \App\Models\BannedIp $banned_ip
|
2023-08-21 10:15:14 +00:00
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
|
*/
|
2023-11-30 14:46:08 +01:00
|
|
|
public function edit(BannedIp $banned_ip): \Illuminate\Contracts\View\View
|
2023-08-21 10:15:14 +00:00
|
|
|
{
|
2023-11-20 17:22:24 +01:00
|
|
|
return view('back::pages.banned-ips.edit', [
|
2023-11-30 14:46:08 +01:00
|
|
|
'bannedipModel' => $banned_ip,
|
2023-08-21 10:15:14 +00:00
|
|
|
]);
|
2020-10-23 12:14:07 +02:00
|
|
|
}
|
|
|
|
|
|
2023-08-21 10:15:14 +00:00
|
|
|
/**
|
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
|
*
|
|
|
|
|
* @param \App\Http\Requests\Bo\BannedIps\UpdateBannedIpRequest $request
|
2023-11-30 14:46:08 +01:00
|
|
|
* @param \App\Models\BannedIp $banned_ip
|
2023-08-21 10:15:14 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
|
*/
|
2023-11-30 14:46:08 +01:00
|
|
|
public function update(UpdateBannedIpRequest $request, BannedIp $banned_ip): \Illuminate\Http\RedirectResponse
|
2021-08-18 17:08:02 +02:00
|
|
|
{
|
2023-11-30 14:46:08 +01:00
|
|
|
return DB::transaction(function () use ($request, $banned_ip) {
|
|
|
|
|
$banned_ip->fill($request->validated());
|
|
|
|
|
if ($banned_ip->saveOrFail()) {
|
2023-08-21 10:15:14 +00:00
|
|
|
return redirect()
|
2023-11-30 14:46:08 +01:00
|
|
|
->route('bo.banned_ips.edit', $banned_ip)
|
2023-08-21 10:15:14 +00:00
|
|
|
->with('success', trans(
|
|
|
|
|
'crud.messages.has_been_updated',
|
2023-11-30 14:46:08 +01:00
|
|
|
['model' => Str::singular(trans('models.classes.banned_ips'))]
|
2023-08-21 10:15:14 +00:00
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
return redirect()
|
|
|
|
|
->back()
|
|
|
|
|
->with('error', trans(
|
|
|
|
|
'crud.messages.cannot_be_updated',
|
2023-11-30 14:46:08 +01:00
|
|
|
['model' => Str::singular(trans('models.classes.banned_ips'))]
|
2023-08-21 10:15:14 +00:00
|
|
|
));
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-10-23 12:14:07 +02:00
|
|
|
|
2023-08-21 10:15:14 +00:00
|
|
|
/**
|
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
|
*
|
2023-11-30 14:46:08 +01:00
|
|
|
* @param \App\Models\BannedIp $banned_ip
|
2023-08-21 10:15:14 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
|
|
|
*/
|
2023-11-30 14:46:08 +01:00
|
|
|
public function destroy(BannedIp $banned_ip): \Illuminate\Http\RedirectResponse
|
2023-08-21 10:15:14 +00:00
|
|
|
{
|
2023-11-30 14:46:08 +01:00
|
|
|
return DB::transaction(function () use ($banned_ip) {
|
|
|
|
|
if ($banned_ip->deleteOrFail()) {
|
2023-08-21 10:15:14 +00:00
|
|
|
return redirect()
|
2023-11-30 14:46:08 +01:00
|
|
|
->route('bo.banned_ips.index')
|
2023-08-21 10:15:14 +00:00
|
|
|
->with('success', __(
|
|
|
|
|
'crud.messages.has_been_deleted',
|
2023-11-30 14:46:08 +01:00
|
|
|
['model' => Str::singular(trans('models.classes.banned_ips'))]
|
2023-08-21 10:15:14 +00:00
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
return redirect()
|
|
|
|
|
->back()
|
|
|
|
|
->with('error', __(
|
|
|
|
|
':crud.messages.cannot_be_deleted',
|
2023-11-30 14:46:08 +01:00
|
|
|
['model' => Str::singular(trans('models.classes.banned_ips'))]
|
2023-08-21 10:15:14 +00:00
|
|
|
));
|
|
|
|
|
});
|
2020-10-23 12:14:07 +02:00
|
|
|
}
|
|
|
|
|
}
|