diff --git a/app/Http/Controllers/ProductsController.php b/app/Http/Controllers/ProductsController.php index 8126187..2e32861 100644 --- a/app/Http/Controllers/ProductsController.php +++ b/app/Http/Controllers/ProductsController.php @@ -10,9 +10,8 @@ class ProductsController extends Controller // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed public function show(Gamme $gamme, Product $product) { - $product = Product::whereSlug($product->slug)->first(); - // var_dump($product); - // exit; + //$product = Product::whereSlug($product->slug)->first(); + //dd($product); return view('front.product', compact('product', 'gamme')); } } diff --git a/app/Models/Gamme.php b/app/Models/Gamme.php index 7c1afc0..208c6d1 100644 --- a/app/Models/Gamme.php +++ b/app/Models/Gamme.php @@ -6,10 +6,12 @@ use App\Lib\Utils; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\File; +use Spatie\Translatable\HasTranslations; class Gamme extends Model { use HasFactory; + use HasTranslations; protected $fillable = [ 'parent_gamme_id', @@ -23,6 +25,16 @@ class Gamme extends Model 'alt_text_banner', ]; + //textual elements only + public $translatable = [ + 'title', + 'slug', + 'text', + 'alt_text_picture', + 'alt_text_banner', + ]; + + protected static function boot() { static::creating(function (Gamme $gamme) { diff --git a/app/Models/Product.php b/app/Models/Product.php index 6b60059..c175d11 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -6,10 +6,12 @@ use App\Lib\Utils; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\File; +use Spatie\Translatable\HasTranslations; class Product extends Model { use HasFactory; + use HasTranslations; protected $fillable = [ 'gamme_id', @@ -28,6 +30,19 @@ class Product extends Model 'seo_description', ]; + //textual elements only + //TODO : make + produit ane pictos translatable + public $translatable = [ + 'name', + 'slug', + 'description', + 'pictos', + 'plusproduit', + 'alt_text_picture', + 'seo_title', + 'seo_description', + ]; + protected static function boot() { static::creating(function (Product $product) { diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 3bd3c81..d1e7073 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -2,6 +2,8 @@ namespace App\Providers; +use App\Models\Gamme; +use App\Models\Product; use Illuminate\Cache\RateLimiting\Limit; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Http\Request; @@ -47,6 +49,18 @@ class RouteServiceProvider extends ServiceProvider ->namespace($this->namespace) ->group(base_path('routes/web.php')); }); + + Route::bind('gammeSlug', function($value, $route) { + $gamme = Gamme::where('slug', 'LIKE', '%:"'.$value.'"%')->firstOrFail(); + return $gamme; + }); + + Route::bind('productSlug', function($value, $route) { + $gamme = $route->parameter('gammeSlug'); + $product = Product::where('slug', 'LIKE', '%:"'.$value.'"%')->where('gamme_id', $gamme->id)->firstOrFail(); + return $product; + }); + } /** diff --git a/resources/views/front/gammes/index.blade.php b/resources/views/front/gammes/index.blade.php index f0edc43..818c974 100644 --- a/resources/views/front/gammes/index.blade.php +++ b/resources/views/front/gammes/index.blade.php @@ -45,7 +45,7 @@ @foreach ($gammes as $gamme)
{{ $gamme->alt_text_picture}} - + {{ $gamme->title}} @@ -56,4 +56,4 @@
-@endsection \ No newline at end of file +@endsection diff --git a/resources/views/front/gammes/product.blade.php b/resources/views/front/gammes/product.blade.php index 35b62fa..8a16289 100644 --- a/resources/views/front/gammes/product.blade.php +++ b/resources/views/front/gammes/product.blade.php @@ -1,8 +1,8 @@
{{ $product->alt_text_picture }}

{{ $product->name }}

- + Découvrir -
\ No newline at end of file + diff --git a/resources/views/front/product.blade.php b/resources/views/front/product.blade.php index a79f8ef..dce6379 100644 --- a/resources/views/front/product.blade.php +++ b/resources/views/front/product.blade.php @@ -31,7 +31,7 @@

{{ $product->name}}

@@ -78,4 +78,4 @@
-@endsection \ No newline at end of file +@endsection diff --git a/routes/web.php b/routes/web.php index 2c8b631..9af54f4 100644 --- a/routes/web.php +++ b/routes/web.php @@ -108,9 +108,9 @@ Route::middleware(['init-vars','lang-check']) Route::get('/', [ControllersHomeController::class, 'index'])->name('home'); Route::view('/notre-marque', 'front.a-propos')->name('wasup'); Route::get('/nos-gammes', [ControllersGammesController::class, 'index'])->name('gammes.index'); - Route::get('/gamme/{gamme:slug}', [ControllersGammesController::class, 'show'])->name('gammes.show'); + Route::get('/gamme/{gammeSlug}', [ControllersGammesController::class, 'show'])->name('gammes.show'); Route::get( - '/produit/{gamme:slug}/{product:slug}', + '/produit/{gammeSlug}/{productSlug}', [ControllersProductsController::class, 'show'] )->name('product.show'); Route::view('/nos-actualites', 'front.news')->name('news');