167 lines
5.4 KiB
PHP
167 lines
5.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Bo\JobVideos\StoreJobVideoRequest;
|
|
use App\Http\Requests\Bo\JobVideos\UpdateJobVideoRequest;
|
|
use App\Models\JobVideo;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Str;
|
|
|
|
class JobVideoController extends Controller
|
|
{
|
|
/**
|
|
* Create the controller instance.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->authorizeResource(JobVideo::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 $jobVideoModels */
|
|
$jobVideoModels = JobVideo::query();
|
|
|
|
/** @var string $search Search field */
|
|
$search = $request->input('search');
|
|
if ($search) {
|
|
$this->searchQuery(
|
|
$jobVideoModels,
|
|
$search,
|
|
null,
|
|
'title',
|
|
'place',
|
|
);
|
|
}
|
|
$searchFields = \implode(', ', [
|
|
Str::ucfirst(trans('validation.attributes.title')),
|
|
trans('validation.custom.place'),
|
|
]);
|
|
|
|
/** Sort columns with a query */
|
|
$this->sortQuery($jobVideoModels);
|
|
|
|
/** Custom pagination */
|
|
$jobVideoModels = $this->paginate($jobVideoModels);
|
|
|
|
return view(
|
|
'bo.pages.job_videos.index',
|
|
compact('jobVideoModels', 'search', 'searchFields')
|
|
);
|
|
}
|
|
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @param \App\Models\JobVideo $jobVideo
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function create(JobVideo $jobVideo): \Illuminate\Contracts\View\View
|
|
{
|
|
return view('bo.pages.job_videos.create', ['jobVideoModel' => $jobVideo]);
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \App\Http\Requests\Bo\JobVideos\StoreJobVideoRequest $request
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function store(StoreJobVideoRequest $request): \Illuminate\Http\RedirectResponse
|
|
{
|
|
return DB::transaction(function () use ($request) {
|
|
$jobVideo = new JobVideo();
|
|
$jobVideo->fill($request->validated());
|
|
|
|
if ($jobVideo->saveOrFail()) {
|
|
return redirect()->route('bo.jobvideos.edit', $jobVideo)
|
|
->with('success', __('crud.messages.has_been_created', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.job_video', 1))
|
|
]));
|
|
}
|
|
return redirect()->back()
|
|
->with('error', __('crud.messages.cannot_be_created', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.job_video', 1))
|
|
]));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param \App\Models\JobVideo $jobVideo
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function edit(JobVideo $jobVideo): \Illuminate\Contracts\View\View
|
|
{
|
|
return view('bo.pages.job_videos.edit', ['jobVideoModel' => $jobVideo]);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \App\Http\Requests\Bo\JobVideos\UpdateJobVideoRequest $request
|
|
* @param \App\Models\JobVideo $jobVideo
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function update(
|
|
UpdateJobVideoRequest $request,
|
|
JobVideo $jobVideo
|
|
): \Illuminate\Http\RedirectResponse {
|
|
return DB::transaction(function () use ($request, $jobVideo) {
|
|
$jobVideo->fill($request->validated());
|
|
|
|
if ($jobVideo->saveOrFail()) {
|
|
return redirect()->route('bo.jobvideos.edit', $jobVideo)
|
|
->with('success', __('crud.messages.has_been_updated', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.job_video', 1))
|
|
]));
|
|
}
|
|
return redirect()->route('bo.jobvideos.edit', $jobVideo)
|
|
->with('error', __('crud.messages.cannot_be_updated', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.job_video', 1))
|
|
]));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param \App\Models\JobVideo $jobVideo
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function destroy(JobVideo $jobVideo): \Illuminate\Http\RedirectResponse
|
|
{
|
|
if ($jobVideo->deleteOrFail()) {
|
|
return redirect()->route('bo.jobvideos.index')
|
|
->with('success', __('crud.messages.has_been_deleted', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.job_video', 1))
|
|
]));
|
|
}
|
|
return redirect()->back()
|
|
->with('error', __('crud.messages.cannot_be_deleted', [
|
|
'model' => Str::ucfirst(trans_choice('models.classes.job_video', 1))
|
|
]));
|
|
}
|
|
|
|
/**
|
|
* Duplicate the specified resource.
|
|
*
|
|
* @param \App\Models\JobVideo $jobVideo
|
|
* @return \Illuminate\Contracts\View\View
|
|
*/
|
|
public function duplicate(JobVideo $jobVideo): \Illuminate\Contracts\View\View
|
|
{
|
|
return $this->create($jobVideo->replicate());
|
|
}
|
|
}
|