我正在处理简单的laravel项目,其中用户有一个注册页面。为此我使用了两个方法register(get方法)和postregister(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' );
}
获取方法工作正常。但是在提交表单后,post方法不会调用。我试过打印dd(" hii")但没有显示。有人能帮助我吗?
@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 :(得分:0)
正常情况下,没有中间件,
路线:
Route::post ( '/register', 'LoginController@postregister' );
在视图中:
<form action="{{ URL::to('/register') }}" method="post"></form>
在LoginController中:
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() }}">
试试这个。祝你好运。