根着视频做的,到5:08秒 提交贴子,出现以下错误:
MethodNotAllowedHttpException in RouteCollection.php line 219:
以下是代码部分:
1.routes.php
<?php
Route::get('/', 'PostsController@index');
Route::resource('discussions', 'PostsController');
Route::get('/user/register', 'UsersController@register');
Route::get('/user/login', 'UsersController@login');
Route::get('/verify/{confirm_code}', 'UsersController@confirmEmail');
Route::post('/user/register', 'UsersController@store');
Route::post('/user/login', 'UsersController@signin');
2.PostsController.php
public function store(Requests\StoreBlogPostRequest $request)
{
$data = [
'user_id' => \Auth::user()->id,
'last_user_id' => \Auth::user()->id
];
$discussion = Discussion::create(array_merge($request->all(),$data));
return redirect()->action('PostsController@show',['id'=>$discussion->id]);
}
3.Discussion.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Discussion extends Model
{
//
protected $fillable = ['title', 'body', 'user_id', 'last_user_id'];
public function user()
{
return $this->belongsTo(User::class);//$discussion->user
}
}
4.StoreBlogPostRequest.php
<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
class StoreBlogPostRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'title'=>'required',
'body'=>'required'
];
}
}
5.create.blade.php
@extends('app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2" role="main">
{!! Form::open(['url'=>'/discussions']) !!}
<div class="form-group">
{!! Form::label('title', 'Title:') !!}
{!! Form::text('title',null,['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('body', 'Body:') !!}
{!! Form::textarea('body',null,['class'=>'form-control']) !!}
</div>
<div>
{!! Form::submit('发表贴子',['class'=>'btn btn-primary pull-right']) !!}
</div>
{!! Form::close() !!}
</div>
</div>
</div>
@stop
如何解决?