61 lines
2.0 KiB
PHP
61 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Modules\Testimonials\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\View\View;
|
|
use Modules\Testimonials\Models\Testimonial;
|
|
|
|
final class TestimonialController extends Controller
|
|
{
|
|
public function index(): View
|
|
{
|
|
return view('testimonials::admin.index', ['records' => Testimonial::query()->latest()->paginate(20)]);
|
|
}
|
|
|
|
public function create(): View
|
|
{
|
|
return view('testimonials::admin.form');
|
|
}
|
|
|
|
public function store(Request $request): RedirectResponse
|
|
{
|
|
$data = $request->validate(['name' => ['required', 'string', 'max:255'],
|
|
'company' => ['nullable', 'string'],
|
|
'content' => ['required', 'string'],
|
|
'rating' => ['nullable', 'integer', 'min:0'],
|
|
'enabled' => ['sometimes', 'boolean']]);
|
|
$data['enabled'] = $request->boolean('enabled');
|
|
Testimonial::create($data);
|
|
|
|
return redirect()->route('administration.testimonials.index')->with('status', 'Testimonial created.');
|
|
}
|
|
|
|
public function edit(Testimonial $testimonial): View
|
|
{
|
|
return view('testimonials::admin.form', ['record' => $testimonial]);
|
|
}
|
|
|
|
public function update(Request $request, Testimonial $testimonial): RedirectResponse
|
|
{
|
|
$data = $request->validate(['name' => ['required', 'string', 'max:255'],
|
|
'company' => ['nullable', 'string'],
|
|
'content' => ['required', 'string'],
|
|
'rating' => ['nullable', 'integer', 'min:0'],
|
|
'enabled' => ['sometimes', 'boolean']]);
|
|
$data['enabled'] = $request->boolean('enabled');
|
|
$testimonial->update($data);
|
|
|
|
return redirect()->route('administration.testimonials.index')->with('status', 'Testimonial updated.');
|
|
}
|
|
|
|
public function destroy(Testimonial $testimonial): RedirectResponse
|
|
{
|
|
$testimonial->delete();
|
|
|
|
return back()->with('status', 'Testimonial deleted.');
|
|
}
|
|
}
|