Error when use media single in my module



  • Hi, i'm try to use media for upload single file.
    In my table i have 3 Field : company, website, and banner_url for the image.
    I'm follow the instructions of @armababy in the topic /topic/127/unable-to-upload-save-image
    In the form i can select the image and i see thumbnailed in the form.
    When a press the save button this error appears:
    MassAssignmentException in Model.php line 424:
    _token
    in Model.php line 424
    at Model->fill(array('_token' => 's8bFHQShH9gmlvjwJWPYMos4xOmOhe3648qI6J8W', 'company' => 'test company', 'website_url' => 'www.testcompany.com', 'medias_single' => array('banner_url' => '1'))) in Translatable.php line 276
    Somebody help me please?
    Thanks


  • Global Moderator

    Hi @mjsorribas

    It looks like you don't have $translatedAttributes set on your Entity.
    Can you paste your Entity code where you are posting this form.

    Thanks.



  • Hi, this is my partner entity
    <?php namespace Modules\Partner\Entities;

    use Dimsav\Translatable\Translatable;
    use Illuminate\Database\Eloquent\Model;

    class Partner extends Model
    {
    use Translatable;

    protected $table = 'partner__partners';
    public $translatedAttributes = [];
    protected $fillable = [];
    

    }

    and this is the PartnerTranslation

    <?php namespace Modules\Partner\Entities;

    use Illuminate\Database\Eloquent\Model;

    class PartnerTranslation extends Model
    {
    public $timestamps = false;
    protected $fillable = [];
    protected $table = 'partner__partner_translations';
    }

    I don't touch it , It's created by scaffold.
    May by the problem is i don't have partner__partner_translations migration file.


  • Global Moderator

    Hi @mjsorribas

    You need to fill the $fillable and translatedAttributes arrays with mass assignment fields.
    For example based on your post data i could assume something like this:

    in class Partner

    $translatedAttributes = ['company'];
    $fillable = ['website_url'];
    

    in class PartnerTranslation

    $fillable = ['company'];
    


  • Thanks, that is one of the problems. i resolved with this:
    <?php namespace Modules\Partner\Entities;
    //use Dimsav\Translatable\Translatable;
    use Illuminate\Database\Eloquent\Model;
    class Partner extends Model
    {
    // use Translatable;
    protected $table = 'partner__partners';
    // public $translatedAttributes = [];
    protected $fillable = ['company','website','banner_url','order'];

    And i created inside "media module" another media partial view called "new-file-link-single-urlget.blade" with line 38 changed:
    '<input type="hidden" name="'+ window.mediaZone +'" value="' + filePath + '">' +
    With this i get the mediumThumb file url directly to save without "Events/uploadEvent", only take url from "media".
    Mayby is not the best option but works to save url of the file perfect.


  • Global Moderator

    @mjsorribas

    You don't need to save url of banner. You can retrieve it whenever you retrieve Model instance via files() method provided by MediaTrait.
    I have noticed you do not use MediaTrait for some reason, but you say that you want to save files.


Log in to reply
 

Looks like your connection to AsgardCms was lost, please wait while we try to reconnect.