Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Pixelairport's avatar

Change request via trait in model

Hi. I i build an extension to upload images, to use it in different other extensions. I think about using a trait which uses the boot methods to do all upload stuff and then replace the request. This is the problem... how can i replace the request. In my example i have an image called "main_image" and want to do something like that:

trait UploadTrait {

public static function bootUploadTrait()
{
    
    static::updating(function ($model) {

        request()->replace(request()->except('main_image'));
       
    });

Is that possible? Because i still get my error: Column not found: 1054 Unknown column 'main_image' in 'field list'

Hope someone can help me or have another idea.

thx Norman

0 likes
2 replies
jeffreyvanrossum's avatar
Level 9

The error refers to, if I'm not mistaken, to the column main_image not existing on your database table.

Pixelairport's avatar

That is why i want to delete it from request with a trait. But before delete it, I want to upload the image.

Please or to participate in this conversation.