简体   繁体   English

如何使用外键将值保存到数据库

[英]How save value to database with foreign key

I have problem! 我有问题! I do not know how save value in database with Foreign key. 我不知道如何用外键在数据库中保存价值。 I need simple solution! 我需要简单的解决方案! My foreign key reference on Countries table! 我在“国家/地区”表上的外键参考!

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();
}

Not sure how your presentation layer (backoffice, otherwise a security issue?) has been setup. 不确定如何设置您的表示层(后台,是否存在安全问题?)。 But if the country_id is static on a specific view, you could use a hidden form variable: 但是,如果country_id在特定视图上是静态的,则可以使用隐藏的表单变量:

<input type="hidden" name="country_id" value="3">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM