169 lines
6.1 KiB
PHP
169 lines
6.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\Bo;
|
||
|
|
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use App\Http\Requests\Bo\HistoricalMilestones\StoreHistoricalMilestoneRequest;
|
||
|
|
use App\Http\Requests\Bo\HistoricalMilestones\UpdateHistoricalMilestoneRequest;
|
||
|
|
use App\Models\HistoricalMilestone;
|
||
|
|
use App\Traits\Controllers\UpdateModelPublished;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use Illuminate\Support\Facades\DB;
|
||
|
|
use Illuminate\Support\Str;
|
||
|
|
|
||
|
|
class HistoricalMilestoneController extends Controller
|
||
|
|
{
|
||
|
|
use UpdateModelPublished;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Create the controller instance.
|
||
|
|
*/
|
||
|
|
public function __construct()
|
||
|
|
{
|
||
|
|
$this->authorizeResource(HistoricalMilestone::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 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
|
||
|
|
{
|
||
|
|
/** @var \Illuminate\Database\Eloquent\Builder $historicalMilestoneModels */
|
||
|
|
$historicalMilestoneModels = HistoricalMilestone::query();
|
||
|
|
|
||
|
|
/** @var string $search Search field */
|
||
|
|
$search = $request->search;
|
||
|
|
if ($search) {
|
||
|
|
$this->searchQuery(
|
||
|
|
$historicalMilestoneModels,
|
||
|
|
$search,
|
||
|
|
null,
|
||
|
|
'text',
|
||
|
|
);
|
||
|
|
}
|
||
|
|
$searchFields = \implode(', ', [
|
||
|
|
Str::ucfirst(trans('validation.attributes.text')),
|
||
|
|
]);
|
||
|
|
|
||
|
|
/** Sort columns with a query */
|
||
|
|
$this->sortQuery($historicalMilestoneModels);
|
||
|
|
|
||
|
|
/** Custom pagination */
|
||
|
|
$historicalMilestoneModels = $this->paginate($historicalMilestoneModels);
|
||
|
|
|
||
|
|
return view(
|
||
|
|
'bo.pages.historicalmilestones.index',
|
||
|
|
compact('historicalMilestoneModels', 'search', 'searchFields')
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Show the form for creating a new resource.
|
||
|
|
*
|
||
|
|
* @param \App\Models\HistoricalMilestone $historicalMilestone
|
||
|
|
* @return \Illuminate\Contracts\View\View
|
||
|
|
*/
|
||
|
|
public function create(HistoricalMilestone $historicalMilestone): \Illuminate\Contracts\View\View
|
||
|
|
{
|
||
|
|
return view('bo.pages.historicalmilestones.create', ['historicalMilestoneModel' => $historicalMilestone]);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Store a newly created resource in storage.
|
||
|
|
*
|
||
|
|
* @param \App\Http\Requests\Bo\HistoricalMilestone\StoreHistoricalMilestoneRequest $request
|
||
|
|
* @return \Illuminate\Http\RedirectResponse
|
||
|
|
*/
|
||
|
|
public function store(StoreHistoricalMilestoneRequest $request): \Illuminate\Http\RedirectResponse
|
||
|
|
{
|
||
|
|
return DB::transaction(function () use ($request) {
|
||
|
|
$historicalMilestone = new HistoricalMilestone();
|
||
|
|
$historicalMilestone->fill($request->validated());
|
||
|
|
|
||
|
|
if ($historicalMilestone->saveOrFail()) {
|
||
|
|
return redirect()->route('bo.historicalmilestones.edit', $historicalMilestone)
|
||
|
|
->with('success', __('crud.messages.has_been_created', [
|
||
|
|
'model' => Str::ucfirst(__('models.classes.historicalMilestone'))
|
||
|
|
]));
|
||
|
|
}
|
||
|
|
return redirect()->back()
|
||
|
|
->with('error', __('crud.messages.cannot_be_created', [
|
||
|
|
'model' => Str::ucfirst(__('models.classes.historicalMilestone'))
|
||
|
|
]));
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Show the form for editing the specified resource.
|
||
|
|
*
|
||
|
|
* @param App\Models\HistoricalMilestone $historicalMilestone
|
||
|
|
* @return \Illuminate\Contracts\View\View
|
||
|
|
*/
|
||
|
|
public function edit(HistoricalMilestone $historicalMilestone): \Illuminate\Contracts\View\View
|
||
|
|
{
|
||
|
|
return view('bo.pages.historicalmilestones.edit', ['historicalMilestoneModel' => $historicalMilestone]);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Update the specified resource in storage.
|
||
|
|
*
|
||
|
|
* @param \App\Http\Requests\Bo\HistoricalMilestone\UpdateHistoricalMilestoneRequest $request
|
||
|
|
* @param \App\Models\HistoricalMilestone $historicalMilestone
|
||
|
|
* @return \Illuminate\Http\RedirectResponse
|
||
|
|
*/
|
||
|
|
public function update(
|
||
|
|
UpdateHistoricalMilestoneRequest $request,
|
||
|
|
HistoricalMilestone $historicalMilestone
|
||
|
|
): \Illuminate\Http\RedirectResponse {
|
||
|
|
return DB::transaction(function () use ($request, $historicalMilestone) {
|
||
|
|
$historicalMilestone->fill($request->validated());
|
||
|
|
|
||
|
|
if ($historicalMilestone->saveOrFail()) {
|
||
|
|
return redirect()->route('bo.historicalmilestones.edit', $historicalMilestone)
|
||
|
|
->with('success', __('crud.messages.has_been_updated', [
|
||
|
|
'model' => Str::ucfirst(__('models.classes.historicalMilestone'))
|
||
|
|
]));
|
||
|
|
}
|
||
|
|
return redirect()->route('bo.historicalmilestones.edit', $historicalMilestone)
|
||
|
|
->with('error', __('crud.messages.cannot_be_updated', [
|
||
|
|
'model' => Str::ucfirst(__('models.classes.historicalMilestone'))
|
||
|
|
]));
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Remove the specified resource from storage.
|
||
|
|
*
|
||
|
|
* @param \App\Models\HistoricalMilestone $historicalMilestone
|
||
|
|
* @return \Illuminate\Http\RedirectResponse
|
||
|
|
*/
|
||
|
|
public function destroy(HistoricalMilestone $historicalMilestone): \Illuminate\Http\RedirectResponse
|
||
|
|
{
|
||
|
|
if ($historicalMilestone->deleteOrFail()) {
|
||
|
|
return redirect()->route('bo.historicalmilestones.index')
|
||
|
|
->with('success', __('crud.messages.has_been_deleted', [
|
||
|
|
'model' => Str::ucfirst(__('models.classes.historicalMilestone'))
|
||
|
|
]));
|
||
|
|
}
|
||
|
|
return redirect()->back()
|
||
|
|
->with('error', __('crud.messages.cannot_be_deleted', [
|
||
|
|
'model' => Str::ucfirst(__('models.classes.historicalMilestone'))
|
||
|
|
]));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Duplicate the specified resource.
|
||
|
|
*
|
||
|
|
* @param \App\Models\HistoricalMilestone $historicalMilestone
|
||
|
|
* @return \Illuminate\Contracts\View\View
|
||
|
|
*/
|
||
|
|
public function duplicate(HistoricalMilestone $historicalMilestone): \Illuminate\Contracts\View\View
|
||
|
|
{
|
||
|
|
return $this->create($historicalMilestone->replicate());
|
||
|
|
}
|
||
|
|
}
|