diff --git a/app/Http/Controllers/Bo/PictoBrandsController.php b/app/Http/Controllers/Bo/PictoBrandsController.php index 1f1b236..66d7795 100644 --- a/app/Http/Controllers/Bo/PictoBrandsController.php +++ b/app/Http/Controllers/Bo/PictoBrandsController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Bo; use App\Http\Controllers\Controller; use App\Http\Requests\StorePictoBrandRequest; use App\Http\Requests\UpdatePictoBrandRequest; +use App\Lib\Utils; use App\Models\PictoBrand; class PictoBrandsController extends Controller @@ -42,6 +43,9 @@ class PictoBrandsController extends Controller public function store(StorePictoBrandRequest $request) { $pictobrand = new PictoBrand($request->validated()); + if (is_a($request->picture,"SplFileInfo")) { + $pictobrand->picture = Utils::storeImage($request->picture, $pictobrand->getTable()); + } if (!$pictobrand->saveOrFail()) { return redirect()->route('bo.pictobrands.edit', $pictobrand->id)->with('error', 'Le pictogramme n\'a pas été crée'); @@ -71,6 +75,9 @@ class PictoBrandsController extends Controller public function update(PictoBrand $pictobrand, StorePictoBrandRequest $request) { $pictobrand->fill($request->validated()); + if (is_a($request->picture,"SplFileInfo")) { + $pictobrand->picture = Utils::storeImage($request->picture, $pictobrand->getTable()); + } if (!$pictobrand->saveOrFail()) { return redirect()->route('bo.pictobrands.edit', $pictobrand->id) diff --git a/app/Models/PictoBrand.php b/app/Models/PictoBrand.php index 7b95261..f5232e7 100644 --- a/app/Models/PictoBrand.php +++ b/app/Models/PictoBrand.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 PictoBrand extends Model { use HasFactory; + use HasTranslations; protected $fillable = [ 'title', @@ -18,16 +20,23 @@ class PictoBrand extends Model 'text', ]; + public $translatable = [ + 'title', + 'picture', + 'alt_text_picture', + 'text', + ]; + protected static function boot() { static::creating(function (PictoBrand $pictoBrand) { - if ($pictoBrand->picture) { + if (is_a($pictoBrand->picture,"SplFileInfo")) { $pictoBrand->picture = Utils::storeImage($pictoBrand->picture, $pictoBrand->getTable()); } }); static::updating(function (PictoBrand $pictoBrand) { - if ($pictoBrand->picture) { + if (is_a($pictoBrand->picture,"SplFileInfo")) { $pictoBrand->picture = Utils::storeImage($pictoBrand->picture, $pictoBrand->getTable()); } }); diff --git a/database/factories/PictoBrandFactory.php b/database/factories/PictoBrandFactory.php index 0cd203b..e1634a3 100644 --- a/database/factories/PictoBrandFactory.php +++ b/database/factories/PictoBrandFactory.php @@ -2,6 +2,7 @@ namespace Database\Factories; +use App\Lib\Utils; use App\Models\PictoBrand; use Illuminate\Database\Eloquent\Factories\Factory; use SplFileInfo; @@ -23,9 +24,14 @@ class PictoBrandFactory extends Factory */ public function definition() { + + $upload = new SplFileInfo(resource_path('assets/images/site-production.jpg')); + $encart = new PictoBrand(); + $imgpath = Utils::storeImage($upload, $encart->getTable()); + return [ 'title' => $this->faker->randomNumber(3, false), - 'picture' => new SplFileInfo(resource_path('assets/images/site-production.jpg')), + 'picture' => $imgpath, 'alt_text_picture' => $this->faker->sentence(10), 'text' => $this->faker->text(20), ]; diff --git a/resources/views/back/pictobrands/form-inputs.blade.php b/resources/views/back/pictobrands/form-inputs.blade.php index 3e1a10a..1a469a1 100644 --- a/resources/views/back/pictobrands/form-inputs.blade.php +++ b/resources/views/back/pictobrands/form-inputs.blade.php @@ -3,7 +3,7 @@