delete picture when a field is deleted

+ fix css bugs
This commit is contained in:
Sebastien Hattry 2022-01-07 17:29:55 +01:00
parent 42af8d3b8d
commit d3b9865717
21 changed files with 274 additions and 71 deletions

View file

@ -7,11 +7,12 @@ use App\Models\Product;
class ProductsController extends Controller
{
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
public function show(Gamme $gamme, Product $product)
{
$product = Product::whereSlug($product->slug)->first();
// var_dump($product);
// exit;
return view('front.product', compact('product', 'gamme'));
}
}

View file

@ -78,36 +78,57 @@ class StoreProductRequest extends FormRequest
'temp' => $this->temp_cook7,
'status' => $this->is_activated7 ? true : false
);
$tabCuisson = json_encode([
'four' => $tabFour,
'friteuse' => $tabFriteuse,
'poele' => $tabPoele,
'cocotte' => $tabCocotte,
'plancha' => $tabPlancha,
'bainmarie' => $tabBainMarie,
'barbecue' => $tabBarbecue,
'microondes' => $tabMicroOndes
]);
// var_dump(public_path() . "\assets\images\sans-label.jpg");
// var_dump(storage_path('app\public'));
// var_dump(pathinfo(storage_path('app\public')));
// exit;
// TODO storage json pictures
$urlPlusProduit = "/assets/images/sans-label.jpg";
if ($this->pictogramme0) {
$urlPlusProduit = "/assets/images/" . $this->pictogramme0->getClientOriginalName();
}
$tabPlusProduit1 = array(
'id' => 0,
'name' => $this->content0,
'url' => '/assets/images/sans-label.jpg',
'url' => $urlPlusProduit,
);
$urlPlusProduit = "/assets/images/sans-label.jpg";
if ($this->pictogramme1) {
$urlPlusProduit = "/assets/images/" . $this->pictogramme1->getClientOriginalName();
}
$tabPlusProduit2 = array(
'id' => 1,
'name' => $this->content1,
'url' => '/assets/images/sans-label.jpg',
'url' => $urlPlusProduit,
);
$urlPlusProduit = "/assets/images/sans-label.jpg";
if ($this->pictogramme2) {
$urlPlusProduit = "/assets/images/" . $this->pictogramme2->getClientOriginalName();
}
$tabPlusProduit3 = array(
'id' => 2,
'name' => $this->content2,
'url' => '/assets/images/sans-label.jpg',
'url' => $urlPlusProduit,
);
$tabPlusProduit = json_encode([$tabPlusProduit1, $tabPlusProduit2, $tabPlusProduit3]);
$this->merge([
'slug' => Str::slug($this->name),
'gamme_id' => $this->gamme_id === '0' ? null : $this->gamme_id,
'pictos' => json_encode([
'four' => $tabFour,
'friteuse' => $tabFriteuse,
'poele' => $tabPoele,
'cocotte' => $tabCocotte,
'plancha' => $tabPlancha,
'bainmarie' => $tabBainMarie,
'barbecue' => $tabBarbecue,
'microondes' => $tabMicroOndes
]),
'plusproduit' => json_encode([$tabPlusProduit1, $tabPlusProduit2, $tabPlusProduit3]),
'pictos' => $tabCuisson,
'plusproduit' => $tabPlusProduit,
'is_published' => $this->is_published ? true : false,
'is_on_top' => $this->is_on_top ? true : false,
'is_food_service' => $this->is_food_service ? true : false,

View file

@ -5,6 +5,7 @@ namespace App\Models;
use App\Lib\Utils;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\File;
class Advice extends Model
{
@ -48,6 +49,33 @@ class Advice extends Model
$advice->picture3 = Utils::storeImage($advice->picture3, $advice->getTable());
}
});
static::deleted(function (Advice $advice) {
if ($advice->picture1) {
$urlPicture = public_path() . $advice->picture1;
if ($urlPicture) {
if (File::exists($urlPicture)) {
File::delete($urlPicture);
}
}
}
if ($advice->picture2) {
$urlPicture = public_path() . $advice->picture2;
if ($urlPicture) {
if (File::exists($urlPicture)) {
File::delete($urlPicture);
}
}
}
if ($advice->picture3) {
$urlPicture = public_path() . $advice->picture3;
if ($urlPicture) {
if (File::exists($urlPicture)) {
File::delete($urlPicture);
}
}
}
});
parent::boot();
}
}

View file

@ -6,6 +6,7 @@ use App\Enums\Page;
use App\Lib\Utils;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\File;
use Kwaadpepper\Enum\Traits\CastsEnums;
class Encart extends Model
@ -38,6 +39,17 @@ class Encart extends Model
$encart->picture = Utils::storeImage($encart->picture, $encart->getTable());
}
});
static::deleted(function (Encart $encart) {
if ($encart->picture) {
$urlPicture = public_path() . $encart->picture;
if ($urlPicture) {
if (File::exists($urlPicture)) {
File::delete($urlPicture);
}
}
}
});
parent::boot();
}
}

