Laravel 5 Cached Routes not updating - php

I've cached my Laravel 5 routes by doing php artisan route:cache.
This went succesfull for quite a while and when I changed a route is could cache them again and it would all work like it should.
The problem is that I've moved some routes to another route group and it seems that they won't be cached for some reason.
I've tried to cache them again but it didn't work. I've also tried php artisan cache:clear but still not working.
Routes.php changes:
Route::group(['prefix' => 'api', 'middleware' => 'auth'], function () {
Route::get('invites', 'InvitationController#get');
Route::get('invites/check', 'InvitationController#check');
});
Changed to:
Route::group(['prefix' => 'api'], function () {
Route::post('auth', 'Auth\AuthController#authenticate');
Route::get('invites', 'InvitationController#get');
Route::get('invites/check', 'InvitationController#check');
});
As you can see I've moved those invitation routes to the Route group without the Authenticate Middleware. When I cached the routes again, it still does execute the Auth Middleware even when they are moved out of the group..

The right syntaxe to remove cached route in laravel 5.* is
php artisan route:clear
Regards

Try:
php artisan optimize
This will clear all the route cache as well as the file cache.

If you don't want to optimize again with every change.
You can try this;
CACHE_DRIVER=file to change => CACHE_DRIVER=array
After, you should clear to folder "bootstrap/cache"
I hope it works.

Related

Laravel auth middleware redirects to localhost even after changing the APP_URL

I have deployed my Laravel 8 application on live server and have set up the reverse proxy successfully to access the laravel app from a url like example.com/app/my-app.
Now the problem is, as I have used auth middleware which requests user to log in before he/she can access the app, opening example.com/app/my-app redirects to localhost:8000/login
Which is wrong as it is supposed to redirect to example.com/app/my-app/login
I have:
set the 'url' => "example.com/app/my-app" in config/app.php
ran php artisan optimize:clear
ran php artisan cache:clear
And also stopped the app and ran php artisan serve again
Can you please help me? Am I missing something?
You can use in web.php, if user not auth redirect '/' => '/login'
Route::group(['middleware' => 'guest'], function () {
// Redirect '/' => '/login'
Route::redirect('/', '/login');
// Auth routes
Auth::routes();
});
Remove the file inside the bootstrap/cache directory.Then run the following command :
php artisan cache: clear
php artisan config: clear
php artisan view: clear
php artisan route: clear
php artisan config: cache
php artisan optimize
Hope this will fixed your problems.

When I run command "make:auth", and reload Laravel, the links show but when I click them it says "Not Found"

So I've downloaded Laravel 5.5, and I ran the following command
in my terminal. php artisan make:auth and when I reloaded Laravel, the links for Login and Register show up but when I click them, it says Not Found.
I've tried resetting artisan and deleting my tables, and re-migrating artisan too, but none of them work.
php artisan make:auth
And heres my web.php file.
Route::get('/', function () {
return view('welcome');
});
Route::get('/post', 'PostController#index');
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
Have you checked your project's directory tree after executing it?
Did you run the migrations?
If you did all that it should scaffold all of the routes and views you need for authentication. But if it still does not work properly, then you might have to uninstall Laravel and install a fresh distro.
Can you add your web.php file under the routes directory please ?
It's probably a route problem.
Thank you.
It is because of anchor tag is not work...it may be some syntex error or spelling mistake
maybe ragister.blade.php have some problem

Laravel 5.4 Modules: NotFoundHttpException in RouteCollection.php line 161

