Answer the question
In order to leave comments, you need to log in
Why doesn't laravel want to add a new product to the database?
I'm pretty sure there is a bug in my code, but I don't know where it is.
It seems that I wrote the method and action correctly:
<form method="POST" action="ProductController/store" class="col s12">
public function store(PublishProductRequest $requestData)
{
$product = new Product;
$product->title = $requestData['title'];
$product->description = $requestData['description'];
$product->full_description = $requestData['full_description'];
$product->author = $requestData['author'];
$product->save();
return redirect()->route('product.index');
}
<form method="POST" action="ProductController/store" class="col s12">
<input name="_token" type="hidden" value="{{ csrf_token() }}">
<div class="row">
<div class="input-field amber-text darken-2-text col s6">
<i class="material-icons prefix amber-text darken-2-text">account_circle</i>
<input id="first_name" type="text" class="amber-text darken-2-text validate">
<label class="amber-text darken-2-text" for="title">title</label>
</div>
</div>
<div class="row">
<div class="input-field amber-text darken-2-text col s6">
<i class="material-icons prefix amber-text darken-2-text">account_circle</i>
<input id="first_name" type="text" class="amber-text darken-2-text validate">
<label class="amber-text darken-2-text" for="description">Description</label>
</div>
</div>
<div class="row">
<div class="input-field amber-text darken-2-text col s6">
<i class="material-icons prefix amber-text darken-2-text">account_circle</i>
<input id="first_name" type="text" class="amber-text darken-2-text validate">
<label class="amber-text darken-2-text" for="full_description">Full description</label>
</div>
</div>
<div class="row">
<div class="input-field amber-text darken-2-text col s6">
<i class="material-icons prefix amber-text darken-2-text">account_circle</i>
<input id="first_name" type="text" class="amber-text darken-2-text validate">
<label class="amber-text darken-2-text" for="author">Author</label>
</div>
</div>
<div class="row">
<div class="file-field input-field col s6">
<div class="btn amber darken-2">
<span>IMG</span>
<input type="file">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text">
</div>
</div>
</div>
<input type="submit">
</form><!--End The form col s12-->
Answer the question
In order to leave comments, you need to log in
in routes.php it seems that the path to the controller / method is written
at the same time, the final path is already indicated in the form, and not the name of the controller with the method
<form method="POST" action="/product/save" class="col s12"></form>
Your input doesn't have a name="title, description, etc"
attribute URI helper doc
<form method="POST" action="action([email protected])" class="col s12">
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question