我的web.php
Route::get('/', ['as'=>'home', 'uses'=>'PagesController@home']);
Route::group(['prefix'=>'auth'], function(){
Route::get('register',[ 'as'=>'get_register',
'uses'=>'Auth\RegisterController@getRegister' ]);
Route::post('register',[ 'as'=>'post_register',
'uses'=>'Auth\RegisterController@postRegister' ]);
});
我的nav.blade.php
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">CodeHub</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="../navbar-static-top/">Log In</a></li>
<li>{!! link_to_route('get_register', 'Register') !!}</li> //To link my register button with route
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container-fluid -->
</nav>
我的register.php
@extends('layouts.masters.main')
@section('page-content')
<div class="container">
@includes('layouts.partials.nav')
<form class="form-signin">
<h2 class="form-signin-heading">Please sign in</h2>
<label for="inputEmail" class="sr-only">Email address</label>
<input type="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input type="password" id="inputPassword" class="form-control" placeholder="Password" required>
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me"> Remember me
</label>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
</div> <!-- /container -->
我的Register Controller
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use RegistersUsers;
/**
* Where to redirect users after login / registration.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6|confirmed',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
}
当我转到此网址not entirely transparent about it时,应该会显示注册表单,但我收到以下错误。
ReflectionException in Route.php line 333: Method App\Http\Controllers\Auth\RegisterController::getRegister() does not exist
任何人都可以帮助谢谢。我很难弄清楚我做错了什么。
答案 0 :(得分:1)
错误很明显:getRegister()
中没有Auth\RegisterController
方法。
如果您想使用Laravel auth脚手架,请删除路线并改为添加Auth::routes();
。