I am running the latest Laravel 5.3 version, and after running php artisan make:auth, I attempt to logout within the application and it returns this error: MethodNotAllowedHttpException.
Web.php (routes file):
Route::get('/', function () {
return view('welcome');
});
Route::auth();
Auth::routes();
Route::get('/home', 'ClinicController#index');
I can see that the views have been created, but why is it returning this error? Many thanks in advance
In Laravel 5.3 /logout route is assigned to method POST, so to log out you have to create form and submit it.
<form action="{{ route('/logout') }}" method="post">
{!! csrf_field() !!}
<button type="submit">Logout</button>
</form>
You can just manually and follow line to your web/routes.php file:
Route::get('/logout', 'Auth\LoginController#logout');
Related
i replace my web.php whit this code, same as my code in laravel 5.2, now im using laravel 5.5, i dont have any errors in 5.2 version.
Route::get('/home', function () {
return view('home');
});
Route::get('/register', 'registerController#index');
Route::post('/register', 'registerController#register');
Route::get('/signin', 'signinController#index');
Route::post('/login', 'signinController#login');
Route::get('/logout', ['uses'=>'signinController#logout'])->middleware('auth');
Route::get('/profile', ['uses'=>'profileController#index'])->middleware('auth');
Route::get('/updateprofile', ['uses'=>'profileController#updateprofile'])->middleware('auth');
Route::post('/updateprofile', ['uses'=>'profileController#updateprofilesave'])->middleware('auth');
Route::post('/updateprofiles', ['uses'=>'profileController#updatechannelart'])->middleware('auth');
Route::get('/changepassword', ['uses'=>'profileController#indexpassword'])->middleware('auth');
Route::post('/changepassword', ['uses'=>'profileController#changepassword'])->middleware('auth');
Route::get('/article', 'articleController#index');
Route::get('/searchuser', ['uses'=>'searchController#index']); //Untuk searching user
Route::get('/searchuserpage', ['uses'=>'searchController#searchuser']); //searching user jquery
Route::get('/photos', ['uses'=>'documentationController#indexphoto'])->middleware('auth');
then i try to access url /profile which means need authenticate first, and it show me an error InvalidArgumentException Route [login] not defined. how to solve this problem. thankyou
this is my code for Authenticate.php
public function handle($request, Closure $next)
{
if(Auth::Check()){
return $next($request);
}
else{
return redirect('/signin');
}
}
The issue comes from the fact that somewhere in your code upon instantiation you're referring to a named route called 'login' but it's not defined in your web.php file.
An example of hitting this issue is you may have a redirect pointing to this route somewhere tucked away in one of your controllers, for example:
return redirect()->route('login');
To fix this issue, apply the name to the applicable route.
Route::post('/login', 'signinController#login')->name('login');
when you call a route in your project you must define route name .
such as :
<form action:"{{route('login')}}" method="post">
and in route :
Route::post('/signin', 'signinController#index')->name('login')
This is issue with the named routes. Please make sure which all places the named routes is being used.
Route::get('/signin', 'signinController#index')->name('login')
Here, you can see I named this route login and I can call this route anywhere using route('login') helper method.
# {{ post.user.name }}
is the line which is creating the error, it is supposed to link to the profile of the user
simply doing
<h2>#{{ post.user.profileUrl }}</h2>
is giving the right address, and typing out that address is also taking me to the right page, but with that link it is giving the error
route files
Route::get('/', function () {
return view('auth/login');
});
Route::auth();
Route::get('/home', 'HomeController#index');
Route::post('/posts', 'PostController#create');
Route::get('users/{user}', 'UserController#index')->name('user.index');
Anyone please help...
On your route/web.php:
Route::get('/post/user/profile', 'PostUserController#profile')->name('post.user.profile');
And then in your view:
Profile
Ps. I went as simple as possible, because the way I've used the routes here doesn't make much sense for me.
im adding csrf_field to all my forms by default and it was working fine , i decided to store some data in session so i've grouped some routes and used web middlewar on them
Route::group(['middleware' => ['category' , 'web']], function () {
Route::get('/', 'HomeController#index');
Route::get('/dashboard', 'DashboardController#index')->name('dashboard');
})
now when i submit a form i get this error
TokenMismatchException in VerifyCsrfToken.php line 67:
but they work fine if i remove web middleware !!
im using database drive for my sessions ... i dont know if that's relevant
Remove web middleware, that should fix the problem.
Since 5.2.27 web middleware applies automatically to all routes (in 5.3 to all routes in routes/web.php) and you shouldn't add it manually.
If the form is not token field _token
<form method="POST" action="">
{{ csrf_field() }}
...
</form>
I have a form that looks like this:
<form method="POST" action="{{ route('flyers.store') }}" enctype="multipart/form-data" class="col-md-6">
#include('flyers.form')
</form>
Throughout the entirety of the project, this worked. It would post to my local development url http://projectflyer.dev:8000/flyers.
Suddenly it's posting to http://projectflyer.dev/flyers.
I'm not sure what would cause this. Any suggestions?
Another interesting development: When I type http://projectflyer.dev:8000/flyers directly into the browser, it redirects to http://projectflyer.dev/flyers.
Routes file looks like:
<?php
Route::group(['middleware' => ['web']], function () {
Route::get('/', function () {
return view('pages.home');
});
Route::resource('flyers', 'FlyersController');
Route::get('{zip}/{street}', 'FlyersController#show');
Route::post('{zip}/{street}/photos', ['as' =>'store_photo_path', 'uses' => 'FlyersController#addPhoto']);
});
This happens as a result of having a route post to 'flyers' when also having a public directory called 'flyers'.
I'm trying to make a simple post through a form, the route exists and the token is there, but when a submit is made always returns '404 Not Found'.
Route:
Route::group(['middleware' => ['web']], function () {
Route::post('/cadastro', 'UsuarioPost#cadastro');
});
UsuarioPost Controller:
class UsuarioPost extends Controller
{
public function cadastro(Request $request)
{
return dd($_POST);
}
}
View with the form:
<form id="f_cadastro" method="POST" action="{{ URL::to('/cadastro') }}">
{{ csrf_field() }}
<button type="submit">Cadastrar</button>
</form>
Is there something new from laravel 5.1 to 5.2 in form submiting?
This used to work fine in the previus version, even without the group in the route.
I suggest you to use named routes instead of this strategy, is more convenient.
Route::get('/profile', [
'as' => 'profile.index',
'uses' => 'ProfileController#index',
]);
And then you can generate the url from your views or codes using only
{{ route('profile.index') }}
So, finally working.
The deal was with apache, and not laravel. Apaches httpd.conf file (apaches directory/conf/httpd.conf) had AllowOverride disabled as default, wich is needed by laravel. So I had to change every single "AllowOverride none" for "AllowOverride all", and removed the line "Require all denied".
Having my apache DocumentRoot already set to the public folder from my project everthing worked fine.