Newbie to Laravel 5.4. Not sure where my error is. I created a logout button for signed-in users. My logout throws an error: MethodNotAllowedHttpException
in RouteCollection.php line 251. I have a logout function in the Login Controller (Controller>Auth>LoginController.php
) and a post route in web.php. What am I missing? Click here to see image of MethodNotAllowedHttpException full error message
Navbar
<div>
@if(!Session::has('id'))
<li> <a href="">Sign in |</a></li>
<li><a href="#"> Join </a></li>
@else
<li><a href="">Sign Out</a></li>
@endif
</div>
Controllers>Auth>LoginController.php
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/profile';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function logout(Request $request) {
Auth::logout();
return redirect('/home');
}
}
web.php
Route::group(['middleware' => ['web']], function () {
Route::post('/signup', [
'uses' => 'UserController@user_register',
'as' => 'signup',
]);
Route::get('/profile', [
'uses' => 'UserController@getProfile',
'as' => 'profile',
]);
Route::post('/logout', [
'uses' => 'LoginController@logout',
'as' => 'logout',
]);
});
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire