Table of Contents....5
About the Author....10
About the Technical Reviewer....11
Acknowledgments....12
Introduction....13
Chapter 1: Introduction to Laravel....14
Laravel’s Flexibility....14
How Laravel Works....16
What Is the MVC Pattern?....20
How the MVC Pattern Works....22
Chapter 2: Setting Up Your Environment....24
Composer....24
Installing Composer Globally....25
Installing Laravel Globally....26
Installing Laravel Locally with Composer....27
Introduction to Homestead, Valet, and Forge....29
Forge: Painless PHP Servers....31
Installing VirtualBox and Vagrant....32
Installing Homestead Using Vagrant....38
Configuring Homestead....40
Shared Folders and Homestead....41
Launching the Vagrant Box....44
Homestead and MySQL....47
How to Create a New Laravel Project....50
Chapter 3: Routing, Controllers, Templates, and Views....53
Route Definitions....53
How to Find the Default Route Files....54
Route and RESTful Controller....55
How to List All Routes....55
Creating Controllers, Views, and Managing Routes....60
CRUD and the Seven Methods....63
Models Acts as a Resource....70
Models Act As Resources....73
Resourceful Controllers....74
The Importance of the Resourceful Controller....76
How to Supplement the Resource Controller....76
Getting User Input and Dependency Injection....77
How a Blade Template Works with Controllers and Models....80
Security in Blade....82
Authentication Through Blade....82
Control Structures in Blade....83
Other Advantages of Blade Templates....84
Chapter 4: Working with Models....86
Route Model Binding: Custom and Implicit....86
Implicit Route Binding....89
Custom Route Binding....90
Model Relations....91
How Migrations Work with the Laravel Model....92
Model and Faker Object....103
Examining the Home Page....108
Relations Between Model, Database, and Eloquent....115
Creating Views to Show Relationships....117
Chapter 5: Database Migration and Eloquent....123
Introduction to Migration....123
Introduction to Eloquent....124
Introduction to Eloquent Relations....125
One-to-One....126
One-to-Many....131
Separation of Concerns....138
Many-to-Many....142
Has-Many-Through....146
Polymorphic Relations....152
The Problem....153
The Solution....154
Summarizing All Relations....166
Chapter 6: Handling User Data and Redirects....177
How Redirect Methods Work....178
What Is a Request Object?....182
How Requests and Responses Work....184
Introducing Validation....185
Web Form Fundamentals....191
Using the Laravel HTML and Form Packages....192
Model Binding....196
The Traditional Way of Form Inputs....199
Form Request Validation....212
Chapter 7: Using Tinker....216
Handling a Database Using Tinker....216
SQLite Is a Breeze!....220
Chapter 8: Authentication, Authorization, and Middleware....222
Different Authentication Methods in the Company/Project/Task Management Application....223
How Auth Controller Works and What Auth Middleware Is....237
Middleware, Authentication, and Authorization in One Place....244
The Company App’s Model-View-Controller....250
Home Page, Redirection, and Authentication....264
Role of a User and Authorization....272
Authorization Through the Blade Template....275
Implementing Authorization Using Gates and Policies....288
How Authorization Works....290
How Policies Work....294
Why Are Policies Needed?....296
Chapter 9: Containers and Facades....302
SOLID Design Principle....302
Single Responsibility Principle....303
The Open-Closed Principle....303
Liskov Substitution Principle....304
The Interface Segregation Principle....304
Dependency Inversion Principle....304
Interfaces and Method Injection....305
Contracts vs. Facades....306
How a Container Works in Laravel....310
Containers and Classes....315
Chapter 10: Working with the Mail Template....322
Local Development....322
Using Tinker to Find the Verified E-mail....328
Changing the Route....330
Sending E-mail and Notifications....332
Sending E-mails....333
How to Send Notifications....343
Chapter 11: Events and Broadcasting....349
What Are Events and Broadcasting?....349
Setting Up Events and Broadcasting....350
Creating Events....351
Receiving Messages....365
Autogenerating Events....374
Chapter 12: Working with APIs....375
What Is REST?....375
Creating an API....376
Working with Laravel Passport....393
API Authentication....403
Appendix: More New Features in Laravel 5.8....407
What Is the Dump Server Feature?....407
Improved artisan Command....415
A Few More Additions....418
Renaming the Mail Format Folder....418
Changes to .env....418
Changing the Look of Error Pages....419
Improving Array and String Helper Functions....420
Changes in Caching....420
Where to Go from Here....421
Index....422
Develop cutting-edge websites and applications using the new features of Laravel 5.8. This book starts with an introduction to Laravel and takes a glance at its newly introduced features. Moving on to setting up your development environment, you will learn how the composer works. In addition to this, you will be introduced to Valet, Homestead, Virtual Box, Vagrant, and Forge in Laravel. With this foundation, you will be ready to get started writing your first Laravel apps.
To do so, you will learn to manage routes and controllers and how the Blade template works. Moving on to models, you will work with route model binding and get to know the relationship between models, databases, and Eloquent. Along the way you will define methods on your Eloquent model classes using different types of relationships.
Shifting focus to handling user data, you will see how redirect methods work. You will also get to know the inner workings of requests and responses. Continuing the data theme, Beginning Laravel covers basic and grouped artisan commands and how to handle databases with Tinker. By being able to handle data effectively, your applications will come alive for your users, giving them the functionality they need.
The last section of the book handles core concepts such as sending emails, alerting users via notifications, and implementing SOLID design principles. You will see how to decouple your application classes by using events and listeners.