为什么在Laravel中没有保存表单数据?(why did not save form data in Laravel?)

编程入门 行业动态 更新时间:2024-10-28 01:18:36
为什么在Laravel中没有保存表单数据?(why did not save form data in Laravel?)

我在My laravel应用程序中使用Auth:命令注册表单。 并且我已经为register.blade.php文件添加了新的nic输入框,如register.blade.php

<div class="form-group{{ $errors->has('nic') ? ' has-error' : '' }}"> <label for="nic" class="col-md-4 control-label">NIC</label> <div class="col-md-6"> <input id="nic" type="text" class="form-control" name="nic"> @if ($errors->has('nic')) <span class="help-block"> <strong>{{ $errors->first('nic') }}</strong> </span> @endif </div> </div>

和我的AuthController是这样的,

protected function validator(array $data) { return Validator::make($data, [ 'username' => 'required|max:255', 'email' => 'required|email|max:255|unique:users', 'password' => 'required|min:6|confirmed', 'nic' => 'required|min:10', ]); } protected function create(array $data) { return User::create([ 'username' => $data['username'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'nic' => $data['nic'], ]); }

并且我在Users表中也有新的专栏。 但是当我点击注册按钮时,其他数据值很好地保存在用户表中,但是密码栏没有保存好的值。 如何解决这个问题?

I am using Auth: command register form in My laravel application. and I have add new nic input box to register.blade.php file as this, register.blade.php

<div class="form-group{{ $errors->has('nic') ? ' has-error' : '' }}"> <label for="nic" class="col-md-4 control-label">NIC</label> <div class="col-md-6"> <input id="nic" type="text" class="form-control" name="nic"> @if ($errors->has('nic')) <span class="help-block"> <strong>{{ $errors->first('nic') }}</strong> </span> @endif </div> </div>

and MY AuthController is like this,

protected function validator(array $data) { return Validator::make($data, [ 'username' => 'required|max:255', 'email' => 'required|email|max:255|unique:users', 'password' => 'required|min:6|confirmed', 'nic' => 'required|min:10', ]); } protected function create(array $data) { return User::create([ 'username' => $data['username'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'nic' => $data['nic'], ]); }

and I have new column as nic in Users table as well. but when I click register button other data values saving well in users table but nic column not saving nic values. how can solve this problem?

最满意答案

检查您的用户模型是否在$fillable数组中添加了nic,因为您执行的是批量分配

<?php namespace App; use Illuminate\Database\Eloquent\Collection; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Backpack\Base\app\Notifications\ResetPasswordNotification as ResetPasswordNotification; class User extends Authenticatable { use Notifiable; protected $fillable = ['username', 'email', 'password', 'nic']; }

Check in your User model if nic is added in $fillable array because you do a mass assignement

<?php namespace App; use Illuminate\Database\Eloquent\Collection; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Backpack\Base\app\Notifications\ResetPasswordNotification as ResetPasswordNotification; class User extends Authenticatable { use Notifiable; protected $fillable = ['username', 'email', 'password', 'nic']; }

更多推荐

本文发布于:2023-07-29 14:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1316819.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   数据   Laravel   data   form

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!