MethodNotAllowedHttpException Laravel 5.2 - php

Hey so I'm getting this weird error
MethodNotAllowedHttpException
I cannot find a solution anyway on the internet, any advice please?
Here it is:
Route::post('api/avatarDetails/{avId}', 'API\APIController#doAvatarDetails');
Route::get('api/avatarDetails', function() {
return Redirect::to('/')->with('failure', 'You lack the ability to do that young one.');
});
There you go #Alexy
Route::get('/', function() {
return view('welcome');
});

I don't see this route, but you still trying to redirect to it:
Route::get('/', function () {
//
});
If you have one, run php artisan route:clear command which will clear all old route cache.

Related

Laravel routes dont show

I am completely new to laravel, so I think my question is a bit ridiculous.
I tried to create a route in the routes/web.php
Route::get('/example', function () {
Return ('hello');
)};
But when I try to see the example page, I receive 404.
I use php artisan serve to load the local host.
I couldn't find a solution relatable to my situation. Still no luck.
Windows version 8.1
Laravel version 8
Also I can't edit
Route::get('/', function () {
Return view ('welcome');
});
The changes won't apply
Thank you
You can type php artisan route:list to see if the route saved or not, if not you can write :
php artisan optimize:clear
Your syntax is not correct.
Route::get('/example', function () {
Return view('hello');
});
Make your hello.blade.php file add your html code that is your view file.run command php artisan route:clear.
you must use:
php artisan:serve
then
your_app_url/example
and edit web.php -- you have syntax error in web.php
Route::get('/example', function () {
return 'hello';
});

Can i use Route::get('/') normally on Laravel?

I have a Laravel 8 project. Everything work fine except the code below
Route::get('/', function ()
{
return redirect('/login');
});
Those code only run when i clear the route cache with php artisan route:clear or it will return this error everytime after i cache route:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The GET method is not supported for this route. Supported methods: HEAD.
I want my users can go to login page despite of they access the http://localhost/myproject/public/ or http://localhost/myproject/public/login
If anyone have the answer, pleas help me. Thank you!
enter image description here
1.Add this at the top of your web.php use Illuminate\Support\Facades\Route;
2.
Route::get('/greeting', function () {
return 'Hello World';
});
Routing Laravel

Laravel 8 default root route not working after route:cache

Getting this error when accessing default '/' route on laravel 8 after doing route:cache
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException The GET method is not supported for this route. Supported methods: HEAD.
Any idea why? all routes except this one is working :D
Route::get('/', function () {
return view('welcome');
});
Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
return view('dashboard');
})->name('dashboard');
even api.php route is working.
can't find any solution online.
Thank you

How should I set up Laravel routes?

I'm a beginner in Laravel and I'm having some difficulties with routes. Actually, I'm having difficulties with a lot of things in Laravel, some of which I've managed to wrap my head around (such as migrations, seeding and authentication) but this is one of the most basic ones.
I've been creating routes based on the one that comes with Laravel. However, after much googling, something seems off. I'm not sure this is how it should be done.
My current web.php file looks like this:
Route::get('/', function () {
return view('pages.home');
});
Route::get('/about', function () {
return view('pages.about');
});
Route::get('/login', function () {
return view('login');
});
Route::get('/student', function () {
return view('profiles.student');
});
Route::get('/professor', function () {
return view('profiles.prof');
});
Route::get('/profadmin', function () {
return view('profiles.profadmin');
});
Route::get('/ident', function () {
return view('pages.ident');
});
// Authentication
Auth::routes();
Route::post('/login', function () {
return view('pages.ident');
});
Route::get('logout', 'Auth\LoginController#logout');
// Route::get('/home', 'HomeController#index')->name('home');
// Route::get('/ident', 'HomeController#ident')->name('ident');
//
// Route::get('/aluno', 'HomeController#aluno')->name('aluno');
//
// Route::get('/ident', 'HomeController#ident')->name('ident');
Also, certain pages should only be viewed by authenticated users and I'm having a hard time understanding how exactly that is done and how the routes should reflect that.
I'm sorry if this is simple stuff, but this is my first time using a PHP framework. Any help will be much appreciated.
lets suppose you want to protect the about route
then in the web.php file, replace your about route with this:
Route::get('/about', function () {
return view('pages.about');
})->middleware('auth');
now anyone hits /about and not logged in, it will be redirected to /login
if you want to know more about authentication, Laravel documentation really the best place for you:
https://laravel.com/docs/5.5/authentication#protecting-routes
First if you are beginner you should read Laravel documentation & Laracasts
In your routes you trying to show only views
Route::get('/about', function () {
return view('pages.about');
});
In Laravel 5.6 you can do it like this
Route::view('/about', 'viewName');

Laravel NotFoundHttpException on all routes

It's laravel version 5.4 and I'm using api.php routes. Following is one of my route in it:
Route::group(['namespace' => 'Api'], function() {
Route::get('auth/test',function(){
return "asd";
});
});
it's giving error on all routes even if I write route in web.php, it's not even loading home page:
http://localhost/bradforduniversityproject/public/
I have run following command too:
php artisan route:clear
nothing is working just giving NotFoundHttpException whatever i write in URL. Any help what could be the reason. thanks!
Following is my api.php file:
Route::group(['namespace' => 'Api'], function() {
Route::get('auth/test2',function(){
return "asd";
});
Route::post('auth/test','Auth\LoginController#test');
Route::post('auth/login','Auth\LoginController#login');
Route::post('auth/register','Auth\LoginController#register');
Route::post('auth/forgotPassword','Auth\LoginController#forgotPassword');
});

Categories