sliders done
This commit is contained in:
@@ -23,16 +23,16 @@ class CompanyController extends Controller
|
||||
{
|
||||
// Store the validated data from the form
|
||||
$validatedData = $request->validated();
|
||||
|
||||
|
||||
// Handle the logo upload if it exists
|
||||
if ($request->hasFile('logo')) {
|
||||
$logoPath = $request->file('logo')->store('logos', 'public');
|
||||
$validatedData['logo'] = $logoPath;
|
||||
}
|
||||
|
||||
|
||||
// Create the company with the validated data
|
||||
$company = \App\Models\Company::create($validatedData);
|
||||
|
||||
$company = Company::create($validatedData);
|
||||
|
||||
// Redirect or return a response
|
||||
return redirect()->route('companies.index')->with('success', 'Company created successfully.');
|
||||
}
|
||||
@@ -51,20 +51,20 @@ class CompanyController extends Controller
|
||||
{
|
||||
// Store the validated data from the form
|
||||
$validatedData = $request->validated();
|
||||
|
||||
|
||||
// Handle the logo upload if it exists
|
||||
if ($request->hasFile('logo')) {
|
||||
$logoPath = $request->file('logo')->store('logos', 'public');
|
||||
$validatedData['logo'] = $logoPath;
|
||||
}
|
||||
|
||||
|
||||
// Update the company with the validated data
|
||||
$company->update($validatedData);
|
||||
|
||||
|
||||
// Redirect or return a response
|
||||
return redirect()->route('companies.index')->with('success', 'Company updated successfully.');
|
||||
}
|
||||
|
||||
|
||||
public function destroy(Company $company)
|
||||
{
|
||||
$company->delete();
|
||||
|
45
app/Http/Controllers/FrontendController.php
Normal file
45
app/Http/Controllers/FrontendController.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
// app/Http/Controllers/FrontendController.php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Post;
|
||||
use App\Models\Slider;
|
||||
|
||||
class FrontendController extends Controller
|
||||
{
|
||||
public function homePage()
|
||||
{
|
||||
$data['sliderItems'] = Slider::all();
|
||||
// $data['preparations'] = Preparation::all();
|
||||
// $data['services'] = Service::all();
|
||||
// $data['about'] = About::all();
|
||||
// $data['contact'] = Contact::first();
|
||||
// $data['testimonials'] = Testimonial::all();
|
||||
// $data['partners'] = Partner::all();
|
||||
// $data['passers'] = Passer::all();
|
||||
// $data['blogs'] = Blog::latest()->take(3)->get();
|
||||
|
||||
return view('frontend.home',$data);
|
||||
}
|
||||
public function aboutPage()
|
||||
{
|
||||
$posts = Post::all();
|
||||
return view('frontend.about', compact('posts'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
slider
|
||||
preparation
|
||||
service
|
||||
about
|
||||
contact
|
||||
testimonial
|
||||
partners
|
||||
passers
|
||||
blog
|
||||
*/
|
@@ -58,4 +58,5 @@ class PostController extends Controller
|
||||
|
||||
return redirect()->route('posts.index')->with('success', 'Post deleted successfully.');
|
||||
}
|
||||
|
||||
}
|
||||
|
80
app/Http/Controllers/PreparationController.php
Normal file
80
app/Http/Controllers/PreparationController.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Preparation;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PreparationController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$preparations = PreparationController::all();
|
||||
return view('preparation.index', compact('preparations'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('posts.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'title' => 'required|string|max:225',
|
||||
'content' => 'required|string',
|
||||
]);
|
||||
|
||||
Preparation::create($validated);
|
||||
return redirect()->route('preparation.index')->with('success', 'Preparation created successfully');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
return view('preparations.show', compact('preparation'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(string $id)
|
||||
{
|
||||
return view('preparations.edit', compact('preparation'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, Preparation $preparation)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'title' => 'required|string|max:225',
|
||||
'content' => 'required|string',
|
||||
]);
|
||||
|
||||
$preparation->update($validated);
|
||||
return redirect()->route('preparation.index')->with('success', 'Preparation updated successfully');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(Preparation $preparation)
|
||||
{
|
||||
$preparation->delete();
|
||||
|
||||
return redirect()->route('preparation.index')->with('success', 'Preparation deleted successfully');
|
||||
}
|
||||
}
|
92
app/Http/Controllers/SliderController.php
Normal file
92
app/Http/Controllers/SliderController.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Slider;
|
||||
|
||||
class SliderController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$sliders = Slider::all();
|
||||
return view('sliders.index', compact('sliders'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('sliders.create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
if ($request->hasFile('logo')) {
|
||||
$logoPath = $request->file('logo')->store('logos', 'public');
|
||||
$validatedData['logo'] = $logoPath;
|
||||
}
|
||||
// $imagePath = $request->file('image')->store('sliders', 'public');
|
||||
$slider = Slider::create([
|
||||
'title' => $request->title,
|
||||
'subtitle' => $request->subtitle,
|
||||
'description' => $request->description,
|
||||
// 'image' => hasFile('image'),
|
||||
'button_text' => $request->button_text,
|
||||
'button_url' => $request->button_url,
|
||||
]);
|
||||
return redirect()->route('sliders.index')->with('success', 'Slider created successfully');
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$slider = Slider::findOrFail($id);
|
||||
|
||||
// Optionally delete the image from storage
|
||||
if ($slider->image && \Storage::disk('public')->exists($slider->image)) {
|
||||
\Storage::disk('public')->delete($slider->image);
|
||||
}
|
||||
|
||||
$slider->delete();
|
||||
|
||||
return redirect()->route('sliders.index')->with('success', 'Slider deleted successfully');
|
||||
}
|
||||
public function show($id)
|
||||
{
|
||||
$slider = Slider::findOrFail($id);
|
||||
return view('sliders.show', compact('slider'));
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$slider = Slider::findOrFail($id);
|
||||
return view('sliders.edit', compact('slider'));
|
||||
}
|
||||
|
||||
public function update(Request $request, Slider $slider)
|
||||
{
|
||||
// dd($slider->toArray());
|
||||
$validated = $request->validate([
|
||||
'title' => 'nullable|string|max:255',
|
||||
'subtitle' => 'nullable|string|max:255',
|
||||
'description' => 'nullable|string',
|
||||
'button_text' => 'nullable|string|max:255',
|
||||
'button_url' => 'nullable|string|max:255',
|
||||
'image' => 'nullable|image',
|
||||
]);
|
||||
|
||||
// If image is uploaded
|
||||
if ($request->hasFile('image')) {
|
||||
// Delete old image if exists
|
||||
if ($slider->image && \Storage::disk('public')->exists($slider->image)) {
|
||||
\Storage::disk('public')->delete($slider->image);
|
||||
}
|
||||
$imagePath = $request->file('image')->store('sliders', 'public');
|
||||
$validated['image'] = $imagePath;
|
||||
}
|
||||
|
||||
$slider->update($validated);
|
||||
|
||||
return redirect()->route('sliders.index')->with('success', 'Slider updated successfully');
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user