我有问题! 我不知道如何使用外键将值保存在数据库中。 我需要简单的解决方案! 我在国家表上的外键引用!
public function create(Request $request){
$brand = new BrandCar();
$brand->name = $request->get('brand');
$brand->country_id = $request->get('country_id'); // This is foreign key
$brand->save();
}
最佳答案
不确定您的表示层(后台,否则存在安全问题?)是如何设置的。但如果 Country_id 在特定 View 上是静态的,您可以使用隐藏的表单变量:
<input type="hidden" name="country_id" value="3">
关于php - 如何使用外键将值保存到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54288952/