user633440
user633440

Reputation:

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.

Upvotes: 1

Views: 694

Answers (2)

brainless
brainless

Reputation: 5819

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.

Upvotes: 1

user633440
user633440

Reputation:

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!

Upvotes: 0

Related Questions