mercredi 24 mars 2021

Serialization of 'class@anonymous' is not allowed in Laravel

I am trying to Merge a common column to form requests but is giving me this error

Serialization of 'class@anonymous' is not allowed

here is my code controller

$response = $this->dispatch(new CreateSupplier($request->all()));

code for CreateSupplier Class

class CreateSupplier extends Job

{

protected $vendor_name;

protected $request;

/**
 * Create a new job instance.
 *
 * @return void
 */
public function __construct($request)
{
    $this->request = $this->getRequestInstance($request);
}

/**
 * Execute the job.
 *
 * @return void
 */
public function handle()
{
    \DB::transaction(function () {
        $this->vendor_name = Vendor::create($this->request);
    });

    return $this->vendor_name;
}

}

here is my Abstract Job Class

abstract class Job implements ShouldQueue { use InteractsWithQueue, Jobs, Queueable, Relationships, SerializesModels;

public function getRequestInstance($request)
{
    if (!is_array($request)) {
        return $request;
    }

    $class = new class() extends FormRequest {
    };

    return $class->merge($request);
}

}

and finally my FormRequest Abstract Class

abstract class FormRequest extends BaseFormRequest
{
    /**
     * Prepare the data for validation.
     *
     * @return void
     */
    protected function prepareForValidation()
    {
        $this->merge([
            'company_id' => session('company_id'),
        ]);
    }

    /**
     * Determine if the given offset exists.
     *
     * @param  string  $offset
     * @return bool
     */
    public function offsetExists($offset)
    {
        return Arr::has(
            $this->route() ? $this->all() + $this->route()->parameters() : $this->all(),
            $offset
        );
    }
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire