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++;
}
}
Database Structur
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->integer('PostTypeID');
$table->string('GroupID', 100)->nullable();
$table->timestamps();
});
}
I want to make the groupID auto increment, but it always return 'POST-1'.