【问题标题】:MethodNotAllowedHttpException in RouteCollection.php line 219 error laravel:RouteCollection.php 第 219 行错误 laravel 中的 MethodNotAllowedHttpException:
【发布时间】:2016-03-18 12:39:39
【问题描述】:

当我尝试访问登录后路由时出现此错误。我是 laravel 的新手,我似乎无法弄清楚如何解决这个错误。请帮忙。

我的路线.php

 Route::group(['middleware' => ['web']], function () {
 Route::get('/', [
'uses'=>'\ocsaf\Http\Controllers\HomeController@index',
'as'=>'home',
 ]);



/*
  *Authentication
 */

Route::get('/signup', [
 'uses'=>'\ocsaf\Http\Controllers\AuthController@getSignUp',
 'as'=>'auth.signup',
 'middleware' => ['guest'],
 ]);

 Route::post('/signup', [
 'uses'=>'\ocsaf\Http\Controllers\AuthController@postSignUp',
 'middleware' => ['guest'],
 ]);

 Route::get('/signin', [
 'uses'=>'\ocsaf\Http\Controllers\AuthController@getSignIn',
 'as'=>'auth.signin',
 'middleware' => ['guest'],
 ]);

 Route::post('/signup', [
 'uses'=>'\ocsaf\Http\Controllers\AuthController@postSignIn',
 'middleware' => ['guest'],
 ]);

  Route::get('/signout', [
 'uses'=>'\ocsaf\Http\Controllers\AuthController@getSignOut',
 'as'=>'auth.signout',
  ]);


 /*
 *search
 */

  Route::get('/search', [
  'uses'=>'\ocsaf\Http\Controllers\SearchController@getResults',
  'as'=>'search.results',
  ]);



  /*
  *Profile
  */

   Route::get('/user/{username}', [
   'uses'=>'\ocsaf\Http\Controllers\ProfileController@getProfile',
   'as'=>'profile.index',
   ]);

   Route::get('/profile/edit', [
   'uses'=>'\ocsaf\Http\Controllers\ProfileController@getEdit',
   'as'=>'profile.edit',
   'middleware'=>['auth'],
   ]);

   Route::post('/profile/edit', [
   'uses'=>'\ocsaf\Http\Controllers\ProfileController@postEdit',
   'as'=>'profile.edit',
   'middleware'=>['auth'],
   ]);

   Route::post('/profile/edit', [
   'uses'=>'\ocsaf\Http\Controllers\StatusController@postStatus',
   'as'=>'status.post',
   'middleware'=>['auth'],
   ]);

   });

AuthController.php

    namespace ocsaf\Http\Controllers;
    use Auth;
   use Illuminate\Http\Request;
   use ocsaf\Models\User;



  class AuthController extends Controller
  {

  public function getSignUp()
  {
  return view('auth.signup');
  }

public function postSignUp(Request $request)
{
$this->validate($request, [
'email' => 'required|unique:users|email|max:255',
'username' => 'required|unique:users|alpha_dash|max:255',
'password' => 'required|min:6',


 ]);
 User::create([
    'email' => $request-> input('email'),
    'username' => $request-> input('username'),
    'password' => bcrypt($request -> input('password')),
 ]);

  return redirect()
  ->route('home')
  ->with('info', 'You have signed up, Please sign in!');
   }

  public function getSignIn()
  {
  return view('auth.signin');
  }

  public function postSignIn(Request $request)
  {
  $this->validate($request, [
  'email' => 'required',
  'password' => 'required',

  ]);

  if(!Auth::attempt($request -> only(['email', 'password' ]), 
  $request ->         has('remember'))){
    return redirect() ->back()->
 with('info', 'could not sign you in with those   details   ');
 }

 return redirect() ->route('home')->with('info', 'You are now signed in');

 }

 }

我的 signin.blade.php 表单声明

    <form class="form-vertical" role = "form" 
    method = "post" action = "{{     route('auth.signin'); }}">

【问题讨论】:

  • 您说您正在尝试访问“登录后路由”,但您拥有的唯一 signin 路由是用于 GET 请求,而不是 POST。

标签: php laravel routes


【解决方案1】:

您的表单方法是post,但对于路由auth.signin,HTTP 动词是get

【讨论】:

  • 我修复了这个问题,但它没有进行身份验证或进入主页。它也不会修改数据库。
  • 你做了什么改变?你改变了表单方法吗?
  • 不,我将路由获取方法更改为 post 登录方法。我认为我的 AuthController.php postSignIn 方法可能有问题。
猜你喜欢
  • 2016-06-28
  • 2016-08-30
  • 2016-06-15
  • 2016-06-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-12
相关资源
最近更新 更多