make Advice Model translatable
This commit is contained in:
parent
cc5456213c
commit
ee09d5de31
6 changed files with 49 additions and 19 deletions
|
|
@ -4,6 +4,7 @@ namespace App\Http\Controllers\Bo;
|
|||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\UpdateAdviceRequest;
|
||||
use App\Lib\Utils;
|
||||
use App\Models\Advice;
|
||||
|
||||
class AdviceController extends Controller
|
||||
|
|
@ -30,6 +31,15 @@ class AdviceController extends Controller
|
|||
public function update(Advice $advice, UpdateAdviceRequest $request)
|
||||
{
|
||||
$advice->fill($request->validated());
|
||||
if (is_a($request->picture1,"SplFileInfo")) {
|
||||
$advice->picture1 = Utils::storeImage($request->picture1, $advice->getTable());
|
||||
}
|
||||
if (is_a($request->picture2,"SplFileInfo")) {
|
||||
$advice->picture2 = Utils::storeImage($request->picture2, $advice->getTable());
|
||||
}
|
||||
if (is_a($request->picture3,"SplFileInfo")) {
|
||||
$advice->picture3 = Utils::storeImage($request->picture3, $advice->getTable());
|
||||
}
|
||||
|
||||
if (!$advice->saveOrFail()) {
|
||||
return redirect()->route('bo.advice.edit', $advice->id)
|
||||
|
|
|
|||
|
|
@ -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 Advice extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasTranslations;
|
||||
|
||||
protected $fillable = [
|
||||
'title1',
|
||||
|
|
@ -24,28 +26,41 @@ class Advice extends Model
|
|||
'text2',
|
||||
];
|
||||
|
||||
public $translatable = [
|
||||
'title1',
|
||||
'title2',
|
||||
'picture1',
|
||||
'alt_text_picture1',
|
||||
'picture2',
|
||||
'alt_text_picture2',
|
||||
'picture3',
|
||||
'alt_text_picture3',
|
||||
'text1',
|
||||
'text2',
|
||||
];
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
static::creating(function (Advice $advice) {
|
||||
if ($advice->picture1) {
|
||||
if (is_a($advice->picture1,"SplFileInfo")) {
|
||||
$advice->picture1 = Utils::storeImage($advice->picture1, $advice->getTable());
|
||||
}
|
||||
if ($advice->picture2) {
|
||||
if (is_a($advice->picture2,"SplFileInfo")) {
|
||||
$advice->picture2 = Utils::storeImage($advice->picture2, $advice->getTable());
|
||||
}
|
||||
if ($advice->picture3) {
|
||||
if (is_a($advice->picture3,"SplFileInfo")) {
|
||||
$advice->picture3 = Utils::storeImage($advice->picture3, $advice->getTable());
|
||||
}
|
||||
});
|
||||
|
||||
static::updating(function (Advice $advice) {
|
||||
if ($advice->picture1) {
|
||||
if (is_a($advice->picture1,"SplFileInfo")) {
|
||||
$advice->picture1 = Utils::storeImage($advice->picture1, $advice->getTable());
|
||||
}
|
||||
if ($advice->picture2) {
|
||||
if (is_a($advice->picture2,"SplFileInfo")) {
|
||||
$advice->picture2 = Utils::storeImage($advice->picture2, $advice->getTable());
|
||||
}
|
||||
if ($advice->picture3) {
|
||||
if (is_a($advice->picture3,"SplFileInfo")) {
|
||||
$advice->picture3 = Utils::storeImage($advice->picture3, $advice->getTable());
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ class Gamme extends Model
|
|||
'alt_text_banner',
|
||||
];
|
||||
|
||||
//textual elements only
|
||||
public $translatable = [
|
||||
'title',
|
||||
'slug',
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Lib\Utils;
|
||||
use App\Models\Advice;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use SplFileInfo;
|
||||
|
|
@ -23,14 +24,19 @@ class AdviceFactory extends Factory
|
|||
*/
|
||||
public function definition()
|
||||
{
|
||||
|
||||
$upload = new SplFileInfo(resource_path('assets/images/repas.jpg'));
|
||||
$advice = new Advice();
|
||||
$imgpath = Utils::storeImage($upload, $advice->getTable());
|
||||
|
||||
return [
|
||||
'title1' => $this->faker->text(40),
|
||||
'title2' => $this->faker->text(40),
|
||||
'picture1' => new SplFileInfo(resource_path('assets/images/repas.jpg')),
|
||||
'picture1' => $imgpath,
|
||||
'alt_text_picture1' => $this->faker->sentence(10),
|
||||
'picture2' => new SplFileInfo(resource_path('assets/images/repas.jpg')),
|
||||
'picture2' => $imgpath,
|
||||
'alt_text_picture2' => $this->faker->sentence(10),
|
||||
'picture3' => new SplFileInfo(resource_path('assets/images/repas.jpg')),
|
||||
'picture3' => $imgpath,
|
||||
'alt_text_picture3' => $this->faker->sentence(10),
|
||||
'text1' => $this->faker->paragraph(10),
|
||||
'text2' => $this->faker->paragraph(10),
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
<div class="form-group">
|
||||
<label for="picture1">{{ __('Image') }} *<small class="text-muted">- JPEG/PNG, 2Mo max. Dimensions {{ Config::get('bo.advice_image_maxwidth') }} px par {{ Config::get('bo.advice_image_maxheight') }} px</small></label><br/>
|
||||
<input type="file" id="picture1" name="picture1" accept="image/png, image/jpeg">
|
||||
@if ($advice->picture1 !== null)
|
||||
@if (!empty($advice->picture1))
|
||||
<br />
|
||||
<br />
|
||||
<img src="{{$advice->picture1}}" alt="{{$advice->title1}}" style="max-height: 100px;">
|
||||
|
|
@ -43,7 +43,7 @@
|
|||
<div class="form-group me-5">
|
||||
<label for="picture2">{{ __('Image') }} *<small class="text-muted">- JPEG/PNG, 1Mo max. Dimensions {{ Config::get('bo.advice_image_maxwidth') }} px par {{ Config::get('bo.advice_image_maxheight') }} px</small></label><br/>
|
||||
<input type="file" id="picture2" name="picture2" accept="image/png, image/jpeg">
|
||||
@if ($advice->picture2 !== null)
|
||||
@if (!empty($advice->picture2))
|
||||
<br />
|
||||
<br />
|
||||
<img src="{{$advice->picture2}}" alt="{{$advice->title2}}" style="max-height: 100px;">
|
||||
|
|
@ -58,13 +58,13 @@
|
|||
<div class="form-group">
|
||||
<label for="picture3">{{ __('Image') }} *<small class="text-muted">- JPEG/PNG, 1Mo max. Dimensions {{ Config::get('bo.advice_image_maxwidth') }} px par {{ Config::get('bo.advice_image_maxheight') }} px</small></label><br/>
|
||||
<input type="file" id="picture3" name="picture3" accept="image/png, image/jpeg">
|
||||
@if ($advice->picture3 !== null)
|
||||
@if (!empty($advice->picture3))
|
||||
<br />
|
||||
<br />
|
||||
<img src="{{$advice->picture3}}" alt="{{$advice->title3}}" style="max-height: 100px;">
|
||||
@endif
|
||||
@include('back.modules.input-error', ['inputName'=>'picture3'])
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="name">{{ __('Text alternatif de l\'image') }} *</label>
|
||||
<input type="text" id="alt_text_picture3" name="alt_text_picture3" class="form-control" placeholder="{{ __('Texte alternatif de l\'image') }} *" value="{{ old('alt_text_picture3', $advice->alt_text_picture3 ?? '') }}" required>
|
||||
|
|
|
|||
|
|
@ -66,17 +66,17 @@
|
|||
<section class="container">
|
||||
@if($products_food->count() > 0)
|
||||
<div class="wrapper">
|
||||
<h2 class="sectiontitle align-center animate__animated fadeInUp animate__slow blue-line">Les produits</h2>
|
||||
<p class="align-center">Nous travaillons toujours pour améliorer nos recettes et proposer des produits de meilleur qualité</p>
|
||||
<h2 class="sectiontitle align-center animate__animated fadeInUp animate__slow blue-line">{{ __('Les produits') }}</h2>
|
||||
<p class="align-center">{{ __('Nous travaillons toujours pour améliorer nos recettes et proposer des produits de meilleur qualité') }}</p>
|
||||
|
||||
<div class="blue-products is-flex wrap space-between desk-mt50">
|
||||
@foreach ($products_food as $product)
|
||||
<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">
|
||||
<span>Découvrir</span>
|
||||
<span>{{ __('Découvrir') }}</span>
|
||||
</span>
|
||||
</div>
|
||||
@endforeach
|
||||
|
|
@ -87,4 +87,4 @@
|
|||
|
||||
</div>
|
||||
|
||||
@endsection
|
||||
@endsection
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue