I m using laravel 8 controller for saving text input type using "Store function".My input for 'name' are not stored in database when i submited it.
Here is my 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>
Here is my 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');
}
your parameter is not complete, 'detail' => 'required'
but it's not found
you need new value input <input type="text" class="form-control" id="detail" placeholder="detail" name="detail">
and you have to add attribute name
in every input
for complete code like this bellow
<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>
and for save or store method https://laravel.com/docs/8.x/eloquent#inserts
$product= new Product;
$product->name = $request->name;
$product->detail= $request->detail;
$product->save();
or like this
$product= Product::create([
'name' => $request->name,
'detail' => $request->detail,
]);