Laravel Notes 2
Laravel Notes 2
Notes:
** XAMPP | PhpMyAdmin when using laptop office:
** http://localhost:8082
** http://localhost:8082/phpmyadmin/
** Git clone https://github.com/bradtraversy/lsapp
** Reference / Youtube Link: The Net Ninja
Introduction
What is Laravel?
● Framework for creating PHP Websites
● Works well with MySQL database
● Packed with useful features (blade, auth, eloquent)
Figure 1.0
Installing Laravel
Figure 1.0
Figure 1.1
Routes & Views
● When a request to the server has been made, the request is handed off to a
route file and looks at the URL. The request made can either process some data
to save into the database, retrieve data, etc. which is injected to a View.
● View method is an HTML template
Figure 1.0
Input:
Figure 1.1
Output:
Figure 1.2
Passing Data to Views
● Setup different simple route handlers
● Get data from database or API endpoint and inject into the view
● Using of Blade template to output dynamic value
● Blade Template: {{ $variable }}
Input:
Figure 1.0
Figure 1.1
Output:
Figure 1.2
Input:
Figure 1.3
Figure 1.4
Output:
Figure 1.5
Blade Basics
● Use of Blade template engine to make it easier to work with data and logic inside
of regular PHP docs
● Blade template is compiled into regular HTML by Laravel
● @ symbol: directives used in Blade
Input:
Figure 1.0
Figure 1.1
Output:
Figure 1.2
Ex.:
Figure 1.3
Blade Loops
● Iteration arrays or lists of data and output template for each item in the array
Ex:
Figure 1.1
Figure 1.2
Figure 1.3 - For Loop
Figure 1.4
Figure 1.5 - For Each Loop
Figure 1.6
Figure 1.5 - Loop Index
Figure 1.6
Figure 1.7 - Embed If Statement in For Each Loop
Ex.:
exte
Query Parameters
● Queries are a way to inject values or variables into a URL
● Question mark (?) denotes the start of a query string
● Ampersand (&) denotes additional query parameters
● Query string can have several query parameters
● Detect query parameter and access the values of them
● Go to route handler
Ex.: