mardi 28 août 2018

input values aren't being stored in database, but options are getting read

I have this in my blade:

<div class="row">
                        <div class="col-sm-6">
                                <label for="name">Name</label>
                                <input class="form-control" type="text" id="name" name="name">
                        </div>
                        <div class="col-sm-6">
                                <label for="slug">Slug</label>
                                <input class="form-control" type="text" id="slug" name="slug"> 
                        </div>
                    </div>
                    <br>
                    <div class="row">
                        <div class="col-sm-6">
                            <label for="item_type">Item Type</label>
                                <select class="form-control" id="item_type" name="item_type">
                                    <option value="physical-goods">Physical Goods</option>
                                    <option value="digital-downloads">Digital Downloads</option>
                                    <option value="credits">Credits</option>
                                </select>
                        </div>
                        <div class="col-sm-6">
                            <label for="order_mode">Order Mode</label>
                                <select class="form-control" id="order_mode" name="order_mode">
                                    <option value="fcfs">First Come, First Serve</option>
                                    <option value="pre-selling">Pre-Selling</option>
                                    <option value="purchase-order">Purchase Order</option>
                                </select>
                        </div>
                    </div>
                    <br>
                    <div>
                        <label for="short_description">Short Description</label>
                        <textarea class="form-control" id="short_description" rows="2"></textarea>
                    </div>
                    <br>
                    <div>
                        <label for="description">Description</label>
                        <textarea class="form-control" id="description" rows="3"></textarea>
                    </div>

and I have this in my ProductsController@Store:

            $product = Product::firstorCreate([
            'name' => $request->input('name'),
            'slug' => $request->input('slug'),
            'item_type' => $request->get('item_type'),
            'order_mode' => $request->get('order_mode'),
            'short_description' => $request->input('short_description'),
            'description' => $request->input('description')
        ]);

and I get the error that name and slug is required but I typed something in the name and slug inputs. When I tried to remove the require field, I got an error and it showed that all my inputs: name, slug, short description, and description are all blank. I have checked my blade and their name checks out so why is this happening?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire