Hello
My projet is under laravel 6.2 and in use craftable 5.0
############################# my model
`<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Brackets\Media\HasMedia\AutoProcessMediaTrait;
use Brackets\Media\HasMedia\HasMediaCollectionsTrait;
use Brackets\Media\HasMedia\HasMediaThumbsTrait;
use Brackets\Media\HasMedia\ProcessMediaTrait;
use Spatie\MediaLibrary\HasMedia\HasMedia;
use Spatie\MediaLibrary\Models\Media;
class Realisation extends Model implements HasMedia
{
use ProcessMediaTrait;
use AutoProcessMediaTrait;
use HasMediaCollectionsTrait;
use HasMediaThumbsTrait;
protected $fillable = [
'titre',
'maitre_ouvrage',
'maitre_oeuvre',
'montant',
'annee',
'projet_titre',
'projet_description',
'debut_travaux',
'duree_tce',
'effectif_moyen',
'effectif_max',
'chiffre_description',
'enabled',
];
protected $dates = [
'created_at',
'updated_at',
];
protected $appends = ['resource_url'];
public function registerMediaCollections()
{
$this->addMediaCollection('gallery')
->accepts('image/*')
->maxNumberOfFiles(4);
}
public function registerMediaConversions(Media $media = null)
{
$this->autoRegisterThumb200();
}
/* ************************ ACCESSOR ************************* */
public function getResourceUrlAttribute()
{
return url('/admin/realisations/'.$this->getKey());
}
}`
################## Form.js
`import AppForm from '../app-components/Form/AppForm';
Do you submit the save button on the form? Media is attached to the eloquent model not after upload but after submitting the form (saving the eloquent model).
Hello My projet is under laravel 6.2 and in use craftable 5.0
############################# my model `<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model; use Brackets\Media\HasMedia\AutoProcessMediaTrait; use Brackets\Media\HasMedia\HasMediaCollectionsTrait; use Brackets\Media\HasMedia\HasMediaThumbsTrait; use Brackets\Media\HasMedia\ProcessMediaTrait; use Spatie\MediaLibrary\HasMedia\HasMedia; use Spatie\MediaLibrary\Models\Media;
class Realisation extends Model implements HasMedia { use ProcessMediaTrait; use AutoProcessMediaTrait; use HasMediaCollectionsTrait; use HasMediaThumbsTrait;
}`
################## Form.js `import AppForm from '../app-components/Form/AppForm';
Vue.component('realisation-form', { mixins: [AppForm], data: function() { return { form: { titre: '' , maitre_ouvrage: '' , maitre_oeuvre: '' , montant: '' , annee: '' , projet_titre: '' , projet_description: '' , debut_travaux: '' , duree_tce: '' , effectif_moyen: '' , effectif_max: '' , chiffre_description: '' , enabled: false ,
}); `
############### the edit blade file `
But no record run in media database .... i don't know why ....
Do you submit the save button on the form? Media is attached to the eloquent model not after upload but after submitting the form (saving the eloquent model).
Yes i try it but always no record in the database
`
But when we look at the source code after uploading a photo, there is no input hidden with the name of the loaded image to send to the model ...
i don't understand ....