Laravel:找不到类"Auth" [英] Laravel: Class 'Auth' not found
本文介绍了Laravel:找不到类"Auth"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用laravel创建一个具有针对用户和帖子的CRUD功能的网站.该部分已完成. 之后,我做了一个寄存器功能,那也行得通.
I'm making a site with laravel that has a CRUD functie for Users and posts. That part is completed. After that I made a register function, that also worked.
但是当我尝试创建登录页面时,有些错误. 选择登录"按钮后,将显示一个错误页面,显示以下错误: 未找到验证"类
But when I tried to make a Login page some is wrong. As soon as I select the, "login"-button a error page shows up with the error: Class 'Auth' not found
我的UserController:
My UserController:
<?php
class UserController extends BaseController {
protected $layout = "layouts.main";
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
// get all the users
$users = User::all();
// load the view and pass the users
return View::make('users.index') ->with('users', $users);
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
// load the create form (app/views/users/create.blade.php)
return View::make('users.create');
}
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$rules = array(
'email' => 'required|email|unique:users',
'password' => 'required|min:8'
);
$validator = Validator::make(Input::all(), $rules);
// process the login
if($validator->fails()) {
return Redirect::to('users/create')
->withErrors($validator)
->withInput(Input::except('password'));
}else{
//store
$user = new User;
$user->email = Input::get('email');
$user->password = Input::get('password');
$user->save();
// redirect
Session::flash('message', 'Successfully created User!');
return Redirect::to('users');
}
}
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
// get the User
$user = User::find($id);
// show the view and pass the user to it
return View::make('users.show') ->with('user', $user);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
// get the user
$user = User::find($id);
// show the edit form and pass the User
return View::make('users.edit') -> with('user', $user);
}
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
$rules = array(
'email' => 'required|email',
'password' => 'required|min:8'
);
$validator = Validator::make(Input::all(), $rules);
// process the login
if($validator->fails()) {
return Redirect::to('users/' . $id . '/edit')
->withErrors($validator)
->withInput(Input::except('password'));
}else{
//store
$user = User::find($id);
$user->email = Input::get('email');
$user->password = Input::get('password');
$user->save();
// redirect
Session::flash('message', 'Successfully updated User!');
return Redirect::to('users');
}
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
// delete
$user = User::find($id);
$user->delete();
// redirect
Session::flash('message', 'Successfully deleted the User!');
return Redirect::to('users');
}
//dit is toegevoegd
public function getRegister() {
$this->layout = View::make('login.register');
}
public function postCreate() {
$validator = Validator::make(Input::all(), User::$rules);
if ($validator->passes()) {
// validation has passed, save user in DB
$user = new User;
$user->email = Input::get('email');
$user->password = Hash::make(Input::get('password'));
$user->save();
return Redirect::to('login/login')->with('message', 'Thanks for registering!');
} else {
// validation has failed, display error messages
return Redirect::to('login/register')->with('message', 'The following errors occurred')->withErrors($validator)->withInput();
}
}
public function __construct() {
$this->beforeFilter('csrf', array('on'=>'post'));
$this->beforeFilter('auth', array('only'=>array('getDashboard')));
}
public function getLogin() {
$this->layout = View::make('login.login');
}
public function postSignin() {
$user = array('email'=>Input::get('email'), 'password'=>Input::get('password'));
if (Auth::attempt($user)) {
return Redirect::to('login/dashboard')->with('message', 'You are now logged in!');
} else {
return Redirect::to('login/login')
->with('message', 'Your username/password combination was incorrect')
->withInput();
}
}
public function getDashboard() {
$this->layout = View::make('login.dashboard');
}
}
我的Login.blade.php:
My Login.blade.php:
@include('header')
<h1>Login page</h1>
{{ Form::open(array('url'=>'login/signin', 'class'=>'form-signin')) }}
<h2 class="form-signin-heading">Please Login</h2>
{{ Form::text('email', null, array('class'=>'input-block-level', 'placeholder'=>'Email Address')) }}
{{ Form::password('password', array('class'=>'input-block-level', 'placeholder'=>'Password')) }}
<br><br>
{{ Form::submit('Login', array('class'=>'btn btn-large btn-primary btn- block'))}}
{{ Form::close() }}
@include('footer')
我的路线:
<?php
Route::get('home', function()
{
return View::make('home');
});
Route::get('/', function()
{
return View::make('home');
});
Route::resource('users', 'UserController');
Route::resource('posts', 'PostController');
Route::controller('login', 'UserController');
有人可以帮助我吗?
推荐答案
您需要添加use Auth;
或使用\Auth::
这篇关于Laravel:找不到类"Auth"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文