This project is based from Laravel 6 Tutorial for Beginners by TheNetNinja, but I am providing some tips to those who want to go along with that tutorial using Laravel 9.
These are the different lessons in that tutorial, which are linked to a specific commit in this repository. Adjustment tips are provided below a lesson that needs them.
After installing Laravel, you need to replace the contents of resources/views/welcome.blade.php
by the contents of this file.
5. Blade Basics
6. Blade Loops
7. Layout Files
8. CSS & Images
11. Controllers
You will encounter an error saying:
ERROR: Target class [PizzaController] does not exist.
To solve this, follow these steps:
-
Import
PizzaController
by adding this line on top ofroutes/web.php
.use App\Http\Controllers\PizzaController;
-
Then use the new Laravel 9 syntax in registering actions in routes:
REPLACE
Route::get('/pizzas', 'PizzaController@index'); Route::get('/pizzas/{id}', 'PizzaController@show');
WITH
Route::get('/pizzas', [PizzaController::class, 'index']); Route::get('/pizzas/{id}', [PizzaController::class, 'show']);
13. Migration Basics
- Do not worry about missing class names in the migration files. They are not required anymore since Laravel 9.
15. Eloquent Models
- You can skip adding a value on the price column. Nevermind the error that will appear on phpMyAdmin.
- Models will be created inside the app/Models folder instead.
Again, the new syntax these route actions are:
[PizzaController::class, 'index']
[PizzaController::class, 'show']
[PizzaController::class, 'create']
19. Post Requests
Again, the new syntax for registering this action in a route is:
Route::post('/pizzas', [PizzaController::class, 'store']);
20. Saving Records
If you get an error saying
SQLSTATE[HY000]: General error: 1364 Field 'price' doesn't have a default value
Just add a value for price during record creation:
...
$pizza->price = 0;
$pizza->save();
21. Arrays & JSON
22. Removing Records
Again, the new syntax for registering this action in a route is:
Route::post('/pizzas/{id}', [PizzaController::class, 'destroy']);
23. Using SASS
Please follow these steps:
- Replace the contents of your
package.json
with the contents of this file. - Replace the contents of your
vite.config.js
with the contents of this file. - Create the
sass
folder insideresources
. - Create the
main.scss
file and copy the content ofpublic/css/main.css
to it. - Replace the contents of
resources/main.scss
with the contents of this file. - In your
resources/views/layouts/layout.blade.php
, replacewith:<link rel="stylesheet" href="/css/main.css">
@vite('resources/sass/main.scss')
- Run
npm install
command. - Run
npm run dev
command on a different terminal session.
-
In your
resources/sass/app.scss
, replace// Bootstrap @import '~bootstrap/scss/bootstrap';
with:
// Bootstrap @import './bootstrap/scss/bootstrap';
-
In your
resources/views/layouts/app.blade.php
, replace<!-- Scripts --> <script src="{{ asset('js/app.js') }}" defer></script>
with:
<!-- Scripts --> @vite('resources/js/app.js')
also replace
<!-- Styles --> <link href="{{ asset('css/app.css') }}" rel="stylesheet"> <link rel="stylesheet" href="/css/main.css">
with:
<!-- Styles --> @vite('resources/sass/app.scss') @vite('resources/sass/main.scss')
-
Run
npm run dev
again.