我在Laravel中创建了一个自定义登录系统。
这是我的控制器:
<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Support\Facades\Auth;
class Front extends Controller
{
public function register()
{
if (Request::isMethod('post')) {
User::create([
'name' => Request::get('name'),
'email' => Request::get('email'),
'password' => bcrypt(Request::get('password')),
]);
}
return Redirect::away('login');
}
public function authenticate()
{
if (Auth::attempt(['email' => Request::get('email'), 'password' => Request::get('password')])) {
return redirect()->intended('checkout');
} else {
return view('login', array('title' => 'Welcome', 'description' => '', 'page' => 'home'));
}
}
public function login()
{
return view('auth/login', array('page' => 'home'));
}
public function checkout()
{
return view('/aboutme', array('page' => 'home'));
}
}
路线是:
// Authentication routes...
Route::get('auth/login', 'Front@login');
Route::post('auth/login', 'Front@authenticate');
Route::get('auth/logout', 'Front@logout');
// Registration routes...
Route::post('/register', 'Front@register');
Route::get('/checkout', [
'middleware' => 'auth',
'uses' => 'Front@checkout'
]);
我得到的错误是:
Front.php第12行中的FatalErrorException:Class &#39;应用程序\ HTTP \控制器\请求&#39;找不到
答案 0 :(得分:0)
您需要导入请求。将其添加到控制器的顶部:
use Request;
顺便说一下,您还需要为Redirect
外观执行此操作。
您的导入应如下所示:
use Auth;
use Request;
use Redirect;
use App\Http\Controllers\Controller;
答案 1 :(得分:0)
请尝试以下操作,因为您似乎没有在Front Controller
中使用特定于请求的命名空间:
use Illuminate\Http\Request;