make translatable textual elements for Gamme and Product Models
route binding on translated slugs
This commit is contained in:
parent
4a75a9f388
commit
c5f57519e5
8 changed files with 51 additions and 11 deletions
|
|
@ -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'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@
|
|||
@foreach ($gammes as $gamme)
|
||||
<div class="gamme-card align-center">
|
||||
<img src="{{ asset($gamme->picture) }}" alt="{{ $gamme->alt_text_picture}}">
|
||||
<a href="{{ route('gammes.show', ['gamme' => $gamme->slug]) }}"></a>
|
||||
<a href="{{ route('gammes.show', ['gammeSlug' => $gamme->slug]) }}"></a>
|
||||
<span class="overlay" style="background-color: {{ $gamme->rgbaColor}};">
|
||||
<span>{{ $gamme->title}}</span>
|
||||
</span>
|
||||
|
|
@ -56,4 +56,4 @@
|
|||
</div>
|
||||
</section>
|
||||
|
||||
@endsection
|
||||
@endsection
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
<div class="product-card align-center">
|
||||
<img src="{{ asset($product->picture) }}" alt="{{ $product->alt_text_picture }}">
|
||||
<h3 class="product-card__title">{{ $product->name }}</h3>
|
||||
<a href="{{ route('product.show', ['gamme' => $product->gamme->slug , 'product' => $product->slug]) }}"></a>
|
||||
<a href="{{ route('product.show', ['gammeSlug' => $product->gamme->slug , 'productSlug' => $product->slug]) }}"></a>
|
||||
<span class="overlay" style="background-color: {{ $gamme->rgbaColor}};">
|
||||
<span>Découvrir</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
<div class="wrapper">
|
||||
<div class="header-title align-center p-rel">
|
||||
<div class="breadcrumb is-flex">
|
||||
<a href="{{ route('gammes.index') }}" class="link">Gammes</a> - <a href="{{ route('gammes.show', ['gamme' => $gamme->slug]) }}" class="link">Produits de la gamme</a>
|
||||
<a href="{{ route('gammes.index') }}" class="link">Gammes</a> - <a href="{{ route('gammes.show', ['gammeSlug' => $gamme->slug]) }}" class="link">Produits de la gamme</a>
|
||||
</div>
|
||||
|
||||
<h1 class="animate__animated fadeInUp animate__slow"><i class="mascotte"></i>{{ $product->name}}</h1>
|
||||
|
|
@ -78,4 +78,4 @@
|
|||
</div>
|
||||
</section>
|
||||
|
||||
@endsection
|
||||
@endsection
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue