I have a problem with my project I try write method which saved record to database. I created controller ProductsController wherein I added methods:
public function create(){
$articles = Article::lists('article_name', 'id');
$categories = Category::lists('category_name', 'id');
$date = Carbon::now();
$minDate = Carbon::minValue($date);
return view('pages.createproduct', compact('articles', 'categories', 'date', 'minDate'));
}
public function store(CreateProductRequest $request){
dd($request->article_name);
$product = new Product($request->all());
Auth::user()->products()->save($product);
return redirect('warehouse');
}
Next I created file createproduct.blade.php:
{!! Form::open(['url' => 'warehouse/create', 'class' => 'form-horizontal']) !!}
{!! Form::select('article_name[]', $articles, NULL, ['class' => 'form-control']) !!}<br />
{!! Form::select('category_name[]', $categories, NULL, ['class' => 'form-control']) !!}<br />
{!! Form::text('sn', null, ['class' => 'form-control', 'placeholder' => 'Podaj serial...']) !!}<br />
{!! Form::number('quantity', null, ['class' => 'form-control', 'min' => '1', 'placeholder' => 'Podaj ilość...']) !!}<br />
{!! Form::date('warranty', $date, ['class' => 'form-control', $minDate]) !!}<br />
{!! Form::submit('Dodaj', ['class' => 'btn btn-default']); !!}
{!! Form::close() !!}
My routes.php file looks like this:
Route::get('/contact', 'PagesController@contact');
Route::resource('/addarticle', 'ArticlesController');
Route::resource('/addcategory', 'CategoriesController');
Route::resource('/warehouse', 'ProductsController');
Route::auth();
Route::get('/home', 'HomeController@index');
And when I when I want to save the record to the database Laravel returns an error:
MethodNotAllowedHttpException in RouteCollection.php line 218
- in RouteCollection.php line 218
- at RouteCollection->methodNotAllowed(array('GET', 'HEAD', 'PUT', 'PATCH', 'DELETE')) in RouteCollection.php line 205
- at RouteCollection->getRouteForMethods(object(Request), array('GET', 'HEAD', 'PUT', 'PATCH', 'DELETE')) in RouteCollection.php line 158
- at RouteCollection->match(object(Request)) in Router.php line 821
- at Router->findRoute(object(Request)) in Router.php line 691
- at Router->dispatchToRoute(object(Request)) in Router.php line 675
- at Router->dispatch(object(Request)) in Kernel.php line 246
- at Kernel->Illuminate\Foundation\Http{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
- at Pipeline->Illuminate\Routing{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
- at CheckForMaintenanceMode->handle(object(Request), object(Closure)) at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
- at Pipeline->Illuminate\Pipeline{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
- at Pipeline->Illuminate\Routing{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
- at Pipeline->then(object(Closure)) in Kernel.php line 132
- at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
- at Kernel->handle(object(Request)) in index.php line 53