copain
1 year ago
193
12
Laravel

Auto Increment string

Posted 1 year ago by copain

how do i create auto increment string in laravel and store it into mysql database? something like this? TEST001,TEST002,TEST003,TEST004,.....TEST001,

MIGRATION TABLE.

 public function up()`

{
    Schema::create('leads', function (Blueprint $table) {
        $table->increments('id');
        $table->string('generate_id');
        $table->string('name')->nullable();
        $table->timestamps();
    });
}```



CONTROLLER:


```public function store(Request $request)
{
    //
    $this->validate($request, [


           'generate_id'=>'required|Unique',


            ]);
            $leads=new lead();
            $leads->generate_id=$request->generate_id;
            $leads->name=$request->name;
            $leads->save();

            return redirect()->route('leads.index')
        ->with('flash_message', 'Success.');
}

Please sign in or create an account to participate in this conversation.