I have this protected route to be accessed only when the user is authenticated:
Route::get('/checkout', [
'middleware' => 'auth',
'uses' => 'Front@checkout'
]);
and the other routes are:
// 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');
And my controller is:
<?php
namespace App\Http\Controllers;
use Request;
use Redirect;
use App\User;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Controller;
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('auth/login');
}
public function authenticate() {
if (Auth::attempt(['email' => Request::get('email'), 'password' => Request::get('password')])) {
return redirect()->intended('/checkout');
} else {
return view('auth/loginerror', array('title' => 'Welcome', 'description' => '', 'page' => 'home'));
}
}
public function login() {
return view('auth/login', array('page' => 'home'));
}
public function checkout() {
return view('contactme', array('page' => 'home'));
}
public function logout() {
Auth::logout();
return Redirect::away('auth/login');
}
}
there is a error with the route:
NotFoundHttpException in RouteCollection.php line 161:
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire