H
H
HeartOfProgrammer2016-03-03 18:02:56
Laravel
HeartOfProgrammer, 2016-03-03 18:02:56

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">

In ProductController I have such a method as store:
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');
    }

And here is my form:
<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-->

Laravel gives such an error when trying to send data to
6e104553390f421598d5c191e265c7d4.png
the database
PS Where and in what did I make a mistake in the code?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Arthur, 2016-03-03
@HeartOfProgrammer

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>

S
Stanislav Pochepko, 2016-03-03
@DJZT

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 question

Ask a Question

731 491 924 answers to any question