mercredi 25 septembre 2019

Request Validation using Observers

With an observer, I add additional content to the model / database. This works without problems!!

Now I would like to validate the incoming request, but unfortunately I do not know how to insert a validation or rules in the observer.

class Customer
{
    /**
     * @var array
     */
    protected $rules = [
        'firstname' => 'numeric',
        'name1' => 'string',
        //'client_number' => 'required|string|unique:customers',
    ];

    /**
     * Listen to the updated event.
     *
     * @param Model $customer
     * @return void
     */
    public function saving(Model $customer)
    {    
        if (request('firstname'))
        {
            if (request('firstname') != null)
            {
                $customer->firstname = request('firstname');
            }
            else
            {
                $customer->firstname = NULL;
            }            
        }

        $customer->client_number = '123456789';
    }
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire