renec112's avatar

Project flyer and routes in 5.2

Sorry to post a lot to this forum today, But i'm a bit lost in the series "Project flyer". The problem is, i'm using Laravel 5.2 and it's build in auth system.

I can't follow along the series because of the web middleware. I'm stuck around video 14. Nothing works anymore and i have tried cleaning up the routes file, watched tutorials about how to arrange it - but i just can't get it to work. At the moment when i viset the homepage, it says View [auth.login] cant be found lol.

What am i missing? - please help.

Route::get('/', 'PageController@index');

Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');
Route::resource("flyer", "FlyerController");
Route::resource("flyer", "FlyerController");
Route::get('{zip}/{street}', 'flyerController@show');

// Routes that require login
Route::group(['middleware' => ['web']], function () {
    
    Route::auth();
    Route::post("{zip}/{street}/photos", "FlyerController@addPhoto");
    Route::get('auth/login', 'Auth\AuthController@getLogin');
    Route::post('auth/login', 'Auth\AuthController@postLogin');
    Route::get('auth/logout', 'Auth\AuthController@getLogout');

});
0 likes
10 replies
hjgarcia1's avatar

Hey, what does your view folder look like? Also post the error.

renec112's avatar

Hi @hjgarcia1 - the whole site is a bit ruined because of my bad routes.. At the moment my error is:

InvalidArgumentException in FileViewFinder.php line 137:
View [auth.login] not found.

My view folder is sorted like this:

Views
    /auth
        login.blade.php
        register.blade.php
    /Errors
        503
    /pages
        home
    /Flyers
        Create
        Form
        Show
    /vendor
        .gitkeep
flash.blade.php
index.blade.php
layout.blade.php
tykus's avatar
tykus
Best Answer
Level 104

Get rid of all of those explicit auth routes are unnecessary since Route::auth() will generate all of these for you:

+--------+----------+-------------------------+------+-----------------------------------------------------------------+------------+
| Domain | Method   | URI                     | Name | Action                                                          | Middleware |
+--------+----------+-------------------------+------+-----------------------------------------------------------------+------------+
|        | GET|HEAD | login                   |      | App\Http\Controllers\Auth\AuthController@showLoginForm          | web,guest  |
|        | POST     | login                   |      | App\Http\Controllers\Auth\AuthController@login                  | web,guest  |
|        | GET|HEAD | logout                  |      | App\Http\Controllers\Auth\AuthController@logout                 | web        |
|        | POST     | password/email          |      | App\Http\Controllers\Auth\PasswordController@sendResetLinkEmail | web,guest  |
|        | POST     | password/reset          |      | App\Http\Controllers\Auth\PasswordController@reset              | web,guest  |
|        | GET|HEAD | password/reset/{token?} |      | App\Http\Controllers\Auth\PasswordController@showResetForm      | web,guest  |
|        | GET|HEAD | register                |      | App\Http\Controllers\Auth\AuthController@showRegistrationForm   | web,guest  |
|        | POST     | register                |      | App\Http\Controllers\Auth\AuthController@register               | web,guest  |
+--------+----------+-------------------------+------+-----------------------------------------------------------------+------------+

Move everything that remains inside the web middleware group - this provides the basic web app middlewares that your app will need by default to allow :

\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,
renec112's avatar

Thank you so much for helping me agian today @tykus_ikus , that's very kind of you!!

it fixed my problem.

Can i ask you a question - now that everything is inside (even the route for the index) doesn't mess up the site? How can users who aren't logged in even access index.php?

Anyways, thank you. You made my day.

tykus's avatar

No, don't confuse web and auth middlewares.

So, your routes file should be simpler now...

Route::group(['middleware' => ['web']], function () {
    
    Route::auth();
    Route::get('/', 'PageController@index');  // what is this for???
    Route::resource("flyer", "FlyerController");
    Route::get('{zip}/{street}', 'FlyerController@show');
    Route::post("{zip}/{street}/photos", "FlyerController@addPhoto");
});
renec112's avatar

I deleted Auth(); before, now it's back and the same error is back

"View [auth.login] not found."

I'm trying to redirect to the home.blade.php with this code:

Route::get('/', 'PageController@index');  // what is this for???

When i try to acces the index file, i get redirected to /login, with the error View [auth.login] not found. ):

tykus's avatar

There may be something in the old implementation that is tripping you up - it is hard to know without the app open in front of me.

However, if you run php artisan make:auth to add authentication to your app, this tends to be trivial. So, I would suggest you remove all of the old Auth files, and re-run this from the commandline. If you do take this option, you will need to rid yourself of whatever is relevant below before:

resources/views/auth/
views/layouts/app.blade.php
test/resources/views/home.blade.php
app/Http/Controllers/HomeController

Also, get a fresh copy of the AuthController here

renec112's avatar

I've already run that command to make the files.. I have the same routes as you now @tykus_ikus and it keeps redirecting to the login page, saying "View [auth.login] not found."

tykus's avatar

You definitely have a template in {project_directory} /resources/views/auth/login.blade.php??

renec112's avatar

Yes i had @tykus_ikus

I think my whole project is messed up.

I found a zip online, containing this project but for laravel 5.2. I'm going to compare that with mine. I can already see you were absolutely correct with the routes!

Thank you for your help :D

Please or to participate in this conversation.