View file

@ -5,6 +5,7 @@ namespace App\Models;
use App\Lib\Utils;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\File;
class Gamme extends Model
{
@ -63,6 +64,32 @@ class Gamme extends Model
$gamme->color = Gamme::whereId($gamme->parent_gamme_id)->select(['color'])->first()->color;
}
});
static::deleting(function (Gamme $gamme) {
if ($gamme->childGammes()->exists()) {
Gamme::whereParentGammeId($gamme->id)
->update(['parent_gamme_id' => null]);
}
});
static::deleted(function (Gamme $gamme) {
if ($gamme->picture) {
$urlPicture = public_path() . $gamme->picture;
if ($urlPicture) {
if (File::exists($urlPicture)) {
File::delete($urlPicture);
}
}
}
if ($gamme->banner) {
$urlPicture = public_path() . $gamme->banner;
if ($urlPicture) {
if (File::exists($urlPicture)) {
File::delete($urlPicture);
}
}
}
});
parent::boot();
}

View file

@ -6,6 +6,7 @@ use App\Enums\Page;
use App\Lib\Utils;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\File;
use Kwaadpepper\Enum\Traits\CastsEnums;
class Moment extends Model
@ -21,7 +22,7 @@ class Moment extends Model
'title',
'subtitle',
'text',
'picture'
'picture',
'alt_text_picture',
];
@ -38,6 +39,17 @@ class Moment extends Model
$moment->picture = Utils::storeImage($moment->picture, $moment->getTable());
}
});
static::deleted(function (Moment $moment) {
if ($moment->picture) {
$urlPicture = public_path() . $moment->picture;
if ($urlPicture) {
if (File::exists($urlPicture)) {
File::delete($urlPicture);
}
}
}
});
parent::boot();
}
}

View file

@ -6,6 +6,7 @@ use App\Enums\Page;
use App\Lib\Utils;
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
@ -36,6 +37,17 @@ class Picto extends Model
$picto->picture = Utils::storeImage($picto->picture, $picto->getTable());
}
});
static::deleted(function (Picto $picto) {
if ($picto->picture) {
$urlPicture = public_path() . $picto->picture;
if ($urlPicture) {
if (File::exists($urlPicture)) {
File::delete($urlPicture);
}
}
}
});
parent::boot();
}
}

View file

@ -5,6 +5,7 @@ namespace App\Models;
use App\Lib\Utils;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\File;
class PictoBrand extends Model
{
@ -30,6 +31,17 @@ class PictoBrand extends Model
$pictoBrand->picture = Utils::storeImage($pictoBrand->picture, $pictoBrand->getTable());
}
});
static::deleted(function (PictoBrand $pictoBrand) {
if ($pictoBrand->picture) {
$urlPicture = public_path() . $pictoBrand->picture;
if ($urlPicture) {
if (File::exists($urlPicture)) {
File::delete($urlPicture);
}
}
}
});
parent::boot();
}
}

View file

@ -5,6 +5,7 @@ namespace App\Models;
use App\Lib\Utils;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\File;
class Post extends Model
{
@ -51,6 +52,25 @@ class Post extends Model
$post->picture_news = Utils::storeImage($post->picture_news, $post->getTable());
}
});
static::deleted(function (Post $post) {
if ($post->picture_home) {
$urlPicture = public_path() . $post->picture_home;
if ($urlPicture) {
if (File::exists($urlPicture)) {
File::delete($urlPicture);
}
}
}
if ($post->picture_news) {
$urlPicture = public_path() . $post->picture_news;
if ($urlPicture) {
if (File::exists($urlPicture)) {
File::delete($urlPicture);
}
}
}
});
parent::boot();
}
}

View file

@ -5,6 +5,7 @@ namespace App\Models;
use App\Lib\Utils;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\File;
class Product extends Model
{
@ -46,6 +47,25 @@ class Product extends Model
$product->banner = Utils::storeImage($product->banner, $product->getTable());
}
});
static::deleted(function (Product $product) {
if ($product->picture) {
$urlPicture = public_path() . $product->picture;
if ($urlPicture) {
if (File::exists($urlPicture)) {
File::delete($urlPicture);
}
}
}
if ($product->banner) {
$urlPicture = public_path() . $product->banner;
if ($urlPicture) {
if (File::exists($urlPicture)) {
File::delete($urlPicture);
}
}
}
});
parent::boot();
}

View file

