简体   繁体   English

在laravel 5中自定义注册表格

[英]customize registration form in laravel 5

I am, newbie on Laravel 5, I need to customize registration form in laraverl 5 so i added some extra fields such as fullname, company, country and mobile number. 我是Laravel 5的新手,我需要在laraverl 5中自定义注册表格,因此我添加了一些额外的字段,例如全名,公司,国家和移动电话号码。

I added them successfully to resources/views/auth/register.blade.php see image: 我已将它们成功添加到resources / views / auth / register.blade.php中,见图: 在此处输入图片说明

and updated Services/Register.php file to save new fields to users table and that's work fine. 并更新了Services / Register.php文件,以将新字段保存到users表中,并且工作正常。

my problem now is: i need country field is selected list not textfield. 我现在的问题是:我需要选择国家字段而不是文本字段。

I have table in database 'countries' and I have model 'Country', so how can it build selected list and fill it with countries from countries table. 我在“国家/地区”数据库中有表,而在“国家/地区”模型中,因此如何建立所选列表并用“国家/地区”表中的国家/地区填充它。

Just add: 只需添加:

{!! Form::select('country', App\Country::lists('name', 'id'), null, ['class'=> 'form-control']) !!}

This will list all the countries to select tag from the database table. 这将列出所有要从数据库表中选择标签的国家。

Replace name to column name assigned for country name. name替换为为国家名称分配的列名称。

Note: install "illuminate/html" package to use Form facade. 注意:安装"illuminate/html"软件包以使用Form Facade。

EDIT : the previous code was a little wrong and it caused errors. 编辑 :以前的代码是有点错误,它导致错误。 Now it is fixed. 现在已修复。

The selected answer is missing a 2nd : 所选答案缺少第二个答案:

It should be: 它应该是:

{!! Form::select('user_type_id', App\UserType::lists('name', 'id'), null, ['class'=> 'form-control']) !!}

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

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