use translateble on PictoBrands Model
This commit is contained in:
parent
592846b56c
commit
c123f8b529
5 changed files with 29 additions and 7 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
];
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
<div class="form-group mb-4">
|
||||
<label for="picture">{{ __('Image') }} <small class="text-muted">- PNG, 500Ko max. Dimensions maximum {{ Config::get('bo.picto_image_maxwidth') }} px par {{ Config::get('bo.picto_image_maxheight') }} px</small></label></br>
|
||||
<input type="file" id="picture" name="picture" accept="image/png, image/jpeg">
|
||||
@if ($pictobrand->picture !== null)
|
||||
@if (!empty($pictobrand->picture))
|
||||
<br />
|
||||
<br />
|
||||
<img src="{{$pictobrand->picture}}" alt="{{$pictobrand->text}}" style="max-height: 100px;">
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
<label for="name">{{ __('Text alternatif de l\'image') }} *</label>
|
||||
<input type="text" id="alt_text_picture" name="alt_text_picture" class="form-control" placeholder="{{ __('Texte alternatif de l\'image') }} *" value="{{ old('alt_text_picture', $pictobrand->alt_text_picture ?? '') }}" required>
|
||||
@include('back.modules.input-error', ['inputName'=>'alt_text_picture'])
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="title">{{ __('Quantité') }} *</label>
|
||||
<input type="text" id="title" name="title" class="form-control" placeholder="{{ __('Quantité') }} *" value="{{ old('title', $pictobrand->title ?? '') }}" required>
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
@foreach ($pictobrands as $picto)
|
||||
<tr>
|
||||
<th>
|
||||
@if ($picto->picture !== null)
|
||||
@if (!empty($picto->picture))
|
||||
<img src="{{$picto->picture}}" alt="{{$picto->text}}" style="max-height: 50px;">
|
||||
@endif
|
||||
</th>
|
||||
|
|
@ -40,4 +40,4 @@
|
|||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
@endsection
|
||||
@endsection
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue