所有记录都为空 laravel

我在 SQLite 数据库中保存对象时遇到问题。在我插入非空值的表单中,请求具有正确的数据,但是当我将对象保存在数据库中时,只有空值。在表格中,我只提供了 1 个示例,但表格会针对各种输入重复。


客户控制器.php


$data = request()->validate([

    'nome' => 'required|max:40|unique:users',

    'cognome' => 'required|max:40|unique:users',

    'cap' => 'required|min:5',

    'comune' => 'required|max:40',

    'via' => 'required|max:40',

    'civico' => 'required|max:40',

    'telefono' => 'required',

    'email' => 'email|unique:users',

]);

$customer = new Customer();

$customer->nome = $request->input('nome');

$customer->cognome = $request->input('cognome');

$customer->cap = $request->input('cap');

$customer->comune = $request->input('comune');

$customer->via = $request->input('via');

$customer->civico = $request->input('civico');

$customer->telefono = $request->input('telefono');

$customer->email = $request->input('email');


($customer->save());


return view('home');

网站.php


Route::get('customer/create', 'CustomerController@create')->middleware(CheckAdmin::class)->name('customer.create');


Route::post('customer/', 'CustomerController@store')->middleware(CheckAdmin::class)->name('customer.store');

形式


<form method="POST" action="/customer/">

    @csrf

    <div class="form-group row">

        <label for="nome" class="col-md-4 col-form-label text-md-right">{{ __('Nome') }}</label>


        <div class="col-md-6">

            <input id="nome" type="text" class="form-control @error('nome') is-invalid @enderror" name="nome" value="{{ old('nome') }}" required autocomplete="nome" autofocus>


            @error('nome')

                <span class="invalid-feedback" role="alert">

                    <strong>{{ $message }}</strong>

                </span>

            @enderror

        </div>

    </div>

    ...

</form>

模型


<?php


namespace App;


use Illuminate\Database\Eloquent\Model;


class Customer extends Model

{

    protected $fillable = ['*'];



    protected $table = 'customers';


    public $nome;

    public $cognome;

    public $cap;

    public $comune;

    public $via;

    public $civico;

    public $telefono;

    public $email;


}


哔哔one
浏览 90回答 1
1回答

青春有我

尝试改变你的模型class Customer extends Model{&nbsp; protected $fillable = [&nbsp; &nbsp; 'nome', 'cognome', 'cap', 'comune', 'via', 'civico', 'telefono', 'email',&nbsp; ];&nbsp; protected $table = 'customers';}
打开App,查看更多内容
随时随地看视频慕课网APP