lundi 28 octobre 2019

How to autogenerate a random, unique, alphanumeric string as serial number of a product in laravel

I would like to have a string which is unique and which can be autogenerated from the controller to the table directly. How am I to handle that In the controller

I would like to have a $serail_number somewhere that will be unique

public function store()
{

    Slaughter::create($this->validateRequest());
    return redirect('/slaughter')->with('message', 'Clinic Details Attached');
}

private function validateRequest()
{ 

    return request()->validate([
        'animal_id' => 'required',
        'slaughter_id' => 'required',
        'slaughtering' => 'required',
    ]);
}



Aucun commentaire:

Enregistrer un commentaire