firstcommit
This commit is contained in:
0
Modules/Testimonial/app/Http/Controllers/.gitkeep
Normal file
0
Modules/Testimonial/app/Http/Controllers/.gitkeep
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Testimonial\app\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\Testimonial\app\Http\Requests\CreateTestimonialRequest;
|
||||
use Modules\Testimonial\app\Repositories\TestimonialRepository;
|
||||
|
||||
class TestimonialController extends Controller
|
||||
{
|
||||
protected $testimonialRepository;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->testimonialRepository = new TestimonialRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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') : [];
|
||||
$testimonials = $this->testimonialRepository->allTestimonials($perPage, $filter);
|
||||
|
||||
return view('testimonial::index', compact('testimonials'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('testimonial::create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(CreateTestimonialRequest $request): RedirectResponse
|
||||
{
|
||||
|
||||
try {
|
||||
$validated = $request->validated();
|
||||
|
||||
$this->testimonialRepository->storeTestimonial($validated);
|
||||
toastr()->success('Testimonial created successfully!');
|
||||
|
||||
return redirect()->route('cms.testimonials.index');
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
return view('testimonial::show');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($uuid)
|
||||
{
|
||||
$testimonial = $this->testimonialRepository->findTestimonialByUuid($uuid);
|
||||
if (!$testimonial) {
|
||||
toastr()->error('Testimonial not found');
|
||||
return back();
|
||||
}
|
||||
|
||||
return view('testimonial::edit', compact('testimonial'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(CreateTestimonialRequest $request, $uuid): RedirectResponse
|
||||
{
|
||||
|
||||
try {
|
||||
$validated = $request->validated();
|
||||
|
||||
$testimonial = $this->testimonialRepository->updateTestimonial($validated, $uuid);
|
||||
|
||||
if (!$testimonial) {
|
||||
toastr()->error('Testimonial not found !');
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
toastr()->success('Testimonial updated successfully.');
|
||||
|
||||
return redirect()->route('cms.testimonials.index');
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($uuid)
|
||||
{
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$testimonial = $this->testimonialRepository->deleteTestimonial($uuid);
|
||||
if (!$testimonial) {
|
||||
toastr()->error('Testimonial not found');
|
||||
return back();
|
||||
}
|
||||
DB::commit();
|
||||
toastr()->success('Testimonial deleted successfully.');
|
||||
|
||||
return redirect()->route('cms.testimonials.index');
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
report($th);
|
||||
|
||||
return back()->error('Something went wrong');
|
||||
}
|
||||
}
|
||||
}
|
0
Modules/Testimonial/app/Http/Middleware/.gitkeep
Normal file
0
Modules/Testimonial/app/Http/Middleware/.gitkeep
Normal file
0
Modules/Testimonial/app/Http/Requests/.gitkeep
Normal file
0
Modules/Testimonial/app/Http/Requests/.gitkeep
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Testimonial\app\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CreateTestimonialRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'required|string|max:255',
|
||||
'designation' => 'sometimes|nullable',
|
||||
'ordering' => 'required|integer|min:1',
|
||||
'statement' => 'required|string',
|
||||
'link' => 'sometimes|nullable|string',
|
||||
'status' => 'required|in:active,inactive',
|
||||
'image' => 'sometimes|nullable|image|mimes:jpeg,png,jpg,gif',
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'name.required' => 'The name field is required.',
|
||||
'name.string' => 'The name field must be a string.',
|
||||
'name.max' => 'The name may not be greater than 255 characters.',
|
||||
'ordering.required' => 'The ordering field is required.',
|
||||
'ordering.integer' => 'The ordering field must be an integer.',
|
||||
'ordering.min' => 'The ordering field must be a positive number.',
|
||||
'statement.required' => 'The statement field is required.',
|
||||
'statement.string' => 'The statement field must be a string.',
|
||||
'link.string' => 'The link field must be a string.',
|
||||
'status.required' => 'The status field is required.',
|
||||
'status.in' => 'The status field must be either "active" or "inactive".',
|
||||
'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