I’m using Laravel
This is web.php
:
Route::get('/index', function () { return view('/product/index'); }); Route::get('/create', function () { return view('/product/create'); }); Route::post('','ProductController@store')->name('products.store'); Route::group(['middleware' => 'auth:admin'], function () { Route::view('/admin', 'admin'); }); Route::group(['middleware' => 'auth:seller'], function () { Route::view('/seller', 'seller'); });
This is form call create:
<div class="container"> <div class="row"> @include('admin.includes.sidebar_admin') <div class="col-md-9"> <div class="panel panel-primary"> <div class="panel-heading">Create products</div> <div class="panel-body"> <form action="{{route('product.store')}}" method="POST" enctype="multipart-data"> {{csrf_field()}} <div class="form-group"> <label for="title">Title:</label> <input type="text" name="title" class="form-control" placeholder="Title..."> </div>
When I click submit, it shows error. I want to create a new product and the detail store in database.
Please Help.
Advertisement
Answer
This is typo error. You have add same name as route name in the form action.
<form action="{{route('products.store')}}" method="POST" enctype="multipart-data"> {{csrf_field()}} <div class="form-group"> <label for="title">Title:</label> <input type="text" name="title" class="form-control" placeholder="Title..."> </div> </form>