Yep, it's another Laravel route not found issue! This is actually quite an odd one. I am aware there are multiple issues here with the same error message at least, but none that seem to be the same as mine.
I am using the nWidart/laravel-modules (https://github.com/nWidart/laravel-modules) package for Laravel to create a module-based setup. I began with a fresh install of Laravel 5.4 via Composer, then generated the basic user authentication via php artisan make:auth. After basic setup, my app/Http/routes.php file looks like this:
// home page
Route::get('/', function () {
return view('welcome');
});
// login, logout, register, etc.
Route::auth();
// admin dashboard
Route::get('/admin', 'AdminController#index');
I then installed the modules package via Composer and ran php artisan module:make Finances Jobs Etsy to create three modules, Finances, Jobs, and Etsy. This ran without incident. I then went into the Http/routes.php file for each individual module and added the auth middleware and an additional prefix to each route group:
// Finances routes file
Route::group(['middleware' => ['web', 'auth'], 'prefix' => 'admin/finances', 'namespace' => 'Modules\Finances\Http\Controllers'], function()
{
Route::get('/', 'FinancesController#index');
});
// Jobs routes file
Route::group(['middleware' => ['web', 'auth'], 'prefix' => 'admin/jobs', 'namespace' => 'Modules\Jobs\Http\Controllers'], function()
{
Route::get('/', 'JobsController#index');
});
// Etsy routes file
Route::group(['middleware' => ['web', 'auth'], 'prefix' => 'admin/etsy', 'namespace' => 'Modules\Etsy\Http\Controllers'], function()
{
Route::get('/', 'EtsyController#index');
});
Now here is the very frustrating issue: all the base app routes work fine. The home page route, the auth routes, and the /admin route all work perfectly. In addition, all the Jobs module routes work perfectly as well. However, any and all routes from the Finances and Etsy modules do not work. Trying to access https://[site url]/admin/finances shows me the following error:
NotFoundHttpException in RouteCollection.php line 161:
Which to me says, Laravel can't find the given route, despite being able to find the route for the Jobs module.
Extra confusingly, it sort of seems like Laravel can find the routes, as running php artisan route:list DOES show me the routes for the Finances and Etsy modules.
I have also tried running php artisan cache:clear and php artisan route:clear multiple times, in case it was some sort of caching issue. No luck.
So at this point I have absolutely no idea what to make of all this. I've got three modules, one whose routes are working perfectly, and two others, whose identically-configured routes are not working at all, yet are being found by route:list. I'm pretty much out of ideas as to what the issue could be at this point.
UPDATE: interestingly, if I place the route in the base app routes.php file like so:
Route::group(['middleware' => ['web', 'auth'], 'prefix' => 'admin/finances'], function()
{
Route::get('/', '\Modules\Finances\Http\Controllers\FinancesController#index');
});
Then the route does work. So it seems to be an issue where the web application specifically can't seem to find the routes.php files for those two modules, but the console application can.
I has the same issue, I solved it adding name property in:
Module/[ModuleName]/Http/routes.php,
For example:
Route::get('alias','controller#functionName')->name('module.alias');
I hope this tip could help you!
I had the same error and it solved like this.
Change file modules.php :
'scan' => [
'enabled' => false,
'paths' => [
base_path('vendor/*/*'),
],
],
To this:
'scan' => [
'enabled' => true,
'paths' => [
base_path('modules/*'),
],
],
And then run:
php artisan route:clear
php artisan optimize

Laravel 5.2 Only one specific route not found, but it does exist

No matter what I try, the route /authenticate/{code} returns a NotFoundHttpException.
My route in routes.php:
Route::get('/authenticate/{code}', ['as' => 'authenticate', 'uses' => 'FrontendController#getAuthenticate']);
When I am calling the route:
URL::route('authenticate', $code)
On my local machine it runs it just fine, but on my production server, it takes me to a NotFoundHttpException page.
It does site inside of the web middleware group.
I have tried (with no success):
resetting the github repo on the server (fresh install)
composer update
php artisan cache:clear
php artisan view:clear
php artisan route:clear
php artisan config:clear
composer dump-autoload
changing the route from authenticate to authenticate-email
What could it be? Every other route on the site works, it is just this one that doesnt.
The only thing I can think to advise is switching from using the URL Facade to using the built in helper function $url = route('authenticate', ['code' => $code]); I only say this because I can't seem to find in the docs how you hint at URI parameters when using URL::route() :)
I also ran into this issue. I deleted the route, then copy another working route and changed the route name and parameters with the one. And It Worked
I don't know if you solved this but I just had exactly the same problem, nothing I did would make the route work. It was a really simple route: Route::get('/search', ['middleware' => 'shop_session','uses' => 'Cinder\StoreController#viewProducts']);
Did all the things you did. In the end I moved the route to the top of my routes file, ran php artisan route:cache and it worked.
Not a great answer and I've got no idea why it worked but it did. Maybe worth a try?

Custom defined routes not resolving in Laravel

I have a Laravel 5.2 instance utilizing all the typical out-of-the-box routes for dashboard, cases, home, login/logout, and users (which is working well). I now need to create a wizard with steps (step1, step2, step3, etc.), and I need access to the session. I assigned them to the group middleware.
Route::group(['middleware' => 'web'], function () {
Route::get('/', function () {
// Uses Web middleware
});
Route::get('wizard/step1', [
'as' => 'wizard/step1', 'uses' => 'Wizard\WizardController#getStep1']);
Route::get('wizard/step2', [
'as' => 'wizard/step2', 'uses' => 'Wizard\WizardController#getStep2']);
});
However, when I go to the named route(s), I get a 404 error. So WizardController looks like the following.
namespace App\Http\Controllers\Wizard;
use App\Http\Controllers\Controller;
use App\Http\Requests;
class WizardController extends Controller
{
public function __construct()
{
//$this->middleware('guest');
}
public function getStep1()
{
return view('wizard.step1');
}
}
The defined views are resources/views/wizard/step1.php. Ideally, I'd like to refactor it so that Wizard is a separate group. However, nothing seems to work with the way I'm defining custom routing currently.
This happens when you cache the routes. The new route entries you add will never be recognized unless you clear the route cache.
You can delete cached routes using php artisan route:clear.
Since you will be changing the routes frequently in dev env, It is always better to not perform route caching while in dev environment.
You can do it by only running artisan route:cache as a post-deploy hook in Git, or just run it as a part of your Forge deploy process. So that every time you deploy your code in your server, your routes are cached automatically.
I resolved my issue by running the command:
php artisan route:clear
This lets Artisan delete your route cache and you can you can make sure routes are in sync.
Thanks for the help!

Categories