Probléme setteur image

Par Zekura, il y a 8 ans


Bonjour,

Voila je rencontre un petit problème avec mon code.

Ce que je fais

Je cherche à ajouter dans un formulaire une image pour un manga déja crée (donc un update)

class Mangas extends Model { public function getLogoMangaAttribute($logo_manga){ if($logo_manga){ return "/img/mangas/{$this->id}.jpg"; }else{ return "/img/mangas/0.jpg"; } } public function setLogoMangaAttribute($logo_manga){ if(is_object($logo_manga) && $logo_manga->isValid()){ ImageManagerStatic::make($logo_manga)->fit(300,450)->save(public_path()."/img/mangas/{$this->id}.jpg"); $this->attributes['logo_manga'] = true; } } class MangasController extends Controller { public function update($id, MangasRequest $request) { $mangas = Mangas::findOrFail($id); $mangas->update($request->only('title_Manga_Fr','start_Date_Manga','end_Date_Manga','description_Manga_Fr','country_Manga','type_Manga','logo_Manga','slug_Manga')); return redirect(action('MangasController@index'))->with('success', 'Le manga a bien été modifié'); }

Ce que j'obtiens

Le getteur marche sans probléme, par contre impossible de rajouter l'image. Je pense que mon probléme vient du setteur mais je vois pas ou est le probléme.

3 réponses

Amilti, il y a 8 ans

Hello,
c'est un peut compliqué de t'aider comme ça tu as vérifié si tu rentre dans ton setteur avec un petit dd($logo_manga) ?

Ensuite le :

if(is_object($logo_manga) && $logo_manga->isValid()){

tu devrais plutôt mêttre la verification au niveau de ton MangaRequest .

https://laravel.com/docs/5.5/validation#rule-file

Je peux pas t'aider plus que ça c'est un peut trop vague comme problème ^^

Zekura, il y a 8 ans

Justement j'ai essayé dd($logo_manga) et apparemment j'entre pas dans le setteur. Et j'utilise Lavarel 5.0

Zekura, il y a 8 ans

J'ai trouvé, j'ai tout simplement oublié de rendre l'attribut fillable -,- je suis bête