Displaying routes that do not exists - laravel

I am getting a really strange problem which I can't solve. Everything worked fine yesterday but today it does not. I am building an API and I have the following in my route file
Route::group(['prefix' => 'api'], function() {
Route::post('login', 'Auth\AuthController#login');
Route::group(['middleware' => ['jwt.auth']], function() {
Route::post('logout', 'Auth\AuthController#logout');
});
});
There are no other routes in my route file - I have double checked using vim via putty.
Anyway, if I visit the route of my url, I am shown the default Laravel 5 welcome page. Strange thing is, I have deleted welcome.blade.php from my server and it still displays!
If I try posting to my API route using Postman, where yesterday I was being returned a token, today I get
NotFoundHttpException in RouteCollection.php line 161
I have tried clearing caches without success.
Has anyone seen anything like this before? Or maybe knows what the problem could be?
Thanks

Related

Laravel any new routes suddenly stop working even though nothing has changed

I have had some weird issues in the past with Laravel routing, however they could usually be fixed with some form of logical solution, eg. clearing the route cache, or a genuine user error...
But this one is very strange. I have been developing this site for a few weeks and using the /admin routes for some time, but today anything related to /admin or logging in is resulting in a 404 | not found from Laravel. And now even adding any new routes is not working, including very basic ones.
eg. the home page is routed like this:
Route::get('/', [App\Http\Controllers\FrontendController::class, 'home'])->name('home');
But adding:
Route::get('/test', [App\Http\Controllers\FrontendController::class, 'home'])->name('test');
To my web.php routes is also bringing me to a 404.
Just to explain my development environment, I am on Windows and I have tried serving this with both "php artisan serve", and also with XAMPP, but both are giving me the same issue. I won't bother explaining the XAMPP set up, because this was literally working yesterday and nothing has changed, but with php artisan serve it takes me to "http://127.0.0.1:8000/".. this doesn't require any special hacking.. it usually just works.
What have I done differently today?
So all I have done today is:
Added a new command with "php artisan make:command SomeCommandIStartedMaking"
This surely hasn't screwed anything up? I've even deleted the command and reset to my last commit just in case and still the routes are screwed.
In my windows "hosts" file I added "127.0.0.1 somedomain.com"
So this sounds like the kind of thing that would have an effect on routing, and it's where I first noticed the issue.. but since then I have "ipconfig /flushdns", I have removed the entries from my host file, and I have cleared my laravel routes and caches, but still the issue remains.
I am really stuck on this one. Also finally! I have done a route:list and I can clearly see the routes showing up like expected, but I can assure you that nothing has changed since yesterday so this seems like another issue.
Here is a dump of web.php, because I know this will be asked for:
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
// Frontend
Route::get('/', [App\Http\Controllers\FrontendController::class, 'home'])->name('home');
Route::get('/instagram-gallery', [App\Http\Controllers\FrontendController::class, 'instagramGallery'])->name('instagram-gallery');
Route::get('/{pageAlias}', [App\Http\Controllers\PageController::class, 'index'])->name('page');
Route::post('/contact-send', [App\Http\Controllers\PageController::class, 'contactSend'])->name('contact-send');
Route::get('/test', [App\Http\Controllers\FrontendController::class, 'home'])->name('test');
// Admin
Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'is_admin']], function(){
Route::get('/', [App\Http\Controllers\AdminController::class, 'index'])->name('admin');
Route::get('/search/{table}', [App\Http\Controllers\AdminController::class, 'search'])->name("admin-search");
Route::get('/browse/{table}', [App\Http\Controllers\AdminController::class, 'browse'])->name("admin-browse");
Route::get('/create/{table}', [App\Http\Controllers\AdminController::class, 'create'])->name("admin-create");
Route::get('/edit/{table}/{id}', [App\Http\Controllers\AdminController::class, 'edit'])->name("admin-edit");
Route::get('/manage-account', [App\Http\Controllers\AdminController::class, 'manageAccount'])->name("admin-manage-account");
Route::get('/documentation/{subject?}', [App\Http\Controllers\AdminController::class, 'documentation'])->name("admin-documentation");
Route::post('/create/{table}/action', [App\Http\Controllers\AdminController::class, 'createAction'])->name("admin-create-action");
Route::post('/edit/{table}/{id}/action',[App\Http\Controllers\AdminController::class, 'editAction'])->name("admin-edit-action");
Route::post('/delete', [App\Http\Controllers\AdminController::class, 'deleteAction'])->name("admin-delete-action");
Route::post('/wysiwyg-upload', [App\Http\Controllers\AdminController::class, 'wysiwygUpload'])->name("wysiwyg-upload");
Route::post('/manage-account-action', [App\Http\Controllers\AdminController::class, 'manageAccountAction'])->name("admin-manage-account-action");
});
require __DIR__.'/auth.php';
One thing to add, is that "/contact" resolves just fine which is using the '/{pageAlias}' route as shown above, so some are working and some aren't. How should I trouble shoot this I don't even know where to start :(
Any help would be hot! This is so frustrating haha! Thanks in advance..
This might due to cache so run following commands
php aritsan config:clear
php artisan route:clear
To use single command:
PHP artisan optimize
The problem is the order of your routes - the code will run line by line trying to find a matching route.
Once it hits
Route::get('/{pageAlias}', [App\Http\Controllers\PageController::class, 'index'])->name('page');
It will match /test and naturally stop - never reaching your next route.
To solve this, your specific route /test needs to be defined before your general "catch-all" route /{pageAlias}

How to solve You don't have permission to access this resource. ubuntu Laravel?

I am working on laravel 8 and i am facing strange issue. Project was working fine 8 hour ago but now i am facing issue You don't have permission to access this resource. my route file is.
Route::get('language/{key}', [SwitchLanguageController::class, 'switchLanguage'])->name('language');
Route::get('register', [RegisterController::class, 'showRegistrationForm'])->name('register')->middleware(['otpVerify']);
Auth::routes();
Route::group(['middleware' => 'auth'], function (){
Route::get('/404', [\App\Http\Controllers\ErrorController::class, 'notFound'])->name('404');
Route::get('/', [DashboardController::class, 'index'])->name('dashboard');
Route::get('profile/show', [AuthenticationController::class, 'profile'])->name('profile.show');
Route::get('/invoices', [InvoiceController::class, 'index'])->name('invoice');
});
when i hit route http://www.ereciept.com/invoices/ on local server i face this issue.

Laravel 5.5 Route groups

I was having this in my website using Laravel 5.3 :
Route::group(['namespace' => 'Admin', 'prefix' => 'admin', 'middleware'=>'auth'], function(){
Route::resource('posts', 'PostsController');
});
This lets me go to the admin panel using: mywebsite/public/admin/posts.
Now, when I migrated the site to Laravel5.5 I got this error Route[admin.posts.create] not defined when i attempt to open the link Create post which was working fine before.
I know that routing system has changed but I did not know how to have such links in new Laravel5.5. I tried url instead of route but I got the same error. I also checked the new documentation but I did not get exactly how to have the same link system.
Can anyone have a better explanation of this new routing system? (I have to migrate the site to 5.5).
Laravel names resource routes by default, you can check them by running php artisan route:list
If you want to override them for any reason you can pass in an array when you define the route and override each individual route name like so:
Route::resource('posts', 'PostsController', ['names' => [
'create' => 'admin.posts.build'
]]);

New routes in Laravel are not working

I just tried to add a new route in Laravel but it seems it's not working, just getting 404 errors.
It only detects the index '/' route.
This code is in the routes/web.php
Route::get('/', 'SiteController#mainView')->name('home');
Route::get('secondroute','SiteController#secondRoute')->name('secondRoute');
The Controller is also working, because it doesnt matter if the index Route (/) is the mainView or SecondRoute so it has to be something with the routing itself?
Thanks
Edit: Mod Rewrite is on
Edit2: I'm using a Ubuntu on a Virtual Machine with Apache 2.4.25
Edit3:
public function secondRoute(){
return view('myself', ['title' => 'Myself']);
}
You missed '/' in second route
change
Route::get('secondroute','SiteController#secondRoute')->name('secondRoute');
to
Route::get('/secondroute','SiteController#secondRoute')->name('secondRoute');

Laravel 5.3 NotFoundHttpException

I'm trying to setup a Laravel 5.3 project. I have create the project and starting the 'localhost//public' shows the welcome screen just fine.
When adding a test entry in the web.php file like
Route::get('about', function () {
return view('welcome');
});
An then trying to access this as 'localhost//public/about' I get this NotFoundHttpException in RouteCollection.php line 161: error. I'm really puzzled as to whats wrong.
In the 5.2 version, with the routes.php, it worked perfectly fine.
Regs.,
Erik
NotFoundHttpException means Laravel can't found the requested route. Hence, you are trying to access something which doesn't exist that's why it is throwing NotFoundHttpException.
Try to access your route like
localhost/public/about
Well its a strange story when using artisan route:list the about neatly pops up. However when accessing through Chrome i wasn't able to load it. I have dropped the whole www directory and started afresh. Now it works. Must have been something lingering around.
Thx.,
Erik
You can try adding a 'public' prefix for the web routes in app\Providers\RouteServiceProvider.php like so:
protected function mapWebRoutes()
{
Route::group([
'middleware' => 'web',
'namespace' => $this->namespace,
'prefix' => 'public',
], function ($router) {
require base_path('routes/web.php');
});
}

Resources