Function Store 未保存在数据库中 laravel 8
Function Store not save in database laravel 8
我正在使用 laravel 8 控制器使用“存储功能”保存文本输入类型。我提交时 'name' 的输入未存储在数据库中。
这是我的blade
<form class="text-center p-4" action="{{ route('store') }}" method = "POST">
@csrf
<div class="mb-3">
<label for="exampleFormControlInput1" class="form-label">names</label>
<input type="text" class="form-control" id="name" placeholder="name">
</div>
<button class="btn btn-primary" type="submit">Button</button>
</form>
这是我的 ProductController.php
public function create()
{
return view('products.create');
}
public function store(Request $request)
{
$request->validate([
'name' => 'required',
'detail' => 'required',
]);
Product::create($request->all());
$products -> save();
return redirect('/saving-list') ->with('success','Umrah record has been updated');
}
你的参数不完整,'detail' => 'required'
但是没找到
您需要输入新值<input type="text" class="form-control" id="detail" placeholder="detail" name="detail">
并且您必须在每个输入中添加属性 name
像下面这样的完整代码
<form class="text-center p-4" action="{{ route('store') }}" method = "POST">
@csrf
<div class="mb-3">
<label for="exampleFormControlInput1" class="form-label">names</label>
<input type="text" class="form-control" id="name" name="name" placeholder="name">
<input type="text" class="form-control" id="detail" name="detail" placeholder="detail">
</div>
<button class="btn btn-primary" type="submit">Button</button>
</form>
以及保存或存储方法https://laravel.com/docs/8.x/eloquent#inserts
$product= new Product;
$product->name = $request->name;
$product->detail= $request->detail;
$product->save();
或者像这样
$product= Product::create([
'name' => $request->name,
'detail' => $request->detail,
]);
我正在使用 laravel 8 控制器使用“存储功能”保存文本输入类型。我提交时 'name' 的输入未存储在数据库中。
这是我的blade
<form class="text-center p-4" action="{{ route('store') }}" method = "POST">
@csrf
<div class="mb-3">
<label for="exampleFormControlInput1" class="form-label">names</label>
<input type="text" class="form-control" id="name" placeholder="name">
</div>
<button class="btn btn-primary" type="submit">Button</button>
</form>
这是我的 ProductController.php
public function create()
{
return view('products.create');
}
public function store(Request $request)
{
$request->validate([
'name' => 'required',
'detail' => 'required',
]);
Product::create($request->all());
$products -> save();
return redirect('/saving-list') ->with('success','Umrah record has been updated');
}
你的参数不完整,'detail' => 'required'
但是没找到
您需要输入新值<input type="text" class="form-control" id="detail" placeholder="detail" name="detail">
并且您必须在每个输入中添加属性 name
像下面这样的完整代码
<form class="text-center p-4" action="{{ route('store') }}" method = "POST">
@csrf
<div class="mb-3">
<label for="exampleFormControlInput1" class="form-label">names</label>
<input type="text" class="form-control" id="name" name="name" placeholder="name">
<input type="text" class="form-control" id="detail" name="detail" placeholder="detail">
</div>
<button class="btn btn-primary" type="submit">Button</button>
</form>
以及保存或存储方法https://laravel.com/docs/8.x/eloquent#inserts
$product= new Product;
$product->name = $request->name;
$product->detail= $request->detail;
$product->save();
或者像这样
$product= Product::create([
'name' => $request->name,
'detail' => $request->detail,
]);