feat: New design and optimization
This commit is contained in:
@@ -4,6 +4,9 @@ namespace App\Http\Controllers\Client;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Carousel;
|
||||
use App\Models\Faq;
|
||||
use App\Models\Product;
|
||||
use App\Models\Testimonial;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Storage;
|
||||
@@ -13,6 +16,7 @@ class HomeController extends Controller
|
||||
public function home()
|
||||
{
|
||||
$carousel = Carousel::all();
|
||||
$testimonail = Testimonial::all();
|
||||
|
||||
|
||||
$response = [
|
||||
@@ -21,6 +25,14 @@ class HomeController extends Controller
|
||||
"alt" => $item->alt,
|
||||
"image_url" => $item->image_url ? asset(Storage::url($item->image_url)) : null,
|
||||
];
|
||||
}),
|
||||
"testimonial" => $testimonail->map(function ($item) {
|
||||
return [
|
||||
"name" => $item->name,
|
||||
"location" => $item->location,
|
||||
"image" => $item->image ? asset(Storage::url($item->image)) : null,
|
||||
"description" => $item->description
|
||||
];
|
||||
})
|
||||
];
|
||||
return Inertia::render('welcome', ['data' => $response]);
|
||||
@@ -28,12 +40,39 @@ class HomeController extends Controller
|
||||
}
|
||||
public function product()
|
||||
{
|
||||
return Inertia::render('product');
|
||||
$product = Product::all();
|
||||
$productResponse = $product->map(function ($item) {
|
||||
return [
|
||||
"id" => $item->id,
|
||||
"title" => $item->title,
|
||||
"type" => $item->type,
|
||||
"image_url" => $item->image_url ? asset(Storage::url($item->image_url)) : null,
|
||||
];
|
||||
});
|
||||
return Inertia::render('product', ['product' => $productResponse]);
|
||||
}
|
||||
public function art()
|
||||
{
|
||||
return Inertia::render('art');
|
||||
}
|
||||
|
||||
public function bespoke()
|
||||
{
|
||||
$product = Product::where("type", "bespoke")->get();
|
||||
$productResponse = $product->map(function ($item) {
|
||||
return [
|
||||
"id" => $item->id,
|
||||
"title" => $item->title,
|
||||
"type" => $item->type,
|
||||
"image_url" => $item->image_url ? asset(Storage::url($item->image_url)) : null,
|
||||
];
|
||||
})->values();
|
||||
return Inertia::render("bespoke", ["product" => $productResponse]);
|
||||
}
|
||||
public function gallery()
|
||||
{
|
||||
return Inertia::render("gallery");
|
||||
}
|
||||
public function contact()
|
||||
{
|
||||
return Inertia::render('contact');
|
||||
|
||||
63
app/Http/Controllers/Client/ProductController.php
Normal file
63
app/Http/Controllers/Client/ProductController.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\client;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Storage;
|
||||
|
||||
class ProductController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$product = Product::all();
|
||||
$productResponse = $product->map(function ($item) {
|
||||
return [
|
||||
"id" => $item->id,
|
||||
"title" => $item->title,
|
||||
"type" => $item->type,
|
||||
"image_url" => $item->image_url ? asset(Storage::url($item->image_url)) : null,
|
||||
];
|
||||
});
|
||||
|
||||
return Inertia::render("dashboard/products/index", ['product' => $productResponse]);
|
||||
}
|
||||
|
||||
public function productAdd()
|
||||
{
|
||||
return Inertia::render("dashboard/products/add");
|
||||
}
|
||||
public function productAddPost(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
"title" => "required|string",
|
||||
"type" => "required|string",
|
||||
"image_url" => "file"
|
||||
]);
|
||||
|
||||
if ($request->hasFile('image_url')) {
|
||||
$path = $request->file('image_url')->store('product', 'public');
|
||||
|
||||
$product = Product::create([
|
||||
'title' => $validated['title'],
|
||||
"type" => $validated['type'],
|
||||
'image_url' => $path
|
||||
]);
|
||||
|
||||
$productResponse = [
|
||||
"title" => $product->title,
|
||||
"type" => $product->type,
|
||||
"image_url" => $product->image_url ? asset(Storage::url($product->image_url)) : null,
|
||||
];
|
||||
|
||||
return to_route('dashboard.product.index', $productResponse);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'File upload failed',
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
@@ -4,20 +4,57 @@ namespace App\Http\Controllers\Client;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\testimonialRequest;
|
||||
use App\Models\testimonial;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Spatie\LaravelImageOptimizer\Facades\ImageOptimizer;
|
||||
use Storage;
|
||||
|
||||
class TestimonialController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return Inertia::render('dashboard/testimonial');
|
||||
$testimonial = Testimonial::all();
|
||||
$testimonialResponse = $testimonial->map(function ($item) {
|
||||
return [
|
||||
"name" => $item->name,
|
||||
"description" => $item->description,
|
||||
"location" => $item->location,
|
||||
"image" => $item->image ? asset(Storage::url($item->image)) : null,
|
||||
];
|
||||
});
|
||||
|
||||
return Inertia::render('dashboard/testimonial', ["testimonial" => $testimonialResponse]);
|
||||
}
|
||||
|
||||
public function store(testimonialRequest $request)
|
||||
{
|
||||
$request->validated();
|
||||
|
||||
dd($request);
|
||||
if ($request->hasFile('image')) {
|
||||
$path = $request->file('image')->store('testimonial', 'public');
|
||||
$fullPath = storage_path('app/public/' . $path);
|
||||
ImageOptimizer::optimize($fullPath);
|
||||
|
||||
$testimonial = Testimonial::create([
|
||||
"name" => $request->name,
|
||||
"location" => $request->location,
|
||||
"description" => $request->description,
|
||||
"image" => $path
|
||||
]);
|
||||
|
||||
$testimonialResponse = [
|
||||
"name" => $testimonial->name,
|
||||
"location" => $testimonial->location,
|
||||
"description" => $testimonial->description,
|
||||
"image" => $testimonial->image ? asset(Storage::url($testimonial->image)) : null
|
||||
];
|
||||
|
||||
return to_route('home', $testimonialResponse);
|
||||
}
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'File upload failed',
|
||||
], 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Inspiring;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Inertia\Middleware;
|
||||
|
||||
class HandleInertiaRequests extends Middleware
|
||||
@@ -38,6 +41,10 @@ class HandleInertiaRequests extends Middleware
|
||||
{
|
||||
[$message, $author] = str(Inspiring::quotes()->random())->explode('-');
|
||||
|
||||
$locale = Session::get('locale', 'en');
|
||||
App::setLocale($locale);
|
||||
|
||||
|
||||
return [
|
||||
...parent::share($request),
|
||||
'name' => config('app.name'),
|
||||
@@ -45,7 +52,9 @@ class HandleInertiaRequests extends Middleware
|
||||
'auth' => [
|
||||
'user' => $request->user(),
|
||||
],
|
||||
'sidebarOpen' => ! $request->hasCookie('sidebar_state') || $request->cookie('sidebar_state') === 'true',
|
||||
'sidebarOpen' => !$request->hasCookie('sidebar_state') || $request->cookie('sidebar_state') === 'true',
|
||||
'locale' => $locale,
|
||||
'translations' => trans("message")
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,11 +23,9 @@ class testimonialRequest extends FormRequest
|
||||
{
|
||||
return [
|
||||
'name' => 'required|string',
|
||||
'rating' => 'required|string',
|
||||
'company' => 'string',
|
||||
'post' => 'string',
|
||||
'location' => 'string',
|
||||
'description' => 'required|string'
|
||||
'description' => 'required|string',
|
||||
'image' => 'required|file'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
14
app/Models/Product.php
Normal file
14
app/Models/Product.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Product extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'image_url',
|
||||
'type',
|
||||
];
|
||||
}
|
||||
@@ -4,14 +4,12 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class testimonial extends Model
|
||||
class Testimonial extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'company',
|
||||
'post',
|
||||
'location',
|
||||
'rating',
|
||||
'description'
|
||||
'description',
|
||||
'image'
|
||||
];
|
||||
}
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
@@ -19,6 +22,18 @@ class AppServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
Inertia::share([
|
||||
'locale' => function () {
|
||||
$locale = Session::get('locale', config('app.locale'));
|
||||
App::setLocale($locale);
|
||||
return $locale;
|
||||
},
|
||||
'translations' => function () {
|
||||
$locale = Session::get('locale', config('app.locale'));
|
||||
App::setLocale($locale);
|
||||
return trans('messages');
|
||||
},
|
||||
]);
|
||||
// App::setLocale(Session::get('locale', config('app.locale')));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user