我在 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');网站.phpRoute::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>模型<?phpnamespace 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;}
1 回答
青春有我
TA贡献1784条经验 获得超8个赞
尝试改变你的模型
class Customer extends Model
{
protected $fillable = [
'nome', 'cognome', 'cap', 'comune', 'via', 'civico', 'telefono', 'email',
];
protected $table = 'customers';
}
- 1 回答
- 0 关注
- 89 浏览
添加回答
举报
0/150
提交
取消