firstcommit
This commit is contained in:
0
Modules/Service/app/Http/Controllers/.gitkeep
Normal file
0
Modules/Service/app/Http/Controllers/.gitkeep
Normal file
139
Modules/Service/app/Http/Controllers/ServiceController.php
Normal file
139
Modules/Service/app/Http/Controllers/ServiceController.php
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Service\app\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\Service\app\Http\Requests\CreateServiceRequest;
|
||||
use Modules\Service\app\Repositories\ServiceRepository;
|
||||
|
||||
class ServiceController extends Controller
|
||||
{
|
||||
protected $serviceRepository;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->serviceRepository = new ServiceRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$perPage = $request->has('per-page') ? $request->input('per-page') : null;
|
||||
$filter = $request->has('filter') ? $request->input('filter') : [];
|
||||
$services = $this->serviceRepository->allServices($perPage, $filter);
|
||||
|
||||
return view('service::index', compact('services'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('service::create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(CreateServiceRequest $request): RedirectResponse
|
||||
{
|
||||
try {
|
||||
$validated = $request->validated();
|
||||
|
||||
$this->serviceRepository->storeService($validated);
|
||||
toastr()->success('Service created successfully.');
|
||||
|
||||
return redirect()->route('cms.services.index');
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
return view('service::show');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($uuid)
|
||||
{
|
||||
$service = $this->serviceRepository->findServiceByUuid($uuid);
|
||||
if (!$service) {
|
||||
toastr()->error('Service not found.');
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
return view('service::edit', compact('service'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(CreateServiceRequest $request, $uuid): RedirectResponse
|
||||
{
|
||||
try {
|
||||
$validated = $request->validated();
|
||||
|
||||
$service = $this->serviceRepository->updateService($validated, $uuid);
|
||||
|
||||
|
||||
if (!$service) {
|
||||
toastr()->error('Service not found !');
|
||||
|
||||
return null;
|
||||
}
|
||||
toastr()->success('Service updated successfully.');
|
||||
|
||||
return redirect()->route('cms.services.index');
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($uuid)
|
||||
{
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$service = $this->serviceRepository->deleteService($uuid);
|
||||
if (!$service) {
|
||||
toastr()->error('Service not found.');
|
||||
|
||||
return back();
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
toastr()->success('Service deleted successfully.');
|
||||
|
||||
return redirect()->route('cms.services.index');
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
|
||||
return back();
|
||||
}
|
||||
}
|
||||
}
|
0
Modules/Service/app/Http/Middleware/.gitkeep
Normal file
0
Modules/Service/app/Http/Middleware/.gitkeep
Normal file
0
Modules/Service/app/Http/Requests/.gitkeep
Normal file
0
Modules/Service/app/Http/Requests/.gitkeep
Normal file
66
Modules/Service/app/Http/Requests/CreateServiceRequest.php
Normal file
66
Modules/Service/app/Http/Requests/CreateServiceRequest.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Service\app\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CreateServiceRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'required|string|max:255',
|
||||
'summary' => 'sometimes|nullable|string',
|
||||
'detail' => 'sometimes|nullable|string',
|
||||
'status' => 'required|in:active,inactive',
|
||||
'meta_title' => 'sometimes|nullable|string|max:255',
|
||||
'meta_description' => 'sometimes|nullable|string',
|
||||
'meta_keywords' => 'sometimes|nullable|string|max:255',
|
||||
'slug' => 'required',
|
||||
// 'homepage_flag' => 'nullable|boolean',
|
||||
'image' => 'sometimes|nullable|image|mimes:jpeg,png,jpg,gif',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'title.required' => 'The title field is required.',
|
||||
'title.string' => 'The title field must be a string.',
|
||||
'title.max' => 'The title may not be greater than 255 characters.',
|
||||
|
||||
'summary.string' => 'The summary field must be a string.',
|
||||
|
||||
'detail.string' => 'The detail field must be a string.',
|
||||
|
||||
'status.required' => 'The status field is required.',
|
||||
'status.in' => 'The status field must be either "active" or "inactive".',
|
||||
|
||||
'meta_title.string' => 'The meta title field must be a string.',
|
||||
'meta_title.max' => 'The meta title may not be greater than 255 characters.',
|
||||
|
||||
'meta_description.string' => 'The meta description field must be a string.',
|
||||
|
||||
'meta_keywords.string' => 'The meta keywords field must be a string.',
|
||||
'meta_keywords.max' => 'The meta keywords may not be greater than 255 characters.',
|
||||
|
||||
'slug.required' => 'The slug field is required.',
|
||||
|
||||
'image.image' => 'The image must be an image file.',
|
||||
'image.mimes' => 'The image must be a file of type: jpeg, png, jpg, gif.',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
// return auth()->user()->can('users.create');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user