我如何自动生成字符串我希望每次按下提交按钮时字符串都会递增,例如我有字符串TEST0001,接下来应该是TEST0002,TEST0003,TEST0004,直到结束。
迁移表
public function up()
{
Schema::create('leads', function (Blueprint $table) {
$table->increments('id');
$table->string('generate_id');
$table->string('name')->nullable();
$table->timestamps();
});
}
控制器:
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.');
}