translatable Picto Model
This commit is contained in:
parent
513db683fb
commit
0839d40242
8 changed files with 39 additions and 16 deletions
|
|
@ -42,6 +42,9 @@ class PictosController extends Controller
|
|||
public function store(StorePictoRequest $request)
|
||||
{
|
||||
$picto = new Picto($request->validated());
|
||||
if (is_a($request->picture,"SplFileInfo")) {
|
||||
$picto->picture = Utils::storeImage($request->picture, $picto->getTable());
|
||||
}
|
||||
$picto->page = Page::marqueBloc2();
|
||||
|
||||
if (!$picto->saveOrFail()) {
|
||||
|
|
@ -72,6 +75,9 @@ class PictosController extends Controller
|
|||
public function update(Picto $picto, StorePictoRequest $request)
|
||||
{
|
||||
$picto->fill($request->validated());
|
||||
if (is_a($request->picture,"SplFileInfo")) {
|
||||
$picto->picture = Utils::storeImage($request->picture, $picto->getTable());
|
||||
}
|
||||
|
||||
if (!$picto->saveOrFail()) {
|
||||
return redirect()->route('bo.pictos.edit', $picto->id)
|
||||
|
|
@ -91,9 +97,9 @@ class PictosController extends Controller
|
|||
public function destroy(Picto $picto)
|
||||
{
|
||||
if (!$picto->delete()) {
|
||||
return redirect()->route('bo.pictos.index')->with('error', trans('La suppression a échoué'));
|
||||
return redirect()->route('bo.pictos.content', $picto->page)->with('error', trans('La suppression a échoué'));
|
||||
}
|
||||
|
||||
return redirect()->route('bo.pictos.index')->with('success', trans('Suppression faite avec succès'));
|
||||
return redirect()->route('bo.pictos.content', $picto->page)->with('success', trans('Suppression faite avec succès'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,15 +4,15 @@ namespace App\Models;
|
|||
|
||||
use App\Enums\Page;
|
||||
use App\Lib\Utils;
|
||||
use App\Traits\CastsEnumsHasTranslations;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Kwaadpepper\Enum\Traits\CastsEnums;
|
||||
|
||||
class Picto extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use CastsEnums;
|
||||
use CastsEnumsHasTranslations;
|
||||
|
||||
public $enumCasts = [
|
||||
'page' => Page::class
|
||||
|
|
@ -24,16 +24,22 @@ class Picto extends Model
|
|||
'text',
|
||||
];
|
||||
|
||||
public $translatable = [
|
||||
'picture',
|
||||
'alt_text_picture',
|
||||
'text',
|
||||
];
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
static::creating(function (Picto $picto) {
|
||||
if ($picto->picture) {
|
||||
if (is_a($picto->picture,"SplFileInfo")) {
|
||||
$picto->picture = Utils::storeImage($picto->picture, $picto->getTable());
|
||||
}
|
||||
});
|
||||
|
||||
static::updating(function (Picto $picto) {
|
||||
if ($picto->picture) {
|
||||
if (is_a($picto->picture,"SplFileInfo")) {
|
||||
$picto->picture = Utils::storeImage($picto->picture, $picto->getTable());
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Lib\Utils;
|
||||
use App\Models\Picto;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use SplFileInfo;
|
||||
|
||||
|
|
@ -22,8 +24,12 @@ class PictoFactory extends Factory
|
|||
*/
|
||||
public function definition()
|
||||
{
|
||||
$upload = new SplFileInfo(resource_path('assets/images/qualite.png'));
|
||||
$picto = new Picto();
|
||||
$imgpath = Utils::storeImage($upload, $picto->getTable());
|
||||
|
||||
return [
|
||||
'picture' => new SplFileInfo(resource_path('assets/images/qualite.png')),
|
||||
'picture' => $imgpath,
|
||||
'alt_text_picture' => $this->faker->sentence(10),
|
||||
'text' => $this->faker->text(10),
|
||||
];
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace Database\Seeders;
|
||||
|
||||
use App\Enums\Page;
|
||||
use App\Lib\Utils;
|
||||
use App\Models\Picto;
|
||||
use Illuminate\Database\Seeder;
|
||||
use SplFileInfo;
|
||||
|
|
@ -21,11 +22,15 @@ class PictosSeeder extends Seeder
|
|||
Page::foodBloc2()
|
||||
];
|
||||
|
||||
$upload = new SplFileInfo(resource_path('assets/images/qualite.png'));
|
||||
$picto = new Picto();
|
||||
$imgpath = Utils::storeImage($upload, $picto->getTable());
|
||||
|
||||
foreach ($tabEncarts as $key => $value) {
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$picto = new Picto();
|
||||
$picto->page = $value;
|
||||
$picto->picture = new SplFileInfo(resource_path('assets/images/qualite.png'));
|
||||
$picto->picture = $imgpath;
|
||||
$picto->alt_text_picture = 'lorem ipsum set doloris at em gorbicus';
|
||||
$picto->text = 'lorem ipsum set doloris';
|
||||
$picto->save();
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
@csrf
|
||||
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||
<h1 class="h2">
|
||||
<a href="{{route('bo.home')}}" class="h2 text-decoration-none"> < </a>
|
||||
<a href="{{route('bo.pictos.content', Page::marqueBloc2())}}" class="h2 text-decoration-none"> < </a>
|
||||
{{ __('Pictogrammes') }} <small class="text-muted">{{ __('Création') }}</small></h1>
|
||||
<div class="btn-toolbar mb-2 mb-md-0">
|
||||
<button type="submit" class="btn btn-sm btn-primary">{{ __('Enregistrer') }}</a>
|
||||
|
|
@ -64,4 +64,4 @@
|
|||
console.error(error);
|
||||
});
|
||||
</script>
|
||||
@endsection
|
||||
@endsection
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
@csrf
|
||||
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
||||
<h1 class="h2">
|
||||
<a href="{{route('bo.home')}}" class="h2 text-decoration-none"> < </a>
|
||||
<a href="{{route('bo.pictos.content', $picto->page)}}" class="h2 text-decoration-none"> < </a>
|
||||
{{ __('Pictogramme') }} <small class="text-muted">{{ __('Edition') }}</small></h1>
|
||||
<div class="btn-toolbar mb-2 mb-md-0">
|
||||
<button type="submit" class="btn btn-sm btn-primary">{{ __('Enregistrer') }}</a>
|
||||
|
|
|
|||
|
|
@ -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 ($picto->picture !== null)
|
||||
@if (!empty($picto->picture))
|
||||
<br />
|
||||
<br />
|
||||
<img src="{{$picto->picture}}" alt="{{$picto->text}}" style="max-height: 100px;">
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@
|
|||
<tbody>
|
||||
@foreach ($pictos as $picto)
|
||||
<tr>
|
||||
@if ($picto->picture !== null)
|
||||
<th class="white-png">
|
||||
<img src="{{$picto->picture}}" alt="{{$picto->text}}" style="max-height: 50px;">
|
||||
@if (!empty($picto->picture))
|
||||
<img src="{{$picto->picture}}" alt="{{$picto->text}}" style="max-height: 50px;">
|
||||
@endif
|
||||
</th>
|
||||
@endif
|
||||
<td>{{$picto->picture}}</td>
|
||||
|
||||
<td>{{$picto->text}}</td>
|
||||
|
|
@ -41,4 +41,4 @@
|
|||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
@endsection
|
||||
@endsection
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue