I just ran through Laravel’s intermediate quickstart tutorial. On the whole it was rather well put together and worked with as little or as much copying and pasting as you felt like using. Here I’m just recording a few notes for future reference about non-obvious things I encountered.
Error messages for simple typos
One interesting thing to note is that using curly braces instead of round brackets in your blade templates can lead to not-obviously-related error messages. For instance, my first attempt at a template began with
1 2 3 |
// Incorrect way to extend a layout: // Note the use of {} instead of () @extends{'layout.php'} // DO NOT DO THIS! |
instead of the correct
1 2 |
// Correct way to extend a template @extends('layout.app') |
While obviously this is a simple typo that is entirely my own fault, the resulting error message,
FatalErrorException in fba8cddd62bd85dee11955629f018a61 line 24:
syntax error, unexpected ‘,’
was not particularly enlightening, and I spent rather longer than I would have liked before noticing my error.
Importing models and policies for authorisation
The tutorial seems to leave out two important lines when it comes to authorising the deletion of tasks via policy. Specifically, when the tutorial gets to the point of adding the new policy to app/Providers/AuthServiceProvider.php ,
1 2 3 |
protected $policies = [ Task::class => TaskPolicy::class, ]; |
it fails to mention that this won’t work until the lines
1 2 3 4 5 6 7 8 |
// app/Providers/AuthServiceProvider.php // ... use App\Task; use App\Policies\TaskPolicy; // ... |
are also added to the file.
Redirecting on login
Finally, if you create your own files from scratch for the tutorial instead of cloning their repo, then registering and logging in will appear to result in an error,
NotFoundHttpException in RouteCollection.php line 161:
This can be surprising at first, and might make you think there actually is an error in your code, but of course it is essentially just a 404 Not Found error—by default you are redirected to /home , which hasn’t been created. One option would of course be to create home view. Another, which is what the Laravel repo does, is to override the redirection destination in app/Http/Controllers/Auth/AuthController.php and point it at /tasks instead.
To do so, simply set the $redirectTo property to the desired path, for example
1 2 3 4 5 6 7 8 9 10 11 12 |
// app/Http/Controllers/Auth/AuthController.php class AuthController extends Controller { // ... use AuthenticatesAndRegistersUsers, ThrottlesLogins; protected $redirectTo = '/tasks'; // ... } |