I think you have to note these instructions : if($last_number_length>$length){$og_length=0;} else{$og_length=$length-$last_number_length;} thank you for this video.
In laravel 9 with PHP 8.1.2 it shows this error “Unsupported operand types: string / int” when saving for the first time. change the line $code = substr($data->$trow, strlen($prefix)+1); to $code = (int)(substr($data->$trow, strlen($prefix)+1)); With that it works for me, thank you very much for the idea of the IDGenerator.
how to create 2 different idgenerator (different prefix) on the same table. Like STD-0001, STD-0002 then in another prefix ABC-0001, ABC-0002 and so on. can you help me?
I have an error its "Attempt to read property "no" on null". "no" is like the number id of document and the error was in this line : $code=(substr($data->$trow, strlen($prefix)+1)); how to solve this sir, thanks before
Hi Got This ErrorException A non-numeric value encountered, when i add 3 or 4 more student at the code $actia_last_number = ($code/1)*1; do you know how to solve this problem?
Hi Irebe, thank you so much for your video, can you please tell me and how to fix this error, ErrorException Required parameter $prefix follows optional parameter $length I use same your code in helper class.
make sure that this helper function has all parameters public static function IDGenerator($model, $trow, $length = 4, $prefix){} also in controller: $student_id = Helper::IDGenerator(new Student, 'student_id', 2, 'STD'); /** Generate id */
@@sawastacks Thank you so much for your support, much appreciated. I checked, but I have same error, This my code: in contoller: function insertDoctor(Request $request){ $request->validate([ 'name'=>'required', ]); $name = $request->name; $email = $request->email; $phone = $request->phone; $address = $request->address; $commission = $request->commission; $doctor_id = mi::IDGenerator(new doctors, 'doctor_id', 2, 'Dr'); /** Generate id */ $q = new doctors; $q->doctor_id = $doctor_id; $q->name = $name; $q->email = $email; $q->phone = $phone; $q->address = $address; $q->commission = $commission; $save = $q->save(); if($save){ return back()->with('success','New studen has been added'); }else{ return back()->with('faile','Something went wrong'); } } And I use custom helper class and I import: use App\mi\mi; inside ( mi ) class, I use same your code without edit it. public static function IDGenerator($model, $trow, $length = 4, $prefix){} And also make a route: Route::post('insertdoctor',[AdminController::class,'insertDoctor'])->name('admin.insertDoctor'); and call that route in form: action="{{ route('admin.insertDoctor') }}" And I import also model class: use App\Models\doctors; this is code in model class class doctors extends Model { use HasFactory; protected $primaryKey = 'id'; protected $fillable = [ 'doctor_id', 'name', 'email', 'phone', 'address', 'commission' ]; } I think everything fine, but I don't know why give me that error.
Hello, Thanks for the great video. Am getting an error though whenever I try to add a new student. Could you kindly assist?, My error is "Trying to get property 'STD-00001' of non-object"
@@sawastacks This is my code in the StudentsController, This function "add_student" is meant to add a new student. So I used your method to generate a random ID. public function add_student(request $request){ $this->validate ($request, [ 'a_date' => ['required'], 'a_year' => ['required'], 'a_grade' => ['required'], 'fname' => ['required', 'string', 'max:255'], 'mname' => ['string', 'max:255'], 'lname' => ['required', 'string', 'max:255'], 'gender' => ['required'], 'dob' => ['required'], 'c_school' => ['string', 'max:255'], 'parent' => ['string', 'max:255'], 'p_relation' => ['string'],
],[ 'fname.required' => "The :value First Name is required.", 'lname.required' => "The :value Last Name is required.", 'a_grade.required' => "The :value Admission Grade is required.", ]);
@Stephen Awuor 1) student_id (s) must be lower case on this line: $Student_id = Helper::IDGenerator(new Students, 'Student_id', 4, 'STD'); to $Student_id = Helper::IDGenerator(new Students, 'student_id', 4, 'STD'); 2) make sure that you import this on this controller: use App\Helpers\Helper; use App\Models\Student; use Validator; 3) Watch how you can create custom helper: ruclips.net/video/Mr5hRns6U50/видео.html
Thank you so much! i'm getting "Unsupported operand types: string / int" error on helper.php where the line $actial_last_number = ($code/1)*1; is found.
Thank you so much. This video helped me to resolve one of my ID Generating issues.
I think you have to note these instructions :
if($last_number_length>$length){$og_length=0;}
else{$og_length=$length-$last_number_length;}
thank you for this video.
In laravel 9 with PHP 8.1.2 it shows this error “Unsupported operand types: string / int” when saving for the first time.
change the line
$code = substr($data->$trow, strlen($prefix)+1);
to
$code = (int)(substr($data->$trow, strlen($prefix)+1));
With that it works for me, thank you very much for the idea of the IDGenerator.
Hello alexander.
I hadn't tried it in laravel 9.
Thank you so much for the correction
thank you for your help :)
this tutorial saved me.how can i pass the custom id generated to an api endpoint?
very helpful. Thank yoyu
This is great tutorial video, thanks for sharing.
Glad it was helpful!
Since it is capturing max ID What happens if two users are trying to insert new student simultaneously????
Thanks 🔥
Hi Elie Bea. you can use my package: github.com/mbere250/laravel-idify for creating custom ID. That package will do the same to this.
how to create 2 different idgenerator (different prefix) on the same table. Like STD-0001, STD-0002 then in another prefix ABC-0001, ABC-0002 and so on. can you help me?
Bro i was succeed generating Id like INV-00001 .. but when i try to get on my view... it just show 0... so how to get the original value of my id?
I have an error its "Attempt to read property "no" on null". "no" is like the number id of document and the error was in this line : $code=(substr($data->$trow, strlen($prefix)+1));
how to solve this sir, thanks before
Thank you so much for your help
merci beaucoup!
if i use this code using facade then facade is define in place of $model.plz tell
i have a question, how can i reset the counter yearly or monthly, lets say STD-2112001 then next year STD-2201001
damn another great video you just earn my sub
can you please add this code to Github repository. Nice video Thanks
Thanks, excellent and really useful tutorial.
Glad you enjoyed it!
how first number id i want first number one not a zero how i can try in code, please help me
Can you try our laravel packages: github.com/mbere250/laravel-idify
You just earned a sub. I hope you'll do more in the future! Thank you!
Thanks for the sub!
i realize I am pretty off topic but does anyone know of a good place to watch new movies online ?
@Ronan Joziah lately I have been using FlixZone. You can find it by googling =)
hi irebe i need help for the same situation where i have a employee-id i need to be save as emp001 but i a m failing to do it
Just change this function like this
Tôi muốn thêm nhiều trong 1 lần thì phải làm sao
Hi Got This ErrorException A non-numeric value encountered, when i add 3 or 4 more student at the code $actia_last_number = ($code/1)*1; do you know how to solve this problem?
Have you check $actia_last_number => $actial_last_number ?
@@sawastacks I solve the problem, because about database on mysql, i change to int -> varchar then is work
@@ThuyLe-gu7cy nice! I already add link of this on description.
Hi Irebe, thank you so much for your video, can you please tell me and how to fix this error,
ErrorException
Required parameter $prefix follows optional parameter $length
I use same your code in helper class.
make sure that this helper function has all parameters
public static function IDGenerator($model, $trow, $length = 4, $prefix){}
also in controller:
$student_id = Helper::IDGenerator(new Student, 'student_id', 2, 'STD'); /** Generate id */
@@sawastacks Thank you so much for your support, much appreciated.
I checked, but I have same error, This my code:
in contoller:
function insertDoctor(Request $request){
$request->validate([
'name'=>'required',
]);
$name = $request->name;
$email = $request->email;
$phone = $request->phone;
$address = $request->address;
$commission = $request->commission;
$doctor_id = mi::IDGenerator(new doctors, 'doctor_id', 2, 'Dr'); /** Generate id */
$q = new doctors;
$q->doctor_id = $doctor_id;
$q->name = $name;
$q->email = $email;
$q->phone = $phone;
$q->address = $address;
$q->commission = $commission;
$save = $q->save();
if($save){
return back()->with('success','New studen has been added');
}else{
return back()->with('faile','Something went wrong');
}
}
And I use custom helper class and I import:
use App\mi\mi;
inside ( mi ) class, I use same your code without edit it.
public static function IDGenerator($model, $trow, $length = 4, $prefix){}
And also make a route:
Route::post('insertdoctor',[AdminController::class,'insertDoctor'])->name('admin.insertDoctor'); and call that route in form:
action="{{ route('admin.insertDoctor') }}"
And I import also model class:
use App\Models\doctors;
this is code in model class
class doctors extends Model
{
use HasFactory;
protected $primaryKey = 'id';
protected $fillable = [
'doctor_id',
'name',
'email',
'phone',
'address',
'commission'
];
}
I think everything fine, but I don't know why give me that error.
@Aya Media Oooh! Am going to check that
@Aya Media it's working, Thank you so much sir.
1364 Field 'customer_id' doesn't have a default value (SQL: insert into `contacts`
$table->string(''customer_id')->nullable(); in migration file
Hello, Thanks for the great video. Am getting an error though whenever I try to add a new student. Could you kindly assist?, My error is "Trying to get property 'STD-00001' of non-object"
Let me check
@@sawastacks Thank you, would you want to see my code?
@@stephenawuor8817 Yeah. show me
@@sawastacks
This is my code in the StudentsController, This function "add_student" is meant to add a new student. So I used your method to generate a random ID.
public function add_student(request $request){
$this->validate ($request, [
'a_date' => ['required'],
'a_year' => ['required'],
'a_grade' => ['required'],
'fname' => ['required', 'string', 'max:255'],
'mname' => ['string', 'max:255'],
'lname' => ['required', 'string', 'max:255'],
'gender' => ['required'],
'dob' => ['required'],
'c_school' => ['string', 'max:255'],
'parent' => ['string', 'max:255'],
'p_relation' => ['string'],
],[
'fname.required' => "The :value First Name is required.",
'lname.required' => "The :value Last Name is required.",
'a_grade.required' => "The :value Admission Grade is required.",
]);
$newstudent=new Students();
$Student_id = Helper::IDGenerator(new Students, 'Student_id', 4, 'STD');
$newstudent->a_date=$request->input('a_date');
$newstudent->a_year=$request->input('a_year');
$newstudent->a_grade=$request->input('a_grade');
$newstudent->fname=$request->input('fname');
$newstudent->mname=$request->input('mname');
$newstudent->lname=$request->input('lname');
$newstudent->gender=$request->input('gender');
$newstudent->dob=$request->input('dob');
$newstudent->c_school=$request->input('c_school');
$newstudent->parent=$request->input('parent');
$newstudent->p_relation=$request->input('p_relation');
$newstudent->Student_id->$Student_id;
$newstudent->save();
return redirect ('/admin_students')->with('success', 'New Student Successfully Added!');
}
@Stephen Awuor 1) student_id (s) must be lower case on this line:
$Student_id = Helper::IDGenerator(new Students, 'Student_id', 4, 'STD');
to $Student_id = Helper::IDGenerator(new Students, 'student_id', 4, 'STD');
2) make sure that you import this on this controller:
use App\Helpers\Helper;
use App\Models\Student;
use Validator;
3) Watch how you can create custom helper:
ruclips.net/video/Mr5hRns6U50/видео.html
Thank you so much! i'm getting "Unsupported operand types: string / int" error on helper.php where the line $actial_last_number = ($code/1)*1; is found.
$actual_last_number = ($code/1)*1;
I'm also getting the same error.
You have to do cast $core=(int) $core
Hi, how to change the start number from "0" To "1" So the first number is 00001 not 00000?
Use this code:
if(!$data){
$og_length = $length;
$last_number = 1;
}else{..........
@@alphonsesossou4283 if(!$data){
$og_length = $length-1;
$last_number = 1;
}else{..........
@@hidjrahs i error in $actial_last_number = ($code/1)*1; in message error A non-numeric value encountered
How to add year bro ? STR-00000-2021
Add date("Y") at the end of the return as a suffix
@@cristianbilu return $prefix.'-'.$zeros.$number.date('Y);
hello, i have problem can you help me? Undefined variable: data
my code : controller
public function store(Request $request)
{
$kode_barang = Helper::IDGenerator(new Stok, 'kode_barang', 5, 'KB-');
Stok::Create([
'kode_barang' => $kode_barang,
'nama' => $request->nama,
'kategori_id' => $request->kategori_id,
]);
return redirect('/stok-barang');
}
Stok::Create([
'kode_barang' => Helper::IDGenerator(new Stok, 'kode_barang', 5, 'KB-');
'nama' => $request->nama,
'kategori_id' => $request->kategori_id,
]);