因此,我可以創建一個新的記錄在我的數據庫與窗體,但不知何故我無法刪除我的數據庫使用窗體而現在,我使用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