Php Idgenerator laravel 8,如何修复异常;表字段类型为bigint,但前缀为string";
为什么总是出现此消息? 即使我想用两个点做一个id,比如=190772.2021.00000001 不能添加“.”(点)这样只能添加1个点只有1907722021.00000001 factory.phpPhp Idgenerator laravel 8,如何修复异常;表字段类型为bigint,但前缀为string";,php,laravel,eloquent,laravel-8,Php,Laravel,Eloquent,Laravel 8,为什么总是出现此消息? 即使我想用两个点做一个id,比如=190772.2021.00000001 不能添加“.”(点)这样只能添加1个点只有1907722021.00000001 factory.php namespace Database\Factories; use App\Models\Anggota; use Illuminate\Database\Eloquent\Factories\Factory; use App\Models\User; use Haruncpi\Larav
namespace Database\Factories;
use App\Models\Anggota;
use Illuminate\Database\Eloquent\Factories\Factory;
use App\Models\User;
use Haruncpi\LaravelIdGenerator\IdGenerator;
class AnggotaFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Anggota::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
$tgl = $this->faker->date;
return [
'id_user' => User::factory(),
'no_anggota' => IdGenerator::generate([
'table' => 'anggotas',
'length' => 19,
'prefix' => date('dmy', strtotime($tgl)).date('.Y.')
]),
'nama_lengkap' => $this->faker->name,
'tempat_lahir' => $this->faker->cityPrefix,
'tanggal_lahir' => $tgl,
'nama_instansi' => $this->faker->word,
];
}
}
文件迁移
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateAnggotasTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('anggotas', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('id_user')->unique();
$table->string('no_anggota');
$table->string('nama_lengkap');
$table->string('tempat_lahir');
$table->date('tanggal_lahir');
$table->string('nama_instansi');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('anggotas');
}
}
而模式数据库中的列“no_anggota”的类型为“string”,但显示为“table field type为bigint,prefix为string”
如何求解,使结果=190772.2021.00000001
帮助我,谢谢软件包默认使用表的id
列。根据您的需要,您还必须通过字段
您所需的输出:190772.2021.00000001(长度20,带两个点)
解决方案:只需通过'field'=>'no_anggota'
和'length'=>20
$tgl = $this->faker->date;
$idConfig = [
'table' => 'anggotas',
'field' => 'no_anggota',
'length' => 20,
'prefix' => date('dmy', strtotime($tgl)).date('.Y.')
];
return [
'id_user' => User::factory(),
'no_anggota' => IdGenerator::generate($idConfig),
'nama_lengkap' => $this->faker->name,
'tempat_lahir' => $this->faker->cityPrefix,
'tanggal_lahir' => $tgl,
'nama_instansi' => $this->faker->word,
];
谢谢,它的工作:)