作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用“添加产品”功能为我的网站创建了一个后端,但是当我添加它时,我没有在 table 上创建产品,并且出现此错误
我有这个错误:
Symfony \ Component \ HttpKernel \ Exception \
MethodNotAllowedHttpException
No message
我的表格:
@extends('admin.layout.admin')
@section('content')
<h3>Aggiungi Prodotto</h3>
<div class='row'>
<div class="col-md-8 col-md-offset-2">
{!! Form::open(['route'=>'product.create','method'=>'post', 'files'=>true]) !!}
<div class="form-group">
{{ Form::label('nome', 'Nome') }}
{{ Form::text('nome', null, array('class'=> 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('descrizione', 'Descrizione') }}
{{ Form::text('descrizione', null, array('class'=> 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('prezzo', 'Prezzo') }}
{{ Form::text('prezzo', null, array('class'=> 'form-control')) }}
</div>
<div class="form-group">
{{ Form::label('category_id', 'Categoria') }}
{{ Form::select('category_id',[1=>'Flauti'],null,['class'=> 'form-control','placeholder'=>'Seleziona Categoria']) }}
</div>
<div class="form-group">
{{ Form::label('image', 'Image') }}
{{ Form::file('image',array('class'=> 'form-control')) }}
</div>
{{ Form::submit('create', array('class'=>'btn btn-->default')) }}
{!! Form::close() !!}
</div>
</div>
@endsection
我的路线:
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', 'frontcontroller@index');
Route::get('/index.html', 'frontcontroller@index');
Route::get('/checkout.html', 'frontcontroller@checkout');
Route::get('/furniture.html', 'frontcontroller@furniture');
Route::get('/login.html', 'frontcontroller@login');
Route::get('/products.html', 'frontcontroller@products');
Route::get('/register.html', 'frontcontroller@register');
Route::get('/single.html', 'frontcontroller@single');
Auth::routes();
Route::get('/logout', 'Auth\LoginController@logout')->name('home');;
Route::get('/home', 'HomeController@index')->name('home');
Route::group(['prefix' => 'admin' ,'middleware'=>'auth'], function () {
Route::get('/', function () {
return view('admin.index');
})->name('admin.index');
Route::resource('product','ProductsController');
Route::resource('category','CategoriesController');
});
我的 Controller :
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Category;
class ProductsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
$categories=Category::pluck('nome','id');
return view('admin.product.create',compact('categories'));
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$formInput=$request->except('image');
//image upload
$image=$request->image;
if ($image){
$imageName=$image->getClientOriginName();
$image->move('image',$imageName);
$formInput['image']=$imageName;
}
Product::create($formInput);
return redirect()->route('admin.index');
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
}
最佳答案
请更改表单中的以下行
{!! Form::open(['route'=>'product.create','method'=>'post', 'files'=>true]) !!}
到
{!! Form::open(['route'=>'product.store','method'=>'post', 'files'=>true]) !!}
基本上,创建路由是为了在使用资源时显示表单。但是,当您想提交表单时,您需要提交到 .store,或者如果它是编辑表单,则提交到 .update 路由。
关于php - 如何在 Symfony 中调试 "MethodNotAllowedHttpException"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47684937/
我是一名优秀的程序员,十分优秀!