Support the ongoing development of Laravel.io →
Configuration Requests Installation

Hi all, Looking to move back from .NET MVC to an enlightened and lovely PHP framework. I like what I'm seeing in Laravel. I've been working through the quickstart to get used to the basic plumbing but I've hit a wall with routing. I did hit the 'errors not defined' error and, after looking on SO, placed the route definitions inside the web middleware group in routes.php:

`Route::group(['middleware' => ['web']], function ()

Route::get('/', function () {

 $tasks = Task::orderBy('created_at', 'asc')->get();
    return view('tasks', [
        'tasks' => $tasks
    ]);
});

Route::post('/task', function (Request $request) {
    $validator = Validator::make($request->all(), [
        'name' => 'required|max:255',
    ]);

    if ($validator->fails()) {
        return redirect('/')
            ->withInput()
            ->withErrors($validator);
    } .... etc`

I also moved ShareErrorsFromSession class in to the 'web' middleware group in Kernel.php. So what I'm getting is this. The root URL ('/') works http://localhost/quickstart/public/ but no named URL works. So http://localhost/quickstart/public/task gives me a 404 not found. I suspect it's around this middleware stuff but I'm a bit foxed TBH. Could also be that I need to define an app root somewhere?

Any suggestions most welcome :) Mark

Last updated 2 years ago.
0

Assigning the web middleware group shouldn't be necessary as it is applied automatically by laravel.

Try changing your server config so that it points towards the public folder as the site root.

0

Thanks for chipping in.

Ok, in routes.php I commented out the Route::group(['middleware' => ['web']], function () { , in app.php I set the app root to /public and in Kernel.php I moved all of this \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, \App\Http\Middleware\EncryptCookies::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Session\Middleware\StartSession::class, \App\Http\Middleware\VerifyCsrfToken::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, out of the web middleware group to the global middleware. I still get a not found when I try to submit the form. If I put a breakpoint in index.php it only gets hit for the root url. /task doesn't even hit index.php.

Last updated 8 years ago.
0

I just added a dummy route to routes.php

Route::get("/fish", function () { return 'this is a get'; });

And if I try to go straight to it, (http get) I still see a 404.

Last updated 8 years ago.
0

This is what should be set by default in your Kernel.php

    protected $middleware = [
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
    ];

    /**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
        ],

        'api' => [
            'throttle:60,1',
        ],
    ];

    /**
     * The application's route middleware.
     *
     * These middleware may be assigned to groups or used individually.
     *
     * @var array
     */
    protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'can' => \Illuminate\Foundation\Http\Middleware\Authorize::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
    ];

which is the default. Don't remove the web middleware group.

Make sure that in your .env file, APP_DEBUG is set to true. Will give you more feedback if something goes wrong.

0

With that Kernel.php I get

Undefined variable: errors (View: /var/www/html/quickstart/resources/views/common/errors.blade.php) (View: /var/www/html/quickstart/resources/views/common/errors.blade.php), and the solution I got from SO was to put the ShareErrorsFromSession class in the $middleware array.

What's curious is that index.php is never hit except for app root ('/')'.

Mark

0

FIXED!!!! Prob was htaccess file. Need to set AllowOverride for web root to All in apache2.conf. Explanation here http://www.epigroove.com/blog/laravel-routes-not-working-make-sure-htaccess-is-working ... Phew... thanks for the suggestions anyway :)

Be a good idea to update the QuickStart notes to avoid people losing a day of their lives.

Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

sparkietm sparkietm Joined 10 May 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.