BRACKETS-by-TRIAD / craftable

Admin panel builder / CRUD generator for Laravel.
https://getcraftable.com
MIT License
981 stars 192 forks source link

No record on database table media #166

Closed mediaboost closed 4 years ago

mediaboost commented 4 years ago

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';

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 ,

        },
        mediaCollections: ['gallery']
    }
}

}); `

############### the edit blade file `

{{ trans('admin.realisation.actions.edit', ['name' => $realisation->id]) }}
@include('admin.realisation.components.form-elements')
@include('brackets/admin-ui::admin.includes.media-uploader', [ 'mediaCollection' => $realisation->getMediaCollection('gallery'), 'media' => $realisation->getThumbs200ForCollection('gallery'), 'label' => 'Gallery of photos' ])
</div>`

But no record run in media database .... i don't know why ....

palypster commented 4 years ago

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).

mediaboost commented 4 years ago

Yes i try it but always no record in the database

`

{{ trans('admin.realisation.actions.edit', ['name' => $realisation->id]) }}
@include('admin.realisation.components.form-elements') @include('brackets/admin-ui::admin.includes.media-uploader', [ 'mediaCollection' => $realisation->getMediaCollection('gallery'), 'label' => 'Gallery of photos' ])
</div>`
mediaboost commented 4 years ago

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 ....