@ -5,6 +5,7 @@ namespace App\Models;
use App\Lib\Utils;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\File;
class Slide extends Model
{
@ -46,6 +47,17 @@ class Slide extends Model
$slide->picture = Utils::storeImage($slide->picture, $slide->getTable());
}
});
static::deleted(function (Slide $slide) {
if ($slide->picture) {
$urlPicture = public_path() . $slide->picture;
if ($urlPicture) {
if (File::exists($urlPicture)) {
File::delete($urlPicture);
}
}
}
});
parent::boot();
}

View file

@ -3,13 +3,11 @@
namespace App\Models;
use App\Enums\Role;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Hash;
use Kwaadpepper\Enum\Traits\CastsEnums;
use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable
{

View file

@ -113,9 +113,9 @@ class ProductFactory extends Factory
]),
'plusproduit' => json_encode([$tabPlusProduit1, $tabPlusProduit2, $tabPlusProduit3]),
'is_published' => true,
'is_on_top' => false,
'is_food_service' => false,
'is_halal' => true,
'is_on_top' => rand(true, false),
'is_food_service' => rand(true, false),
'is_halal' => rand(true, false),
'seo_title' => $this->faker->text(5),
'seo_description' => $this->faker->sentence(20),
];

View file

@ -4179,6 +4179,18 @@ img{
margin-left:25px;
}
.product ul.more li{
width:-webkit-max-content;
width:-moz-max-content;
width:max-content;
}
.product ul.more li p:first-of-type{
font-size:18px;
}
.product ul.more li::before{
top:30px;
}
ul.more{
margin-top:50px;
}
@ -4187,21 +4199,20 @@ ul.more li{
position:relative;
padding-left:25px;
margin-bottom:30px;
width:-webkit-max-content;
width:-moz-max-content;
width:max-content;
width:100%;
}
ul.more li:last-of-type{
margin-bottom:0;
}
ul.more li p:first-of-type{
position:relative;
font-size:26px;
}
ul.more li::before{
content:"";
position:absolute;
left:0;
top:30px;
top:20px;
width:10px;
height:10px;
background-color:#222f5c;
@ -4263,7 +4274,7 @@ ul.infos span{
padding-top:50px;
}
ul.more li::before{
.product ul.more li::before{
top:10px;
}
}
@ -4321,6 +4332,10 @@ ul.infos span{
font-weight:bold;
}
.on-bottom{
z-index:-1;
}
.ttu{
text-transform:uppercase;
}

View file

@ -75,6 +75,16 @@ img {
margin-left: 25px;
}
.product ul.more li {
width: max-content;
p:first-of-type {
font-size: 18px;
}
&::before {
top: 30px;
}
}
ul.more {
margin-top: 50px;
@ -83,19 +93,20 @@ ul.more {
position: relative;
padding-left: 25px;
margin-bottom: 30px;
width: max-content;
width: 100%;
&:last-of-type {
margin-bottom: 0;
}
p:first-of-type {
position: relative;
font-size: 26px;
}
&::before {
content: "";
position: absolute;
left: 0;
top: 30px;
top: 20px;
width: 10px;
height: 10px;
background-color: $color-blue;
@ -159,7 +170,7 @@ ul.infos {
main {
padding-top: 50px;
}
ul.more li::before {
.product ul.more li::before {
top: 10px;
}
}

View file

@ -11,7 +11,9 @@
.bold {
font-weight: bold;
}
.on-bottom {
z-index: -1;
}
.ttu {
text-transform: uppercase;
}

View file

@ -109,7 +109,7 @@ $plusproduit = json_decode($product->plusproduit);
@if ($plus->url !== null)
<br/>
<br/>
<img src="{{$plus->url}}" alt="{{$plus->name}}" style="max-height: 100px;">
<img src="{{$plus->url}}" alt="{{$plus->name}}" id="aleg{{$plus->id}}" name="aleg{{$plus->id}}" style="max-height: 100px;">
@endif
@include('back.modules.input-error', ['inputName'=>'pictogramme{{$plus->id}}'])
</div>

View file

@ -1,7 +1,7 @@
<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' => $gamme->slug , 'product' => $product->slug]) }}"></a>
<a href="{{ route('product.show', ['gamme' => $product->gamme->slug , 'product' => $product->slug]) }}"></a>
<span class="overlay" style="background-color: {{ $gamme->rgbaColor}};">
<span>Découvrir</span>
</span>

View file

@ -41,10 +41,10 @@
</div>
</div>
<div class="is-flex desk-mt180">
<div class="w25 desk-mr10 animate__animated fadeInLeft animate__slow">
<div class="w25 desk-mr10 on-bottom animate__animated fadeInLeft animate__slow">
<img class="advice-img" src="{{ asset($advice_news->picture2) }}" alt="{{ $advice_news->alt_text_picture2 }}">
</div>
<div class="w25 desk-mr18 animate__animated fadeInLeft animate__slow">
<div class="w25 desk-mr18 on-bottom animate__animated fadeInLeft animate__slow">
<img class="advice-img" src="{{ asset($advice_news->picture3) }}" alt="{{ $advice_news->alt_text_picture3 }}">
</div>
<div class="w50 animate__animated fadeInRight animate__slow">

View file

@ -27,7 +27,7 @@
</div>
</section>
<section class="container">
<section class="container product">
<div class="wrapper">
<div class="header-title align-center p-rel">
<div class="breadcrumb is-flex">
@ -39,38 +39,40 @@
<div class="is-flex mt-5">
<div class="w50 align-center">
<img src="{{ asset($product->picture) }}" alt="{{ $product->alt_text_picture }}" class="animate__animated fadeInLeft animate__slow">
<ul class="infos animate__animated fadeInLeft animate__slow">
<li><span><img src="{{ asset('assets/images/four.png') }}" alt=""></span>15-20 min 180°C</li>
<li><span><img src=" {{ asset('assets/images/friteuse.png') }}" alt=""></span>15-20 min 180°C</li>
<li><span><img src="{{ asset('assets/images/poele.png') }}" alt=""></span>10 min à la poêle</li>
</ul>
@php
$pictos = json_decode($product->pictos);
@endphp
@if (isset($pictos))
<ul class="infos animate__animated fadeInLeft animate__slow">
@foreach ($pictos as $picto)
@if ($picto->status)
<li><span><img src="{{$picto->url}}" alt="{{$picto->name}}"></span>{{ $picto->time }}<br/>{{ $picto->temp }}</li>
@endif
@endforeach
</ul>
@endif
</div>
<div class="w50 mt-5">
<p class="animate__animated fadeInRight animate__slow align-justify">{!! clean(nl2br($product->description)) !!}</p>
<span class="best p-rel animate__animated fadeInRight animate__slow">
<span>les +</span>
<span>Produit</span>
</span>
<ul class="more is-flex flex-col vertical-center">
<li class="is-flex animate__animated fadeInRight animate__slow">
<p>Lorem ipsum dolor sit amet consectetur</p>
<span class="label">
<img src="{{ asset('assets/images/sans-label.jpg') }}" alt="photo">
</span>
</li>
<li class="is-flex animate__animated fadeInRight animate__slow">
<p>Lorem ipsum dolor sit amet consectetur</p>
<span class="label">
<img src="{{ asset('assets/images/sans-label.jpg') }}" alt="photo">
</span>
</li>
<li class="is-flex animate__animated fadeInRight animate__slow">
<p>Lorem ipsum dolor sit amet consectetur</p>
<span class="label">
<img src="{{ asset('assets/images/sans-label.jpg') }}" alt="photo">
</span>
</li>
</ul>
@php
$plusproduit = json_decode($product->plusproduit);
@endphp
@if (isset($plusproduit))
<span class="best p-rel animate__animated fadeInRight animate__slow">
<span>les +</span>
<span>Produit</span>
</span>
<ul class="more is-flex flex-col">
@foreach ($plusproduit as $plus)
<li class="is-flex animate__animated fadeInRight animate__slow">
<p>{{ $plus->name }}</p>
<span class="label">
<img src="{{$plus->url}}" alt="{{$plus->name}}">
</span>
</li>
@endforeach
</ul>
@endif
</div>
</div>
</div>

View file

@ -97,7 +97,6 @@ Route::prefix('bo')
)->name('slides.change-order');
Route::get('/pictos/{page}', [PictosController::class, 'index'])->name('pictos.content');
Route::get('/texts/{page}', [TextsController::class, 'index'])->name('texts.content');
// Route::get('/posts', [PostsController::class, 'index'])->name('posts');
}
);
}
@ -108,13 +107,12 @@ Route::middleware(['init-vars'])
function () {
Route::get('/', [ControllersHomeController::class, 'index'])->name('home');
Route::view('/notre-marque', 'front.a-propos')->name('wasup');
// Route::view('/le-produit', 'front.product')->name('product');
// Route::view('/les-produits', 'front.products-list')->name('products');
// Route::view('/les-gammes', 'front.gammes')->name('gammes');
Route::get('/nos-gammes', [ControllersGammesController::class, 'index'])->name('gammes.index');
Route::get('/gamme/{gamme:slug}', [ControllersGammesController::class, 'show'])->name('gammes.show');
Route::get('/produit/{gamme:slug}/{product:slug}', [ControllersProductsController::class, 'show'])->name('product.show');
// Route::view('/les-categories', 'front.categorie')->name('categories');
Route::get(
'/produit/{gamme:slug}/{product:slug}',
[ControllersProductsController::class, 'show']
)->name('product.show');
Route::view('/nos-actualites', 'front.news')->name('news');
Route::view('/food-service', 'front.food-service')->name('food');
Route::view('/mentions-legales', 'front.legals')->name('cgu');