因此,我可以创建一个新的记录在我的数据库与窗体,但不知何故我无法删除我的数据库使用窗体而现在,我使用laravel 5。是我的代码看起来像删除方法不允许,并返回Laravel 5中的MethodNotAllowedHttpException
routes.php文件
Route::get('/', [
'as' => '/',
'uses' => '[email protected]'
]);
Route::resource('product', 'ProductController');
ProductController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use DB;
use App\Product;
use resources\views\products;
class ProductController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$product = DB::select('select * from feedback');
return view('products.index')
->with('product',$product);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('products.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
/*$rating = new Product;
$rating->Name= $request->name;
$rating->avg=$request->price;
$rating->save();*/
$inputs= $request->all();
$product= Product::create($inputs);
//return redirect()->route('product.index');
return redirect()->action('[email protected]');
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$product= Product::where('idoveralRating',$id)->first();
//return $product;
return view('products.show')
->with('product',$product);
}
/**
* 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)
{
//echo '<script>console.log("bitch")</script>';
//Product::destroy($id);
$product= Product::where('idoveralRating',$id)
->delete();
return redirect()->route('product.show');
}
}
show.blade.php
@extends('layouts.layout')
@section('Head')
<h1>{{$product}}</h1>
@stop
@section('Body')
<h1>{{$product->Name}}</h1>
{!!Form::open([
'method' => 'delete',
'route'=> array('product.destroy',$product->id),
])!!}
{!!Form::submit('Delete')!!}
{!!Form::close()!!}
@stop
index.blade.php
@extends('layouts.layout')
@section('Head')
ALL Product
@stop
@section('Body')
@foreach($product as $col)
<h1>{{$col->Name}}</h1>
@endforeach
@stop
layout.blade.php
<!DOCTYPE html>
<html>
<head>
@yield('Head')
</head>
<body>
@yield('Body')
</body>
</html>
好了,所以我试着删除我的数据库基于我的数据库ID,我在我的浏览器链接上键入(所以让我说我类型的产品/ 1),这意味着我想删除我的我的数据库ID为1.
到目前为止,我已经实现的是,我能够显示我的数据库基于id我键入但不知何故,当我想在ProductController类中将id路由到我的销毁方法,它显示method =>'delete'不允许,我做错了什么?
运行'PHP工匠路线:list',你看在此列表中名称为'product.destroy'的路线? –
@AlexeyMezenin运行的命令,它显示了有product.destroy – Kevin