2017-05-27 54 views
0

我的問題是我應該如何連接的東西來返回視圖? 所有的時間得到了這樣的錯誤:如何在這種情況下返回從laravel控制器的視圖

MethodNotAllowedHttpException在RouteCollection.php線251

下面你可以檢查我在哪裏:

web.php

Route::post('registered', '[email protected]_view')->name('registration.registered'); 

AuthController。 php

public function store_view(Request $request) 
{ 
    $this->validate($request, [ 
     'name' => 'required', 
     'email' => 'required|email', 
     'password' => 'required|min:5' 
    ]); 

    $name = $request->input('name'); 
    $email = $request->input('email'); 
    $password = $request->input('password'); 

    $user = new User([ 
     'name' => $name, 
     'email' => $email, 
     'password' => bcrypt($password) 
    ]); 

    if ($user->save()) { 
     $user->signin = [ 
      'href' => 'api/v1/user/signin', 
      'method' => 'POST', 
      'params' => 'email, password' 
     ]; 
     $response = [ 
      'msg' => 'User created', 
      'user' => $user 
     ]; 
     return view('registration.registered')->with('response',$response); 
    } 

    $response = [ 
     'msg' => 'An error occurred' 
    ]; 

    return view('registration.registered')->with('response',$response); 
} 

regist er.blade.php

<div class="container" style="margin-top:40px"> 
    <div class="row"> 
     <div class="col-sm-6 col-md-4 col-md-offset-4"> 
      <div class="panel panel-default"> 
       <div class="panel-heading"> 
        <strong> Register to continue!</strong> 
       </div> 
       <div class="panel-body"> 
        <form role="form" action="{{-- {{ url('/api/v1/user') }} --}}" method="POST"> 
        {{ csrf_field() }} 
         <fieldset> 

          <div class="row"> 
           <div class="center-block"> 
            <img class="profile-img" 
             src="{{ URL::to('img/key.png') }}" alt="key"> 
           </div> 
          </div> 

          <div class="row"> 
           <div class="col-sm-12 col-md-10 col-md-offset-1 "> 

            <div class="form-group"> 
             <div class="input-group"> 
              <span class="input-group-addon"> 
               <i class="glyphicon glyphicon-user"></i> 
              </span> 
              <input class="form-control" placeholder="Username" name="name" type="text" autofocus> 
             </div> 
            </div> 

            <div class="form-group"> 
             <div class="input-group"> 
              <span class="input-group-addon"> 
               <i class="glyphicon glyphicon-envelope"></i> 
              </span> 
              <input class="form-control" placeholder="E-mail" name="email" type="text"> 
             </div> 
            </div> 

            <div class="form-group"> 
             <div class="input-group"> 
              <span class="input-group-addon"> 
               <i class="glyphicon glyphicon-lock"></i> 
              </span> 
              <input class="form-control" placeholder="Password" name="password" type="password"> 
             </div> 
            </div> 

            <div class="form-group"> 
             <input type="submit" class="btn btn-lg btn-primary btn-block" value="Register"> 
            </div> 

           </div> 
          </div> 

         </fieldset> 
        </form> 
       </div> 
       <div class="panel-footer "> 
        Already have an account? <a href="{{route('sign.login')}}" onClick=""> Sign In Here! </a> 
       </div> 
      </div> 
     </div> 
    </div> 
</div> 

回答

0

在您的形式使用此,表單action屬性必須是你的名字路線:

<form role="form" action="{{route('registration.registered')}}" 
+0

謝謝@Alfredo他們! :) – r4nd3l8888