0
我正在採用laracast - Jefferies視頻的形式和我的代碼是非常基本的,但我對框架的知識也是如此。我的代碼在下面,如果你沒有猜測,你的看法是我想創建一個值列表存儲在數據庫中,並將用戶重定向到新存儲的值。 「商店」部分似乎是問題的領域。每當我點擊「添加食品」我沒有重定向,但出現此錯誤,MethodNotAllowedHttpException。Larval MethodNotAllowedHttpException正在拋出
```
Route::get('food/create', '[email protected]');
ROute::post('fond/post', '[email protected]');
Route::get('food/{id}', '[email protected]');
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Food;
class FoodController extends Controller
{
public function index($id) {
$food = Food::find($id);
return view('index')->with('food', $food);
}
public function create() {
return view('vendor.create');
}
public function store(Request $request) {
$input = Request->all();
$food = Food::create($input);
return redirect('food/'.$food->id);
}
}
@extends('app')
@section('body')
<h1>Foods!</h1>
<h2>{{ $food->vegetables }}</h2>
<h2>{{ $food->fruit }}</h2>
<h2>{{ $food->grains }}</h2>
<h2>{{ $food->meat }}</h2>
<h2>{{ $food->sugar }}</h2>
@stop('body')
@extends('app')
@section('body')
{!! Form::open(['url'=>'food/store']) !!}
<div class="form-group">
{!! Form::label('vegetables', 'Vegetable item:') !!}
{!! Form::text('vegetables', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('fruit', 'Fruit item:') !!}
{!! Form::text('fruit', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('meat', 'Meat item:') !!}
{!! Form::text('meat', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('grains', 'Grain item:') !!}
{!! Form::text('grains', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('sugar', 'Sugar item:') !!}
{!! Form::text('sugar', null, ['class' => 'form-control']) !!}
</div>
<div>
{!! Form::submit('Add Food items', ['class' => 'btn btn-primary form-control']) !!}
{!! Form::close() !!}
</div>
@stop('body')
```
不應該''路線:: post('food/post','FoodController @store');'? –
我只是固定了0路線和食品/商店食品/郵政和愚蠢的喜歡食物。似乎又出現了一個錯誤。非靜態方法Illuminate \ Http \ Request :: all()不應被靜態調用,假設$ this來自不兼容的上下文@MarkDavidson –
@SethWarner Request-> all();'應該是'$ request-> all() ;'。 – patricus