2016-03-30 36 views
4

我正在使用簡單的laravel項目,其中用戶有一個註冊頁面。爲此,我使用了兩種方法註冊(get method)和postregister(post method)。 我的代碼:laravel post不工作​​

public function register() { 

    return view ('auth/register'); 
} 
public function postregister(Request $req) { 

dd("sowmya"); 
    $user = new User(); 
    $user->name = $req->get ('username'); 
    $user->email = $req->get ('email'); 
    dd($user); 
    $user->password = Hash::make ($req->get ('password')); 
    $user->remember_token = $req->get ('_token'); 

    $user->save(); 

    return redirect ('/login'); 
} 

GET方法提交表單的POST方法是不是calling.even我試圖與印刷DD(「HII」),但不顯示後工作fine.But。有人能幫我嗎?

  @extends('layout') @section('content')<style> 
      <style> 
      nav { 
       visibility: hidden; 
      } 
      </style> 
     <h3 style="margin-top: 70px;" align="center">Signup Page</h3> 

     <div class="container"> 
       <div class="row"> 
       <div class="register is-Responsive" 
        style="background-color: rgba(0, 0, 0, 0.3)"> 
      <div id="logo-container"></div> 
      <div class="col-sm-12 col-md-10 col-md-offset-1"> 
      <form action="/register" id="loginForm" method="post"> 
       @if (count($errors) > 0) 
       <div class="alert alert-danger"> 
        <ul> 
         @foreach ($errors->all() as $error) 
         <li>{{ $error }}</li> @endforeach 
        </ul> 
       </div> 
       @endif {!! csrf_field() !!} 
       <div class="form-group input-group"> 
        <span class="input-group-addon"><i class="fa fa-user"></i></i></span> 
        <input class="form-control" type="text" name='username' 
         placeholder="username" /> 
       </div> 

       <div class="form-group input-group"> 
        <span class="input-group-addon"><i class="fa fa-envelope"></i></span> 
        <input class="form-control" type="email" name='email' 
         placeholder="email" /> 
       </div> 
       <div class="form-group input-group"> 
        <span class="input-group-addon"><i class="fa fa-key"></i></span> <input 
         class="form-control" type="password" name='password' 
         placeholder="password" /> 
       </div> 
       <div class="form-group input-group"> 
        <span class="input-group-addon"><i class="fa fa-key"></i></span> <input 
         class="form-control" type="password" name='password_confirmation' 
         placeholder="confirm password" /> 
       </div> 
       <div class="checkbox"> 
        <label> <input type="checkbox"> I agree to the <a href="#">Terms 
          and Conditions</a> 
        </label> 
       </div> 
       <div class="form-group"> 
        <button type="submit" class="btn btn-def btn-block">Signup</button> 
       </div> 

      </form> 
     </div> 
    </div> 
</div> 

@endsection

+0

您是否在發送請求期間在您的表單中發送了csrf? –

+0

你是否也可以發佈你的HTML代碼... –

+0

你的路線是什麼? –

回答

0

在正常情況下,沒有中間件,

途徑:

Route::post ('/register', '[email protected]'); 

鑑於:

<form action="{{ URL::to('/register') }}" method="post"></form> 

在LoginCo ntroller:

public function postregister(Request $req) 
{ 
print_r("Came here");die; 
} 

更改按鈕標籤輸入:

<input type="submit" value="Submit" class="btn btn-def btn-block"></input> 

添加這個表單裏面:

<input type="hidden" name="_token" value="{{ csrf_token() }}"> 

試試運氣this.Good。

+0

thnku ...但我試着用這個...相同的代碼工作before.suddenly它不是工作從過去3天...我不知道什麼問題是.. –

+0

任何錯誤消息,你是得到些什麼? – Sunil

+0

不......當我提交表單時..user不保存在分貝..以及憑據在url中顯示爲get方法 –