0

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',
    ]);
}
Peter O.
  • 32,158
  • 14
  • 82
  • 96
Jimmyjbk
  • 351
  • 3
  • 20
  • You could make use of a [Uuid](https://github.com/michaeldyrynda/laravel-efficient-uuid). – Kenny Horna Oct 29 '19 at 04:59
  • Possible duplicate of [How can I create a unique random string in laravel 5](https://stackoverflow.com/questions/33304930/how-can-i-create-a-unique-random-string-in-laravel-5) – farooq Oct 29 '19 at 05:05
  • let me try that – Jimmyjbk Oct 29 '19 at 05:05
  • see https://stackoverflow.com/questions/1846202/php-how-to-generate-a-random-unique-alphanumeric-string – JustLearninThisStuff Oct 29 '19 at 05:19
  • 1
    Possible duplicate of [PHP: How to generate a random, unique, alphanumeric string?](https://stackoverflow.com/questions/1846202/php-how-to-generate-a-random-unique-alphanumeric-string) – Peter O. Oct 29 '19 at 05:20
  • You can create a random number using PHP's `random_bytes`; however, random numbers cannot ensure absolute uniqueness by themselves. Consider reading my principles on [unique random identifiers](https://peteroupc.github.io/random.html#Unique_Random_Identifiers), and editing your question to respond to the six questions I mention in those principles. – Peter O. Oct 29 '19 at 05:26
  • From Laravel helper functions you may use the UUID https://laravel.com/docs/5.7/helpers – Muhammad Oct 29 '19 at 06:20
  • Is there any way to customize the uuid – Jimmyjbk Oct 30 '19 at 07:09

0 Answers0