vendredi 13 décembre 2019

In laravel how to create unique and random number

i am trying to store unique and random student_registration_id number if i create 5000 user registration that time also it should be unique and it should 10 digit

and also i am storing student image below image storing unique id is perfect or not

now i am using below code

public function store(Request $request)

{

  $this->validate($request, [

      'student_name' => 'required|string|max:255',
      'student_father_name' => 'required|string|max:255',
      'student_mother_name' => 'required|string|max:255',
      'student_photo' => 'required|image|mimes:jpeg,png,jpg|max:2048',  

]);


    $input['student_photo'] = time().'.'.$request->student_photo->getClientOriginalExtension();
    $folder1 = public_path('STUDENT_DATA/STUDENT_PHOTO/');
    $path1 = $folder1 . $input['student_photo']; // path 1
    $request->student_photo->move($folder1, $input['student_photo']); // image saved in first folder
    $path2 = public_path('../../../abc.com/public/STUDENT_DATA/STUDENT_PHOTO/') . $input['student_photo']; // path 2
    \File::copy($path1, $path2);

       $input['student_name'] = strtoupper ($request['student_name']);
       $input['student_father_name'] = strtoupper ($request['student_father_name']);
       $input['student_mother_name'] = strtoupper ($request['student_mother_name']);

       $input['student_registration_id'] ="SIIT_".time();






    Student::create($input);


   return back()->with('success',' STUDENT REGISTERD SUCCESSFULLY .');


}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire