class PostController extends Controller{
public $grupID = 1;
public function store(Request $request)
{
$post = new Post();
$post->GroupID = 'POST-' . $this->grupID;
$post->save();
return response()->json($post);
$this->grupID++;
}
}
数据库StructurLaravel存储数据自动递增
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->integer('PostTypeID');
$table->string('GroupID', 100)->nullable();
$table->timestamps();
});
}
我想使组ID自动递增,但它总是返回 'POST-1'。
分享你的数据库/表是怎么样子? – C2486
对不起,我对错误的人回复评论...我已经尝试了你的代码..但是groupID不会增加.. –
为什么groupid是post增量?只有post id应该增加默认值。 ? – C2486