不知何故,我的laravel關係不起作用,如果我試圖保存我的外鍵保持爲空。Laravel外鍵爲空
客戶遷移
Schema::create('clients', function(Blueprint $table)
{
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
查詢遷移
Schema::create('inquiries', function(Blueprint $table)
{
$table->increments('id');
$table->unsignedInteger('client_id')->nullable();
$table->unsignedInteger('device_id')->nullable();
$table->string('android_device_token')->default('');
$table->integer('status')->default(0);
$table->timestamps();
$table->foreign('client_id')->references('id')->on('clients')->onDelete('cascade');
$table->foreign('device_id')->references('id')->on('devices')->onDelete('cascade');
});
試圖把這些請求和保存這樣的,但數據庫不斷顯示我空
$data = array(
"device_id" => $request->input('device_id'),
"client_id" => Client::find($request->input('client_id'))->id,
"android_device_token" => $inquiry->android_device_token,
"status" => $request->input('status')
);
$inquiry->fill($data);
$inquiry->save();
模型關係:
查詢:
public function client()
{
return $this->hasOne(Client::class);
}
客戶:
protected $table = 'inquiries';
protected $fillable = ['client_id', 'device_id', 'android_device_token', 'status'];
public function inquiry()
{
return $this->hasMany(Inquiry::class);
}
,你能否告訴我們'Inquiry'模型? –
你的$ $查詢有什麼? – PaladiN
@ArigiWiratama確定我在 – junikear