testimonial done

This commit is contained in:
2025-06-05 17:21:28 +05:45
parent 27d26848e2
commit 9ceb854168
14 changed files with 435 additions and 4 deletions

View File

@ -10,6 +10,7 @@ use App\Models\Slider;
use App\Models\Preparation;
use App\Models\Service;
use App\Models\About;
use App\Models\Testimonial;
class FrontendController extends Controller
{
@ -20,7 +21,7 @@ class FrontendController extends Controller
$data['services'] = Service::all();
$data['abouts'] = About::all();
// $data['contact'] = Contact::first();
// $data['testimonials'] = Testimonial::all();
$data['testimonials'] = Testimonial::all();
// $data['partners'] = Partner::all();
// $data['passers'] = Passer::all();
// $data['blogs'] = Blog::latest()->take(3)->get();

View File

@ -0,0 +1,88 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Testimonial;
class TestimonialController extends Controller
{
public function index()
{
$testimonials = Testimonial::all();
return view('testimonials.index', compact('testimonials'));
}
public function create()
{
return view('testimonials.create');
}
public function store(Request $request)
{
$validated = $request->validate([
'name' => 'required|string|max:225',
'message' => 'required|string',
'image' => 'nullable|image|mimes:jpeg,png,jpg,webp|max:2048',
]);
if ($request->hasFile('image')) {
$validated['image'] = $request->file('image')->store('testimonials', 'public');
}
Testimonial::create($validated);
return redirect()->route('testimonials.index')->with('success', 'Testimonials created successfully');
}
public function destroy($id)
{
$testimonial = Testimonial::findOrFail($id);
// Optionally delete the image from storage
if ($testimonial->image && \Storage::disk('public')->exists($testimonial->image)) {
\Storage::disk('public')->delete($testimonial->image);
}
$testimonial->delete();
return redirect()->route('testimonials.index')->with('success', 'testimonial deleted successfully');
}
public function show($id)
{
$testimonial = Testimonial::findOrFail($id);
return view('testimonials.show', compact('testimonial'));
}
public function edit($id)
{
$testimonial = Testimonial::findOrFail($id);
return view('testimonials.edit', compact('testimonial'));
}
public function update(Request $request, testimonial $testimonial)
{
// dd($testimonial->toArray());
$validated = $request->validate([
'name' => 'nullable|string|max:255',
'message' => 'nullable|string',
'image' => 'nullable|image',
]);
// If image is uploaded
if ($request->hasFile('image')) {
// Delete old image if exists
if ($testimonial->image && \Storage::disk('public')->exists($testimonial->image)) {
\Storage::disk('public')->delete($testimonial->image);
}
$imagePath = $request->file('image')->store('testimonials', 'public');
$validated['image'] = $imagePath;
}
$testimonial->update($validated);
return redirect()->route('testimonials.index')->with('success', 'testimonial updated successfully');
}
}