亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Laravel 5.8 字段“名稱”沒有默認值

Laravel 5.8 字段“名稱”沒有默認值

PHP
料青山看我應如是 2021-12-03 19:39:17
您好,我在 laravel 中開發了一個學生 CRUD,但是我在將數據保存在我的數據庫中時遇到了問題。這是laravel返回的問題。SQLSTATE[HY000]:一般錯誤:1364 字段“名稱”沒有默認值我的商店功能。public function store(Request $request)    {        $alumno = Alumno::create();        $alumno->fill($request->all());        $alumno->save();        return redirect('/alumnos');    }我的型號:class Alumno extends Model{    protected $fillable = ['name','apellido','matricula','correo'];}我的表格:<form action="/alumnos" method="post">    @csrf    <fieldset class="form-fieldset">        <div class="form-group">            <label class="form-label">Nombre<span class="form-required">*</span></label>            <input type="text" class="form-control" name="name" required/>        </div>        <div class="form-group">            <label class="form-label">Apellido<span class="form-required">*</span></label>            <input type="text" class="form-control" name="apellido" required/>        </div>        <div class="form-group">            <label class="form-label">Matricula<span class="form-required">*</span></label>            <input type="number" class="form-control" required name="matricula" />        </div>        <div class="form-group mb-0">            <label class="form-label">Correo Electronico<span class="form-required">*</span></label>            <input type="email" class="form-control" name="correo" required />        </div>    </fieldset>    <input type="submit" class="btn btn-primary" value="Guardar" /></form>我做錯了什么?請幫忙,謝謝?。。?)
查看完整描述

3 回答

?
蝴蝶不菲

TA貢獻1810條經驗 獲得超4個贊

您應該將行添加到遷移

$table->string('name')->nullable();

設置表格如上

 <form action="{{action('YourController@store')}}">

用于插入所有請求輸入

Alumno::create($request->all());


查看完整回答
反對 回復 2021-12-03
?
守著一只汪

TA貢獻1872條經驗 獲得超4個贊

您應該按如下方式保存數據:


public function store(Request $request)

    {

        $alumno = new Alumno();

        $alumno = $alumno->create($request->all());

        return redirect('/alumnos');

    }

它會正常工作。


查看完整回答
反對 回復 2021-12-03
?
HUX布斯

TA貢獻1876條經驗 獲得超6個贊

問題是從表單操作 URL 嘗試將操作更改為 {{ action('YourController@store') }}


查看完整回答
反對 回復 2021-12-03
  • 3 回答
  • 0 關注
  • 264 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號