0% found this document useful (0 votes)
102 views268 pages

Understanding Laravel Framework Basics

The document provides an overview of frameworks, particularly focusing on web frameworks like Laravel and Composer for PHP dependency management. It explains the benefits of using frameworks, such as improved code reusability and productivity, and details how to install and use Composer, including commands and the structure of a composer.json file. Additionally, it outlines the process for setting up a new or existing package using Composer.

Uploaded by

Huzaifa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views268 pages

Understanding Laravel Framework Basics

The document provides an overview of frameworks, particularly focusing on web frameworks like Laravel and Composer for PHP dependency management. It explains the benefits of using frameworks, such as improved code reusability and productivity, and details how to install and use Composer, including commands and the structure of a composer.json file. Additionally, it outlines the process for setting up a new or existing package using Composer.

Uploaded by

Huzaifa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

2024

Laravel

Huzaifa Noor
What is
Framework??
A frame Work is the set of the conceptual Structure and guidelines, used to
build something useful.
In Simple words framework is basically Contain Prewritten Code which can
perform some basic, important, daily use task. So What We gone Do in The
Framework is that We will write the codes of that tasks into the Specific
place and we Will Create the particular Classes of That Code or particular
Blocks of that Codes .And After that We will Simply Link that Code OR we
will implement that Code into our Original page.
 We will basically define the set of the rules For our Previously
performing tasks.
 We will also define the structure of that tasks.
 The OUTPUT Of the Frame work is the something useful.

“A framework may include predefined classes and


functions that can be used to process input, manage
hardware devices , and interact with system software

Why we use Framework?


 This Will make the Code easier and it will make the reusability Of The
code.
 It will make the Code faster and The Short.
 Like We use Some Tools To make our Work easier. For Example We Drill
Nail In the Wall With the hammer and the nail. That we called As the
Simple Version of Doing Work.
 But When We drill A Nail With Drill Machine That We Will make our
Work more Perfect, short-time And Easier. That’s What a Framework
can do.

1
 The Purpose Of the framework is to allow developers to focus on
building a unique features for their Projects rather than Writing code
from scratch(Start).
 Collection Of tools.
 No Need to start From the scratch.
 Save Time.
 Improve Productivity.
 Clean Code.
 Reuseable Code.
 Testing Will be the Easy.
 Debugging Will be The easy.

Web
Framework
 A web Framework (WF) or web application Framework (WAF)
Which helps to build Web Applications.
 Web Framework Provides Tools and libraries to Simplify
Common Web Development Operations. This can include web
Services, APIs, and other resources Which are useful into your
Work.
 Web framework help with a variety of tasks, From templating
and database access to session management and code reuse.
 More than 80% of all web app framework rely On the method
View Controller architecture.

Some Web
Framework
 Laravel
 Codeigniter
 Zend

2
 Django
 Spring

Composer
 Composer is a Tool in Php Which is used for the dependency
management in PHP.
 It allows you to declare the Libraries your Project depends on
and it will manage (install/update) them for You.
 Composer is not a package manager in the same Sense as
Yum or Apt are. Yes, it deals with “Packages” or Libraries, but
it manages them on a per-project basis, installing them in a
Directory (e.g. vendor) inside your Project.
 By default it does not install Any thing globally . Thus, it is a
dependency via the global command.
 For Example of we Create a Project inside that project we will
use the Different libraries and Function to manage these
libraries and the Function We Will use that Tool Which is Called
the Composer (We can Also manage the Libraries and The
Functions manually But that Will be too hardworking and
Difficult as Compare to the Composer.)
 We can also Say that Composer is made by the inspiration
from the NPM(Which will manage the packages.)
 All the work inside the Composer are locally not The globally.

Why we use
Composer
Suppose
 You have a Project that Depends on Number of
libraries.

3
 Some of those libraries are depends on the Other
libraries.
 if we Did not use The Composer then you should have to use
all that libraries and Also their corresponding libraries by their
selves.
Composer
 It Enables you to Declare the libraries you depend on.
 It Find out Which version Of Which package can and need to
be installed, and install them (Meaning it download them into
your Project.)
 In Simple words if your project needs ten Different libraries to
be installed then you Did not Need to install it manually the
Composer will install All of these libraries by itself And it will
mange these libraries.

How to install
Composer
Composer require PHP 5.3.2 + to run.
There are two ways to install the Composer.
 Download Composer exe from official website then install it.
 User Command line installation.
- It may need to set the path or use php
[Link] init.

Check if composer is already Installed


composer – V

How to update Composer:


Composer self-update

4
How to roll back the Composer update:
composer self-update --rollback.

List of all Composer Commands:


composer
Usage:
command [options] [arguments]
Options:
-h, --help Display help for the given command. When
no command is given display help for the list command
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi|--no-ansi Force (or disable --no-ansi) ANSI output
-n, --no-interaction Do not ask any interactive question
--profile Display timing and memory usage
information
--no-plugins Whether to disable plugins.
--no-scripts Skips the execution of all scripts defined
in [Link] file.
-d, --working-dir=WORKING-DIR If specified, use the given
directory as working directory.
--no-cache Prevent use of the cache
-v|vv|vvv, --verbose Increase the verbosity of messages: 1
for normal output, 2 for more verbose output and 3 for debug

Available commands:

5
about Shows a short information about Composer
archive Creates an archive of this composer package
audit Checks for security vulnerability advisories for
installed packages
browse [home] Opens the package's repository URL or
homepage in your browser
bump Increases the lower limit of your [Link]
requirements to the currently installed versions
check-platform-reqs Check that platform requirements are
satisfied
clear-cache [clearcache|cc] Clears composer's internal
package cache
completion Dump the shell completion script
config Sets config options
create-project Creates new project from a package into given
directory
depends [why] Shows which packages cause the given
package to be installed
diagnose Diagnoses the system to identify common errors
dump-autoload [dumpautoload] Dumps the autoloader
exec Executes a vendored binary/script
fund Discover how to help fund the maintenance of
your dependencies
global Allows running commands in the global composer
dir ($COMPOSER_HOME)
help Display help for a command
init Creates a basic [Link] file in current
directory

6
install [i] Installs the project dependencies from the
[Link] file if present, or falls back on the [Link]
licenses Shows information about licenses of
dependencies
list List commands
outdated Shows a list of installed packages that have
updates available, including their latest version
prohibits [why-not] Shows which packages prevent the
given package from being installed
reinstall Uninstalls and reinstalls the given package names
remove [rm] Removes a package from the require or
require-dev
require [r] Adds required packages to your [Link]
and installs them
run-script [run] Runs the scripts defined in [Link]
search Searches for packages
self-update [selfupdate] Updates [Link] to the
latest version
show [info] Shows information about packages
status Shows a list of locally modified packages
suggests Shows package suggestions
update [u|upgrade] Updates your dependencies to the
latest version according to [Link], and updates the
[Link] file

How to get Help


composer help

Get Help for command


7
composer help command_name.
composer help self-update
Description:
Updates [Link] to the latest version
Usage:
self-update [options] [--] [<version>]
selfupdate

Arguments:
version The version to update to

Options:
-r, --rollback Revert to an older installation of composer
--clean-backups Delete old backups during an update. This makes the current
version of composer the only backup available after the update
--no-progress Do not output download progress.
--update-keys Prompt user for a key update
--stable Force an update to the stable channel
--preview Force an update to the preview channel
--snapshot Force an update to the snapshot channel
--1 Force an update to the stable channel, but only use 1.x versions
--2 Force an update to the stable channel, but only use 2.x versions
--2.2 Force an update to the stable channel, but only use 2.2.x LTS
versions
--set-channel-only Only store the channel as the default one and then exit
-h, --help Display help for the given command. When no command is given
display help for the list command
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi|--no-ansi Force (or disable --no-ansi) ANSI output
-n, --no-interaction Do not ask any interactive question

8
--profile Display timing and memory usage information
--no-plugins Whether to disable plugins.
--no-scripts Skips the execution of all scripts defined in [Link] file.
-d, --working-dir=WORKING-DIR If specified, use the given directory as working
directory.
--no-cache Prevent use of the cache
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2
for more verbose output and 3 for debug

Help:
The self-update command checks [Link] for newer
versions of composer and if found, installs the latest.

php [Link] self-update

Read more at [Link]

[Link]
 It is the main [Link] File that defines your
Project requirements.
For Example Will Show How their code Will be Written.
{
“name”: “HUZAIFA”,
“Author”:
[
“name” : “Huzaifa Noor”
“e-mail” : hn764889@[Link]
}
],

9
“require”: {}
}
}

How to setup a new or Existing


package
You can also say how to create [Link] file in a Project to
make it Package.
There are basically two ways to Create the Composer file.
- Using Composer init command.
- Manually Creating [Link] file.

Creating Composer init Command


composer init – it is used to setup a new or existing package ,
The init command creates a basic [Link] file in the
Current directory.
Every project is a package.
As soon as you have a [Link] in a directory, that
Directory is a package.
Your Project will become the package when the [Link] File
is Created into your project.
Whenever you run that Command there Should be The
questions Which will be asked From you. And the meaning
of that Question will be the following.
- Package name – in order to make that package
installable you need to it a name. It consists of
vendor name and project name , separated by /.
The name can contain any character, including
white spaces, names are case insensitive , the

10
convention is all lowercase and dashes for word
separation. It is required for published
packages(libraries).

Syntax: vendername/packagename

Example: HuzaifaNoor/geek

Description:
- A Short description of the package. Usually this is
one line [Link] is required for published
packages(libraries).
- Authors – The authors of the package. This is
an array of objects. Each author can have
Following properties.
-
name : the author’s name . Usually their
real name.
- email: The author’s email. That’s the author
Email address.
- homepage: An URL to the author’s
Website.
- role: the Author’s role in the project (e.g.
developer or Translator)

For Example:
{
“author”: [
“name” : “Huzaifa”;
“email” ; “hn764889@[Link]”;

11
“homepage”:
“[Link]
“role” : “Developer”;
}
{
“name” : “HuzaifaNoor”;
“email” : “noorhuzaifa201@[Link]”;
“homepage” : “https//[Link]”;
“role” : “Developer”
}
]
}

Minimum Stability - Composer accepts these


flags as minimum-stability settings. The default setting for
minimum-stability if not provide is assumed to be
stable ,but you could define any of the flags down the
hierarchy.
These are the following categories of the packages.
- Stable (most stable)
- rc
- beta
- alpha
- dev (last stable)

12
Package Type - package type are used for
Custom installation logic. If you have a package that
needs some special logic, you can define a custom
type. It defaults(by-default) to library.
- Library
- Project
- Metapackage
- Composer-plugin

License – The license of the package. This can


be eithera string or any array of strings.
Example:- MIT
{
“license” : “MIT”
}
Creating Composer in Command
Prompt
PS C:\Users\LENOVO\OneDrive\Documents\XAMPP\htdocs\CMP> composer ini
Welcome to the Composer config generator

This command will guide you through creating your [Link] config.

Package name (<vendor>/<name>) [lenovo/cmp]: VendorKaName/Huzaifa


The package name VendorKaName/Huzaifa is invalid, it should be lowercase and have a vendor
name, a forward slash, and a package name, matching: [a-z0-9_.-]+/[a-z0-9_.-]+
Package name (<vendor>/<name>) [lenovo/cmp]: vendorkaname/huzaifa
Description []: "This is my First package"
Author [n to skip]: HuzaifaNoor <contact@[Link]>
Minimum Stability []:

13
Package Type (e.g. library, project, metapackage, composer-plugin) []:
License []:

Define your dependencies.

Would you like to define your dependencies (require) interactively [yes]? n


Would you like to define your dev dependencies (require-dev) interactively [yes]? n
Add PSR-4 autoload mapping? Maps namespace "Vendorkaname\Huzaifa" to the entered relative
path. [src/, n to skip]: y
The src folder name "y" is invalid. Please add a relative path with tailing forward slash. [A-Za-z0-9_-/]
+/
Add PSR-4 autoload mapping? Maps namespace "Vendorkaname\Huzaifa" to the entered relative
path. [src/, n to skip]: src/

{
"name": "vendorkaname/huzaifa",
"description": "\"This is my First package\"",
"autoload": {
"psr-4": {
"Vendorkaname\\Huzaifa\\": "src/"
}
},
"authors": [
{
"name": "HuzaifaNoor",
"email": "contact@[Link]"
}
],
"require": {}
}

Do you confirm generation [yes]? y


Generating autoload files
Generated autoload files
?>

[Link]
{
"name": "vendorkaname/huzaifa",
"description": "\"This is my First package\"",
"autoload": {
"psr-4": {
"Vendorkaname\\Huzaifa\\": "src/"
}
},
"authors": [
{

14
"name": "HuzaifaNoor",
"email": "contact@[Link]"
}
],
"require": {}
}

How to setup a new or existing


Package
Manually Creating [Link] File:
You have to Create [Link] File and write JSON code yourself with
required Properties.

Manually Created
[Link]
{
"name": "vendorkaname/huzaifa",
"description": "\"This is my First package\"",
"autoload": {
"psr-4": {
"Vendorkaname\\Huzaifa\\": "src/"
}
},
"authors": [
{
"name": "HuzaifaNoor",
"email": "contact@[Link]"
}
],
"require": {}
}

 composer config –global(-g) –


Operate on the global config File located at
$COMPOSER_HOME/[Link] without this
command affects the local [Link] File.
15
 composer config –list(-l) – It shows all
the current config variables. ( it will Show all of your
current config variables).
 composer config setting-key”setting-value”
– it sets the config key to the value.
 composer config --unset - It removes the
Configuration element named by setting-key.
 Composer config --editor(-e) – Opens the
config file([Link]) in an editor. Use the global config
([Link]).

Keys
- name
- version
- type
- description
- license
- homepage
- keywords
composer config --list
PS C:\Users\LENOVO\OneDrive\Documents\XAMPP\htdocs\CMP> composer config --list
[[Link]] composer
[[Link]] [Link]
[process-timeout] 300
[use-include-path] false
[use-parent-dir] prompt
[preferred-install] dist
[[Link]] fail
[notify-on-install] true
[github-protocols] [https, ssh]
[gitlab-protocol]
[vendor-dir] vendor (C:\Users\LENOVO\OneDrive\Documents\XAMPP\htdocs\CMP/vendor)
[bin-dir] {$vendor-dir}/bin (C:\Users\LENOVO\OneDrive\Documents\XAMPP\htdocs\CMP/vendor/bin)
[cache-dir] C:/Users/LENOVO/AppData/Local/Composer

16
[data-dir] C:/Users/LENOVO/AppData/Roaming/Composer
[cache-files-dir] {$cache-dir}/files (C:/Users/LENOVO/AppData/Local/Composer/files)
[cache-repo-dir] {$cache-dir}/repo (C:/Users/LENOVO/AppData/Local/Composer/repo)
[cache-vcs-dir] {$cache-dir}/vcs (C:/Users/LENOVO/AppData/Local/Composer/vcs)
[cache-ttl] 15552000
[cache-files-ttl] 15552000
[cache-files-maxsize] 300MiB (314572800)
[cache-read-only] false
[bin-compat] auto
[discard-changes] false
[autoloader-suffix]
[sort-packages] false
[optimize-autoloader] false
[classmap-authoritative] false
[apcu-autoloader] false
[prepend-autoloader] true
[github-domains] [[Link]]
[bitbucket-expose-hostname] true
[disable-tls] false
[secure-http] true
[cafile]
[capath]
[github-expose-hostname] true
[gitlab-domains] [[Link]]
[store-auths] prompt
[archive-format] tar
[archive-dir] .
[htaccess-protect] true
[use-github-api] true
[lock] true
[platform-check] php-only
[home] C:/Users/LENOVO/AppData/Roaming/Composer
}

composer config name


“examplevan/examplepack”
PS C:\Users\LENOVO\OneDrive\Documents\XAMPP\htdocs\CMP> composer config name
"exampleven/examplepack"
PS C:\Users\LENOVO\OneDrive\Documents\XAMPP\htdocs\CMP>
/* That name will be set out in the [Link] File */
{
"name": "exampleven/examplepack",
"description": "\"This is my First package\"",
"autoload": {
"psr-4": {
"Vendorkaname\\Huzaifa\\": "src/"

17
}
},
"authors": [
{
"name": "HuzaifaNoor",
"email": "contact@[Link]"
}
],
"require": {}
}

composer config – unset


description(remove the
description)
PS C:\Users\LENOVO\OneDrive\Documents\XAMPP\htdocs\CMP> composer config name
"exampleven/examplepack"

PS C:\Users\LENOVO\OneDrive\Documents\XAMPP\htdocs\CMP> composer config --unset description


PS C:\Users\LENOVO\OneDrive\Documents\XAMPP\htdocs\CMP> composer config --unset description
PS C:\Users\LENOVO\OneDrive\Documents\XAMPP\htdocs\CMP>
/* it will remove the description from the [Link] file */
{
"name": "exampleven/examplepack",
"autoload": {
"psr-4": {
"Vendorkaname\\Huzaifa\\": "src/"
}
},
"authors": [
{
"name": "HuzaifaNoor",
"email": "contact@[Link]"
}
],
"require": {}
}

18
Command to Open [Link] in
an editor
composer config –editor
{
"name": "exampleven/examplepack",
"description": "\"This is my First package\"",
"autoload": {
"psr-4": {
"Vendorkaname\\Huzaifa\\": "src/"
}
},
"authors": [
{
"name": "HuzaifaNoor",
"email": "contact@[Link]"
}
],
"require": {}
}

If you want to open [Link] global for


that you will use the global flag.
composer config -- global –
editor
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

19
Install the latest PowerShell for new features and improvements!
[Link]
PS C:\Users\LENOVO\OneDrive\Documents\XAMPP\htdocs\CMP> composer
config --global --editor
{
"config": {}
}

How to install/Add
package
composer require VendorName/packageName –
This command install a package, and any packages that it
depends on.

--dev: Add packages to require -dev.


If you want to write The require then you will write the
Following Command.
Composer require VendorName/PackageName --dev.
[Link]

How to uninstall/Remove
Package

20
composer remove
VendorName/PackageName - The remove
command removes packages from the [Link] File
from the current directory.

Syntax:-
composer remove
vendorName/PackageName.
Syntax:-
composer remove
vendorName/PackageName1
VendorName/PackageName2 .
Example:-
composer remove fazninotto/faker.
--dev: it removes packages from require -dev
Example:-
composer remove fazanintto/faker --dev
composer remove
dompdf/dompdf
Installiing the Composer With the Specific Version
for that We wil Write Out the following Command.

21
composer require
dompdf/dompdf:0.7.0
if we want to install the dev master Version of the
package for that We will Write out the following
Command.
composer require
dompdf/dompdf:dev-master
if we want to install the package Inside The require-
div For that we will Write th out the Following Code .
What is the Difference between the require and the
require-dev
- Inside the require those packages are
installed Which is required For The
processing.
- And inside the required-dev those packages
are installed which is Required For The
testing Purpose. These packages are For the
testing purpose OR the development
Purpose.
composer remove dompdf/dompdf --
dev

22
How to use the
package
There are three Simple Steps to use the packages.
- Install package
- Include [Link] File
- Now you can use packages.

[Link]
<?php
/* This package Will Generate the Fake Data For your project */
require_once('./vendor/[Link]');
$faker = Faker\Factory::create();
echo $faker->name . "<br>";
echo $faker->address. "<br>";

/* the Following Code have got from the website that how we can use the following package into our
project */
use Dompdf\Dompdf;

// instantiate and use the dompdf class


$dompdf = new Dompdf();
/* in The Following bracket the Content Of the PDF File Will be exist */
$dompdf->loadHtml($faker->name . $faker->address);

// (Optional) Setup the paper size and orientation


$dompdf->setPaper('A4', 'landscape');

// Render the HTML as PDF


$dompdf->render();

// Output the generated PDF to Browser


$dompdf->stream();
?>

OUTPUT

23
Julia Streich
0390 Sanford Land Apt. 762 Mayertton, WI 01050

Update
composer update VendorName/PackageName – This
command is used to get the latest version of the
dependencies and to update the [Link] file. If no
package name is specified, all packages in the specified
location will installed.
(It will not update the packages it will upgrade the
dependencies in the latest versions)

Syntax:
composer update
(It Will update the all Dependencies)
Syntax:
composer update VenderName/packageName
Syntax:
composer update VenderName/packageName
VenderName2/packageName2
Syntax:
composer upgrade VenderName/packageName
Syntax:
composer u VenderName/packageName

24
Example:
composer update fzanintto/faker

install/i
composer install - The install command reads the
[Link] file from the current directory, resolves the
dependencies, and installs them into vendor.
If there is a [Link] files in the current directory, it
will use the exact versions from there instead of resolving
them. This ensures that everyone using library will get the
same versions of the dependencies.
- The advantage O fusing this is that it will Not
cause Any version Problem For Example Some Of
our member Will have another version of The
package And the Other of our member have
Another version This Will not happened because
everyone Will get The same version dependencies.
There is no [Link] , Composer will create one after
dependency resolution.

Example:
composer install

global
25
The global command allows you to run other commands
like install, remove , require or update as if you were
running them from the COMPOSER_HOME directory.

Example:
composer global install
The COMPOSER_HOME var allows you to change the
Composer home directory. This is hidden, global( per-user
on the machine) directory that is shared between all
projects. This is the hidden, global ( pre-user on the
machine) directory that is shared between all Projects.
By default it points to C:\users\<user>\AppData\Roaming\
Composer on Windows.

How to list All


packages
composer show - This command is used to list all of the
available Packages.
composer show vendername/packageName -
This command is used to see the details of a certain package.

Example:- composer show fzanintto/faker


composer show
dompdf/dompdf v2.0.4 DOMPDF is a CSS 2.1 compliant HTML to PDF
converter
fzaninotto/faker v1.5.0 Faker is a PHP library that generates fake data
for you.
masterminds/html5 2.8.1 An HTML5 parser and serializer.

26
phenx/php-font-lib 0.5.6 A library to read, parse, export and make
subsets of different types of font files.
phenx/php-svg-lib 0.5.2 A library to read, parse and export to PDF SVG
files.
sabberworm/php-css-parser v8.5.1 Parser for CSS Files written in PHP

-- all : List all packages available in all your


repositories.
--name-only (-N): List package name only.
--path(-P): List package paths.
--tree (-t): List your dependencies as a tree. if you
pass a package name it will show the dependency
tree for that package.
PS C:\Users\LENOVO\OneDrive\Documents\XAMPP\htdocs\CMP> composer show --tree
dompdf/dompdf v2.0.4 DOMPDF is a CSS 2.1 compliant HTML to PDF converter
├──ext-dom *
├──ext-mbstring *
├──masterminds/html5 ^2.0
│ ├──ext-dom *
│ └──php >=5.3.0
├──phenx/php-font-lib >=0.5.4 <1.0.0
│ └──ext-mbstring *
├──phenx/php-svg-lib >=0.3.3 <1.0.0
│ ├──ext-mbstring *
│ ├──php ^7.1 || ^8.0
│ └──sabberworm/php-css-parser ^8.4
│ ├──ext-iconv *
│ └──php >=5.6.20
└──php ^7.1 || ^8.0
fzaninotto/faker v1.5.0 Faker is a PHP library that generates fake data for you.

27
└──php >=5.3.3
PS C:\Users\LENOVO\OneDrive\Documents\XAMPP\htdocs\CMP>

--available (-a): List available packages only.

Create a project from a


package
composer create-project VendorName/PackageName
ProjectName –
you can use Composer to create new projects From an existing
package.
To create a new project using Composer you can use the create-
project command. Pass it a package name, and the directory to
create the project in. You can also provide a version as third
argument, Otherwise the latest version is used.
If the directory does not currently exist, it will be created during
installation.

Example:
composer create-project Laravel/Laravel myproject

Example:
composer create-project Laravel/Laravel myproject
“5.8.*”
We will Create the Project from the Package.

[Link]
28
[Link] and the [Link] Files have the Same
properties.

- name - it Consists of Vendor name and project name,


separated by /.
Example:
“name” : “HuzaifaNoor”
- description – A Short description of the package.
Example:
“description” : “Hello I am package”.
- version – The version Of the package.
Example:
“version” : “v0.8.3”
- type – The type of the package. It Defaults to the
Library.
Example:
“type” : “library”.

- keywords – An Array of keywords that the package is


related to. These can be used for Searching and Filtering .
Example:
“keywords” : [“css”,“parser” , “stylesheet”].
- homepage – An URL to the website of the project.
Example:
“homepage”:
“[Link]
- time– Release date of the Version.
Example:
“time” : “2018-12-14T[Link]+00:00”.
- _readme – A related path to the readme document
Example:
“_readme” : [].
“This File lock the dependencies of your project to a
known state”,

29
“Read more about it at [Link]
[Link]#installing-dependencies”.
“This File @generated automatically”
]
- license – the license of the package. This can be
either a String or an array of strings.
Example:- MIT
- authors – The author of the package. This is an
array of objects.
Each Author object can have the Following Properties.

- name – the author’s name. Usually their


real name.

- email – The author’s email address.


- hompage – An URL to the author’s
Website.

- role – The author’s role in the Project


(e.g. developer or translator.).

- require – Lists packages required by this


package. The Package will not be installed unless those
requirement can be met.

Example:
“require”: {
“ext-dom” :”*”,
“ext-mbstring” : “*”,
“phenx/php-font-lib” : “0.5”,
“phenx/php-svg-lib” : “0.3”,

30
}
Require basically list Up all of those elements which are
need to require to install the particular package. Mean’s to
install a particular packages we will Also need few package
to be installed that will be managed by the require.

- require-dev – Lists packages require for


developing this package , or running tests, etc.
The dev requirements of the root package are
installed by default. ( that require is used for the
developing )
Example:
require-dev{
“phpunit/phpunit”: “4.8|^5.5|^6.5”.
“squizlabs/php_codesniffer”: “2.*”
}
- autoload – Autoload mapping ofr a PHP
autoloader.
PSR-4
Classmap
Files
- autoload-dev – This section allows to define
autoload rules for the development purpose.
PSR-4
Classmap
Files

Autoloading
31
The package we install inside that packages how their Files are
autoloaded.
How you can autoload the files in your project.
There are some Following properties of the autoload.

- autoload – Autoload mapping for a PHP autoloader.


- autoload-dev – This section allows to define
autoload rules for development purposes.
 Files
 Classmap
 psr-4
There is a Following command
dump-autoload/dumpautoload
if you need to Update the autoloader because Of new
classes in a classmap package for example, you can use
dmp-autoload to do that without having to go through an
install or update.

Example:-
composer dump-autoload

files
if you want to require certain files explicitly on every request then
you can use the files autoloading mechanism. This is useful if your
package includes PHP function that cannot be autoload by
php. The files reference are all combined, into a single key.
 value array which may be Found in the generated file
vendor/composer/autoload_files.php (Location)
The files references are all combined, into a single key.

32
Here is the Following code to autoload All
the Files
{
“autoload” : {
“files” : {
“realme/[Link]”,
“realme/[Link]”,
“realme/[Link]”,
“realme/[Link]”
}
}
}

Classmap
This Scanning for Classes in [Link] and .inc files in the
given directories/files.
This classmap references are all combined, during
install/update, into a single key => Value array which may
be found in the generated file.
 Vendor/composer/autoload_classmap.php
 You can use the classmap generation support to define
autoloading for all libraries that do not follow PSR-
0/4.

33
“autoload” : {
“files” : [
“realme/[Link]”,
“realme/[Link]”,
“realme/[Link]”,
“realme/[Link]”
}
]
“classmap” : [
“./realme/[Link]”,
“./realme/[Link]”,
“myclass/”
]
}
}

Steps to autoload the (functions


and classes)

Step1:
composer init (terminal command to create the
package)
Step2:
Location Of the inside the file attributes.
"files":[

34
"realme/[Link]",
"redme/[Link]",
"redme/[Link]"
]

Step 3:
Location of the Classes inside the classmap attribute.
"classmap": [
"./realme/[Link]",
"./redme/[Link]",
"myclass/"
],

Step 4:
If we want to include(autoload) all of the classes from the
directory For that Give the Location of The Directory only.
"myclass/"
Like this

Step 5:
If we want to Exclude(Not include/autoload) one of the File
from the directory for that we will use The Following code.
"exclude-from-classmap" : [
"./myclass/[Link]"
],

Step6(IMP):

35
You will run the Command on the Terminal to autoload the functions and
the classes.

“composer dump-autoload”.

[Link]
<?php

/* With using the autoloading concept */


require('./vendor/[Link]');
/*
Without using the autoloading concept
require('./realme/[Link]');
require('./redme/[Link]');
require('./redme/[Link]');
require('./redme/[Link]');

==>Remember
For Functions we will use the Files of the Composer.
For classes we will use the Classmap of the composer.
*/
displaymodel1();
displaymodel2();
displaymodel3();

/* Creating the object of the classes */


$realme = new Realmemobile;
$redme = new Redmemobile;
/* If we Give Only the Directory OR the Folder name then it Will Find OR Scan All the Classes inside
that Folder And
it will Autoload that Classes
==> in the Following Exmaple we have Given only the Directory name not the name of the File it
Scan the classes by itself*/
$class1 = new class1;
/* if we do Not want to Include one of The classs from the whole Directory(It does not metter how
many classes inside the directory)
For that we will use the Following Code That
"excluse-from-classmap" : [
"./myclass/[Link]"
],
"excluse-from-classmap" This Function Will Exclude that particular File.
So that Following class2 Will not be Shown to us.
*/
$class2 = new class2;

36
?>

[Link]
<?php
function displaymodel1(){
echo "real Me 2 <br>";
}

?>

[Link]
<?php
class Realmemobile {
function __construct(){ /* Constructor will automatically When we make the object Of that class. */
echo "Realme Mobile Class <br>" ;
}
}
?>

[Link]
<?php
function displaymodel2(){
echo " redmi 2 <br>";
}
?>

[Link]
<?php
function displaymodel3(){
echo " redmi 3 <br>";
}
?>

[Link]
<?php
function displaymodel3(){
echo " redmi 3 <br>";
}
?>

[Link]
<?php

37
class Redmemobile {
function __construct(){ /* Constructor will automatically When we make the object Of that class. */
echo "Realme Mobile Class <br>" ;
}
}
?>

[Link]
{
"name": "lenovo/project1",
"description": "This is my First project",
"autoload": {
"files":[
"realme/[Link]",
"redme/[Link]",
"redme/[Link]"
],
"classmap": [
"./realme/[Link]",
"./redme/[Link]",
"myclass/"
],
"exclude-from-classmap" : [
"./myclass/[Link]"
],
"psr-4": {
"Lenovo\\Project1\\": "src/"
}
},
"require": {}
}

OUTPUT
real Me 2
redmi 2
redmi 3
Realme Mobile Class
Realme Mobile Class
Class 1

Fatal error: Uncaught Error: Class "class2" not found in C:\Users\LENOVO\


OneDrive\Documents\XAMPP\htdocs\Project1\[Link] Stack trace: #0

38
{main} thrown in C:\Users\LENOVO\OneDrive\Documents\XAMPP\htdocs\
Project1\[Link] on line 35

psr-4
Under The psr-4 key you define a mapping for the
namespaces to paths,relatives to the package root. The
PSR-4 references are all combine, during install/update,
into a single key => value array which may be found in
the generated file Vendor/composer/autoload_psr-[Link].
you can use the classmap generation support to define
autoloading for all libraries that do not follow PSR-0/4.
"autoload": {
"psr-4": {
" Project\\": "Product/"
}
}
},
psr-4 should have the standard specification Which
Should have to be followed.

specification:
\<NamespaceName>(\<SubNamespaceNames>)*\
<ClassName>

classmap vs psr4
PSR-4 does not need reported(run the Command )
dumpautoload for every change or addition of new file,

39
While classmap requires (to run the command )
dumpautoload for every Change in existing files containing
classes or addition of new Files in Specified Directory.

If we want to autoload all the files inside the


Directory with the help Of The psr-4 it is the
necessary that the name of the directory(Folder)
(Bang Nepal because namespace is Product/Nepal)
and the namespace should be the same.
(Pak India because namespace is Product/India)

[Link](Items(Folder))
<?php
/* Without using the autoload
For the psr-4 it is necessary to create the namespace in all of these following
files.
require 'C:\Users\LENOVO\OneDrive\Documents\XAMPP\htdocs\Items\bang\[Link]';
require 'C:\Users\LENOVO\OneDrive\Documents\XAMPP\htdocs\Items\pak\[Link]';
require 'C:\Users\LENOVO\OneDrive\Documents\XAMPP\htdocs\Items\pak\[Link]';
*/
require '/Users/LENOVO/OneDrive/Documents/XAMPP/htdocs/Items/vendor/[Link]';

use Product\India\Laptop;
use Khana\pak\Lahore\Biryani;
use Product\India\Mobile;
use Product\Cool\Dell;
use Product\Nepal\Books;

$lap = new Laptop;


$MOB2 = new Mobile;
$DELL3 = new Dell;
$PP2 = new Biryani;
$BK3 = new Books;
?>

[Link](Items/Nepal(Folder))
<?php
namespace Product\Nepal;

40
class Books {
function __construct()
{
echo "<h1> Product\Nepal Namespace - Books class </h1><br>";
}
}
?>

[Link](Items/India)
<?php
namespace Product\India;
class Mobile {
function __construct()
{
echo "<h1> Product\India Namespace - Mobile class </h1><br>";
}
}
?>

[Link](Items/india)
<?php
namespace Product\India;
class Laptop{
function __construct()
{
echo "<h1> Product\India Namespace - Laptop class </h1><br>";
}
}
?>

[Link](Items/)
<?php
namespace Product\Cool;
class Dell{
function __construct()
{
echo "<h1> Product\Cool Namespace -Dell class </h1><br>";
}
}
?>

41
[Link](Items/pak/lahore)
<?php
namespace Khana\pak\Lahore;
class Biryani{
function __construct()
{
echo "<h1> Khana\Pakistan\Lahore Namespace Biryani Class </h1><br>";
}
}
?>

[Link]
{
"name": "huzaifanoor/huzaifa",
"description": "\"This is an Product Package\"",
"require": {
"dompdf/dompdf": "^2.0"
},
"autoload": {
"psr-4": {
"Product\\Nepal\\":
"C:/Users/LENOVO/OneDrive/Documents/XAMPP/htdocs/Items/Nepal",
"Product\\India\\":
"C:/Users/LENOVO/OneDrive/Documents/XAMPP/htdocs/Items/India",
"Product\\Cool\\":
"C:/Users/LENOVO/OneDrive/Documents/XAMPP/htdocs/Items/",
"khana\\Pakistan\\":
"C:/Users/LENOVO/OneDrive/Documents/XAMPP/htdocs/Items/pak/Lahore/"

}
}
}

OUTPUT
Product\India Namespace - Laptop class

42
Product\India Namespace - Mobile class

Product\Cool Namespace -Dell class

Fatal error: Uncaught Error: Class "Khana\pak\Lahore\Biryani" not found in C:\Users\LENOVO\


OneDrive\Documents\XAMPP\htdocs\Items\[Link] Stack trace: #0 {main} thrown in C:\
Users\LENOVO\OneDrive\Documents\XAMPP\htdocs\Items\[Link] on line 19

Composer Documentation
[Link]

All Commands
[Link]

Packages
[Link]

Model View Controller


(MVC)
The MVC is an architectural pattern that separates an application
into there main logical components Model, Views and controller.
Each of these Component have their own role in the project .
MVC model was first introduced in 1987 in the Smalltalk
programming language.
More than 80% of all Web app framework rely on the Model view
controller architecture.

43
View
It represent how data should be presented to the application user. User can read or
write the data from view.

(How the data should be represented in the Front of The


user)
Basically it is responsible For Showing the end user content, we
can say it is user interface.
It may consists of HTML, CSS, JS

Controller

44
The user can send request by interacting with view, the controller
handles these requests and sends to Models then gets appropriate
response from the Model, sends response to view.
It may also have required Logics.
It works as a mediator between view and the model.

Real Life Example

45
Role Of Model:
All the Request that we have got according to the Data Model have
Process that Request.
- For Example It(Model) have got the request of the Inserting
the Data And updating the data.
The Model can Communicate With the Controller. Because it got the data
(Required information) From the Controller and in response it will
Communicate with the Controller.

Role of View:
View in this Architecture work as the user-interface it will update Itself. Whenever
Controller send the information it will update that information.

- That information Will be shown to the user as an interface (After the


updation.).
- That interface should be the Form or the webpage or another
[Link]/CSS
- It will get the Information From the Controller.

46
Role of Controller:
- All the Logic of the server Site Will be Handled by the Controller.
- It will Also Check How URL request of the Data is get From the
GET Method OR POST Method.
- It Will Process All of these Requests.
- It will Also Process Any input from the data.
- It will also get the Data from the user.
- Any information Or the data it will get Will pass to the model.
- It will Also get The data from the Model.
- Then It will pass the data to the Model.

The Important reason Wy we use MVC is that We can


divide OR Separate the Model ,Controller and View
in Parts.
It will basically Separate the every block
(Model,controller,view) and Every block Are The
Independent and does not Effect the Other.(It
Contain Very minor dependency).

Why use MVC


 Organized Code.
( Your Code will be Completely Organized you
Will understand Which part of the Code Should be

47
Exist Where . Where Should We have to Written
the Model Code , Or View Code Or the Controller
Code.)
 In MVC Every block independent In Simple Words
one block In MVC are not depend upon the Other
block in the MVC.
 It will Reduce the Complexity of Th Web
Application.
 It is Easy to maintain.
 It will be easy to Modify.
 MVC cannot be used in the small projects.

Basic Directory Structure Of


MVC
 assets(Folder)
- CSS
- images
- JS
 Config(Folder)
- Database config File
 Controllers
 Models
 Views

What is Laravel?
Laravel is a Free, Open-source PHP based Web Framework
For building high End web Application, Following the Model

48
View Controller architectural Pattern and based on
Symfony.
Laravel Follow the Model View Controller(MVC)
Architectural pattern.
It is Created by Taylor Otwell.
Laravel Source Code:
[Link]

Advantages of Laravel:
- It is an Open Source
- Laravel Basically Contain Collection Of the Tools.
- As We know it Contain Lots Of the available Tool So that it
will Save Time.
- It will Improve the Productivity.
- Robust and Easy.
- It Provide The Security of an Application.
- It Provide the authentication.
- It will Provide the Routing features.
- It will Provide The Templating Features.

Requirements For the


Laravel
You Should have The basic knowledge About the Following Topics.
 HTML

49
 CSS
 JAVASCRIPT
 SQL
 PHP OOP
 MVC
 Composer

How to install Laravel


The First method of installing the Laravel is that
Download the Laravel installer using composer.
The Command For install the Laravel is Following.
composer global require

Laravel/installer

Then use Laravel new command will create a fresh Laravel


installation in the Directory you Specify.

laravel new projectname


For the Creation Of Another project you Did Not need
to Run that Command

composer global require

Laravel/installer

50
We just Have to Run Only that Command.

laravel new projectname


if you want to Remove the larval Installer For that We
will write the Following Command.

composer gobal remove


Laravel/installer
Second Method
Install Laravel by issuing the Composer Create-Project Command.
composer create-project --prefer-dist
Laravel/Laravel projectname

Laravel Directory
Structure

51
GeekyShow:-
That’s the project Folder name. inside that Folder The Folders and the Files of the project is here.

app – This app Directory(Folder) Contain the Core Code of the application.
bootstrap – The Bootstrap directory contains the [Link] file Which bootstraps the Framework.

config – The Config Directory as The name Implies, Contains all of your application’s Configuration
files.

database – The database Directory Contain your Database migrations , Model factories , and Seeds. If
you Wish you may Also Uses this Directory to hold an SQLLite Database.

public – the Public Folder Contain the [Link] File, Which is the entry point for all requests entering
your application and Configures autoloading. This Directory also houses your assets such as images,
JavaScripts, and CSS. It is the main and the Useful Directory in our Project.

52
resources - The resources Directory Contains Your view as well as your raw ,
uncompiled assets such as CSS or JavaScripts. This Directory also houses all of your languages
Files.

routes – The routes Directory Contains all of The Routes Definitions For your
Applications.

Storage – The Storage Directory Contain your Compiled Blade templates, Files based
Sessions , File caches , and other Files generated by the Frameworks.

test - The Test Directory Contain your Automated tests. This Will Contain the test Files.

Vendor – The Vendor Directory Contain your Composer dependencies. All


requirement That our project Should need be Exist in that Directory. This is the largest Folder
by the Size because it Contain lots of the packages.

app Directory

app – the app Directory Contain the source Code of your applications.
Console - The Console Directory contains all of your artisan commands.

53
Exception - The Exception directory Contains your application’s exception handler
and is also a good place to place any exceptions throws by your application.

http - The http Directory contains your controllers, middleware and requests.
Controller – It contain all Controller.

Middleware - It Contain all Middleware Files.

Models – The Models Directory contains all of your Eloquent models Classes.

Providers - The Providers Directory Contains all of the Service Providers For your
application.

Bootstrap Directory

Bootstrap - The bootstrap Directory Contains the [Link] Files Which


Bootstraps The framework.

cache – The cache Directory Which contains framework generated Files


For Performance Optimization such as the route and the Service Code Files.

Config Directory
54
Config - The Config Directory, as the name implies, Contain all Of your application’s
Configuration Files. All the Configurations Files Of our Directory Should be exist In that Folder.

database Directory

55
database – The database Directory contains Your Database Migrations, Model
Factories , and seeds. If you Wish, you may also use this Directory to Hold an SQLite
Database.

factories – It contain the All the Files of the Model Factories.


migration – The Migration Directory Contain the Migration Files.
seeders – Seeder Directory Contain All of the seeder Files.

Public Directory

public – the Public Folder Contain the [Link] File, Which is the entry point for all
requests entering your application and Configures autoloading. This Directory also houses your
assets such as images, JavaScripts, and CSS. It is the main and the Useful Directory in our
Project. In the Public Directory you Will not get the CSS, images and the JS Files By default.

56
resource Directory

resources - The resources Directory Contains Your view as well as your raw ,
uncompiled assets such as CSS or JavaScripts. This Directory also houses all of your languages
Files. Our HTML Code Should be Exist Inside that folder.

css – It Contain the css Files.


js – It Contain all Of the js Files (Javascript).
lang – It contain the language Files.
views – It Contain all the blade Php Files.
This is very important and the Useful Folder Of our project.

57
routes Directory
[Link] - The [Link] File Contains routes that the Route ServiceProvider place in the
api middle group, Which provides rate limiting. These routes are intended to be stateless, so
requests entering the application through these routes are intended to be authenticated via
tokens and will not have access to session state.

[Link] – The [Link] File in Where you may register all of the event
broadcasting channels that your application supports.

[Link] – The [Link] File is where you may define all of your closure
based console commands. Each closure is bound to a Command instances allowing a Simple
approach with each Command’s IO methods. Even though this File does Not Define HTTP
routes, It defines console based entery points (routes) Into your application.

[Link] – the [Link] contain routes that the routeserviceProvider places in the web
middleware group, Which provides session state, CSRF protection, and cookie encryption. If
your application does not offer a stateless. RESTful API,all of your routes will most likely be
define in the [Link] file. It is an important Files here we will define our when we start our
coding. Our Project Should be Start from that File.

Storage Directory

58
Storage – The Storage Directory Contain your Compiled Blade templates, Files based
Sessions , File caches , and other Files generated by the Frameworks.

app - The app Directory may be used to store any files generated by your application.

Public – The Public Directory may be used to store user-generated files, such as profile avatars,
that should be publicly accessible.

framework – the framework Directory is used to store framework generated files and caches.
logs – The logs Directory contain your Application log’s Files,
There are some following three folder which are very useful at the initial Stage.

Routing
There are some basic and important things inside The Laravel and routing is one of
them. if you have Grip on Routing then Laravel will be easy for you.

59
- First thing is Define the Route.
- Second thing Will be the view (How can we create the view OR [Link])
- How to Create the controller And how we can Write the Code inside the controller. And how to
join the controller, view and the route together.
- Controller ,view , route and the Model(Database) These Are the important Topics of the
Laravel.

“All Laravel Routes are defines in your Route Files, Which are Located in
The Routes Directory. Theses Files are automatically loaded by the
framework.”
All the Laravel routes are defined inside The route files. And route File is located inside the route directory.

The routes/[Link] file defines routes that are for your web interface. Inside the [Link]
We will define the route of our own Application.

For the most application you Will begin by defining routes in your routes/[Link]
files. Defining route will be the beginning step of our project/Application.

Syntax:
Route::get(‘URI’,Closure/Callback) // the r of the Route Should be Capital because it is the
class.

Example:
Route::get(‘about’, function(){

return “Hello world”;

});

Route returning String


Syntax:
Route::get(‘URI’,Closure/Callback);

Example:

60
Route::get(‘about’,function(){}

:: this Operator is called the scope resolution Operator.

Example:
Route::get(‘about’,function() {

Return “Hello World”;

});

Routes Parameter
In Simple Word meaning is that We will Define the parameter inside the routes.

Sometimes you will need to capture segments of the URI(user_Id) within your route. For
Example, you may need to capture a user’s ID from of the URL.

Syntax:
Route::get(‘uri/{p_para}’, function(Spara){

Return Spara;

});

Example:
Route::get(‘user/{u_id}’, Function($id) {

return $id;

});

Routes Multiple parameters


If we want to Route the Multiple parameter For that we will Write the Following Code.

61
Example:
Route::get(‘post/{post_id}/comment/{comment_id}’, function( $post_id, $comment_id ){

Return $post_id.$comment_id;

});

Note:-
Route parameters are always encased with {} braces and Should consist of alphabetic
characters, and may not contain a – character.

Optional Routes parameter


We can make an optional parameter by placing a? mark after the parameter name.

Example:
Route::get(‘student/{name?}’.function($name = null)
{
return $name;
});
Route::get(‘student/{name?}’.function($name = ‘Sonam’){
return $name;
})
// We can also pass integer here as a parameter in the place of the [Link] Simple
Words meaning is that here we are not restricte their [Link] can use any of
their datatype.

Routes parameter and Regular Expression


62
In the Regular Expression we will Declare Their particular Datatype.

You may Constrain the format of your parameters using the where method on a
route instance. The where method accepts the name Of the parameter and a regular
expression Defining how the parameter should be Constrained.

Syntax:-
Route::get(‘uri/{p_para}’,function($para){

return $para;

}) ->where(‘p_para’.’Regular Expression’);

Example:-
Route::get(’product/{p_name}’.function($name){

return $name;

})->where(‘p_name’.[A-Za-z])

[A-Za-z] This is the regular Expression. It Can Exist Any Value inside the small or the Capital.

Second Example With the multiple parameters:


Route::get(‘manager/{id}/{name}’.Function($id,$name){

return $id.$name;

}) where(‘id’=>’[0-9]+’ , ‘name’ => ‘[a-z]+’);

Route parameter with Regular Expression Helper Method


Laravel Language Give us the Facility of the helper method to Apply the regular Expression.

Route::get(‘user/{id}/{name}’.function ($id,$name){

//

})  whereNumber(‘id’) whereAlpha(‘name’);

63
(2)(Uuid)
Route::get(‘user/{id}’.function ($id){

//

})  whereUuid(‘id’)

Redirect Routes
If we redirect a route that redirect to another URL, you use the Route::redirect
method.

By default, Route::redirect return a 302 status Code.

Syntax:
Route::redirect(‘/here’,’/there’);

Example:
Route::redirect(‘/login-success’,’/dashboard’);

// That’s the Code to redirect them.

Syntax:
Route::redirect(‘/here’.’/there’,301);

// By default it’s status Code is 302 but you can Change it 301.

The Status Code of the Permanent redirect is 302 you can also use it.

Route::permanentRedirect(‘/here’,’/there’);
// Status Code Will Return Something On the basis Of that Status Code you Will perform Some
action.

// There are Different Status Code and on the basis of that Status Code you will perform the
specific Action.

64
Fallback Routes
Using the Route ::fallback method, you may define a route that will be Executed When no other route matches
the incoming request.

The fallback Route should always be the last route registered by your Application.

In Simple Words We can also called it as the backup Route when none Of the Route will be Occurred than that
Route Will be executed.

Example:
Route::fallback(function(){

// We can also Write here “Default page” OR “ Fault Tolerance”. When there is None page
Found that Statement Will be the executed.

});

Route Methods
There are Some Following Different route Methods.

o Route::get('URI’,Callback);
o Route::post(‘URI’,Callback);
o Route::put(‘URI’,Callback);
o Route::patch(‘URI’,Callback);

Using Multiple Match


If we want to use the multiple methods to gather For that we will match method .
Route::match([‘get’,’post’],’/’,function(){
// In this method you will Specifically define Which Of the methods Will be accepted by the route.

});

Route::any(‘/’,function(){

65
// In this method We can get Any method it Does not matter that method Will be
the Get, Post or another method.

});

Some Terminal Commands


cd command is used to move inside the particular Folder,
php artisan serve
After Running this Command It will give you the particular Server link on which your project is Running.

The Correct Command To Create the Laravel Project


composer create-project laravel/laravel:^10.0 example-app

huzaifanoor  routes  [Link] ( Here we will Start Our Work in Case if our Project is working Perfectly)

Role of the use keyword in PHP


In PHP, the "use" keyword is used to import namespaces or traits into the current scope. It allows you to access
classes, functions, or constants defined within those namespaces or traits without needing to fully qualify their
names.

[Link] Here Our Working will be Start Out


Route With String
Syntax:
Route::get(‘URI’,Closure/Callback);

Code(Route With String)


<?php

66
/* here it is importing the route Class Basically from that particular path*/
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
return view('welcome');
/* it is returning the view File From that Resources.*/
});

/* First of all we will see the route Returning String */


Route::get('about',function(){
return "Hello World";
});

OUTPUT
Write the command in URL
[Link]:8000/about

OUTPUT

Hello World

Route with Paramters


Syntax:
Route::get(‘uri/{p_para}’, function(Spara){

Return Spara;

});

67
Code([Link])
<?php

/* here it is importing the route Class Basically from that particular path*/
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
return view('welcome');
/* it is returning the view File From that Resources.*/
});

/* First of all we will see the route Returning String */


Route::get('about',function(){
return "Hello World";
});
/* Our Second method Will be the route Function with te parameter. */
Route::get('user/{u_id}', function($id){
return $id;
});

OUTPUT
The URI Command is the following because

[Link]:8000/user/933434

OUTPUT
933434

Route With Multiple parameters

68
Syntax:
Route::get(‘post/{post_id}/comment/{comment_id}’, function( $post_id, $comment_id ){

Return $post_id.$comment_id;

});

Code([Link])
<?php

/* here it is importing the route Class Basically from that particular path*/
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
return view('welcome');
/* it is returning the view File From that Resources.*/
});

/* Our third Method Will be the route With the multoiple paramteres */
Route::get('user/{u_id}', function($id){
return $id;
});

Route::get('post/{post_id}/comment/{comment_id}', function($post_id,$comment_id){
return "Post ID :". $post_id ."Comment ID :". $comment_id; /* For the
Concatenation we will use the dot (.) Operator */
});

OUTPUT
Command inside The URL:

69
[Link]:8000/post/933434/comment/2222111

( It is Necessary to Define their Values Inside the URL If Missed To Define One Of them either post OR
comment then it will Show the like this then it will Show the Following error.

[Link]:8000/post/933434/comment/

(these Parameters are Compulsory if we define the have Define the Route Function With the paramters. )

OUTPUT

Post ID :933434Comment ID :2222111

Routes With Optional parameter


Optional parameter mean’s that if we want to Skip one of the value of the parameter inside the
URL Then it will not Show us the (ERROR 404)

Syntax:
Route::get(‘student/{name?}’.function($name = null)
{
return $name;
});

70
Route::get(‘student/{name?}’.function($name = ‘Sonam’){
return $name;
})

Code([Link])
<?php

/* here it is importing the route Class Basically from that particular path*/
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
return view('welcome');
/* it is returning the view File From that Resources.*/
});

/* Our third Method Will be the route With the multoiple paramteres */
Route::get('user/{u_id}', function($id){
return $id;
});

Route::get('post/{post_id}/comment/{comment_id}', function($post_id,$comment_id){
return "Post ID :". $post_id ."Comment ID :". $comment_id; /* For the
Concatenation we will use the dot (.) Operator */
});

/* Creating a Name paramter as an Optional that Mean's you Can Also Skip The value
of the Column */
Route::get('student/{name?}', function($name = null){
return " Hello ".$name;
});

Route::get('student1/{name?}', function($name = “HUZAIFA NOOR”{


return " Hello ".$name;

71
});
/* If Did Not Write The value Of the name parameter then It will not Give the 404
Error on the
Screen because it is an Optional parameter. */

OUTPUT
URL Commands
[Link]:8000/student/

Second Command
[Link]:8000/student1/

OUTPUT
Hello

Hello HUZAIFA NOOR

Regular Expression in Routes


If we want to Apply Some Restriction on the Route that it will only be Entered A numeric Or it
will only be Entered An String value For that We will use the regular Expression inside The
Routes.

Syntax:
Route::get(‘user/{id}/{name}’.function ($id,$name){

//

})  whereNumber(‘id’) whereAlpha(‘name’);

Code([Link])
<?php

/* here it is importing the route Class Basically from that particular path*/

72
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('student/{name?}', function($name = null){


return " Hello ".$name;
});
/* If we want to Specify the particular Datatype of the Route For that We will use
the Regular Expression
inside the Routes. */
/* Decalring The number DataTypes OR Restricting the number Data Types. */
Route::get('manager/{id}/{name}',function($id,$name){
return " Manager Name:".$name."Manager ID :". $id;
/* In the Following Code we wil Apply the restriction Of their DataType.*/
})->where(['id'=>'[0-9]+','name'=>'[A-Za-z]+']);

OUTPUT
URL command:
Error Causing Commands Are the Following.

[Link]:8000/id/HUZaifaNoor123

OUTPUT

73
Correct URL Command:
[Link]:8000/manager/1931/HUZAIFANOOR

OUTPUT
Manager ID :1931Manager Name:HUZAIFANOOR

(If you Want to Change/ Restrict the Route For the particular Data Type For that We have the
Find Out the rajex of the particular Data With The help of that rajex We can Create the
regular Expression and With the help of the regular Expression we can Create the We Are able
to restrict Our datatype.)

Regular Expression With the helper Method


Syntax:
Route::get(‘user/{id}’.function ($id){

//

})  whereUuid(‘id’)

74
Code([Link])
<?php

/* here it is importing the route Class Basically from that particular path*/
use Illuminate\Support\Facades\Route;
use PhpParser\Builder\Function_;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
*/

/* Regular Expression With the helper Method */

Route::get('Empolee/{id}/{name}/{reg}', function($id,$name,$reg){
return "Emploee ID :"." Employee Name:".$name. $id." Registration No :".$reg;
})->whereNumber('id')->whereAlpha('name')->whereAlphaNumeric('reg');

OUTPUT
URL Command:
[Link]:8000/Empolee/1931/HUZAIFANOOR/2021uam1931

OUTPUT
Emploee ID : Employee Name:HUZAIFANOOR1931 Registration No :2021uam1931

Route Redirecting
Syntax:
Route::redirect(‘/here’,’/there’);

75
Code([Link])
<?php

/* here it is importing the route Class Basically from that particular path*/

use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Route;
use PhpParser\Builder\Function_;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
*/

/* Redirect Method in Route */


Route::redirect('yaha1','vaha1' ,301); //301 is The status Code For the redirecting
/* The status Code For the permanent Redirect */
Route::permanentRedirect('yaha2','vaha2'); /* Status Code For the Permanent Redirect
is 302 by Default */

OUTPUT
Before Redirecting URL Command:
[Link]:8000/yaha2

After Redirecting URL Command:


[Link]:8000/waha2

76
Route Fallback Method
Syntax:
Route::fallback(function(){

// We can also Write here “Default page” OR “ Fault Tolerance”. When there is None page
Found that Statement Will be the executed.

});

Code([Link])
<?php

/* here it is importing the route Class Basically from that particular path*/

use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Route;
use PhpParser\Builder\Function_;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These

77
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
*/

Route::get('name',function(){
return "HELLO HOW ARE YOU ??";
});

/*Fallback Methods inside the Route


the Fallback method Will Run When We hit Any URL Which is Not Present
*/
Route::fallback(function(){
return "Default Message";
});

OUTPUT
Correct URL Command:
[Link]:8000/name

OUTPUT
HELLO HOW ARE YOU ??

Incorrect URL Command:


[Link]:8000/about

OUTPUT

View
78
View Contain the HTML Served by your application and Separate your Application logic From your
Presentation Logic . Views are Stored in the Resources/Views Directory.

Creating View:
In the Following We will See how we can Create the View.

(Locations)  Resources/views/

(File Name)  [Link]

(File name Should be anything but their Extension(.[Link]) Whould be The same.
Because Laravel used a Template Whose name is the blading Template.)

In That File We will Write The Code is Same Like The HTML and the CSS.

<html>

<body>

<h1> Hello Laravel About me <h1>

</body>

</html>

Create Route For View


How we can Create a View For your Web Page. Why it is necessary to Create Route For the View. How your
Page([Link],php) Will be Shown At the Web browser.

 To Shown A Particular page in the Web browser There Should be the Route For The View. That’s Why we Should
have to Define The Route.

 Now we will See the syntax How We can Create the Route For Our Web Page.

Syntax:
Route::get(‘uri’, function(){return view(‘view_name’)});

(In The above We are Returning the Route From the String.)

Example:
Route::get(‘about’ function(){

79
return view(‘aboutme’);

})

//This Function is Returning a View Whose name is aboutme.

Location Of the view:


resources  views  [Link]
whenever user hit the URL (127:0.0.0:8000/aboutme) then it will able to See the view of The webpage. That’s
we define the Route For the Webpage.

Short Cut Method


If your method only need to Return the view For that We will use the Following Short Cut method.

Route::view
If you Want to build Some logics in your Route For that you Should not have to use the Short Cut [Link]
If your only purpose Is to Return the View For that you Will use this Short Cut method.

Syntax:
Route::view(‘uri’, ‘view_name’);

Example:
Route::view(‘about’,’aboutme’);

Creating view
resources/view/admin

admin is the Folder which is Created by the user. It is not the built-in Folder like the
Resources and the view.

resources/view/admin

[Link]

<html>

80
<body>

<h1> Hello Laravel Admin Panel </h1>

</body>

</html>

How will you define the Route when you Create your own Folder and Created your
View File In your own Folder. For that the Syntax of the View Should be
Following.

Syntax:
Route::get(‘uri’,function(){return view(‘folder_name.view_name’)});

Example:
Route::get(‘adminprofile’,function(){

return view(‘[Link]’);

});

If your Route only needs to return a View, You may use the Route::view Method.

Syntax:
Route::view(‘uri’, ‘folder_name.view_name’);

Example:
Route::view(‘adminprofile’,’[Link]’)

For the View Practical We will Do our Working In the two Files

 Welcome_blade.php ( resources(Folder)  view(Folder)welcome_blade.php)


 [Link] ( route(Folder)  [Link])

Command to Run the Server:


php artisan serve

81
Creating A new File inside the View Folder Whose name Will be the Following

[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>PHP View Practical</title>
</head>
<body>
<h1>Wellcome to the About Me View page </h1>
{{-- Now we Want to Define The Route So that we will see the Route On the screen
For That
we Should have to Define the particular Route. --}}
</body>
</html>

(Remember the File Extension is .[Link] Not only .php)


Creating the Route For the file inside the [Link] File that are exist
inside the Route(Folder).
<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
return view('welcome');
});

/* Here is the Following code in Which we are Creating the Route for the View
Route::get('about',function(){

82
return view('aboutme');
});
Here is the Following Shortcut Method For Definning the Route For the View
*/
Route::view('about','aboutme');

OUTPUT
URL Command:
[Link]:800//about

(In the Following We will See how we can Create the new Folder inside the View Folder Which
is the built-in Folder. Inside The View Folder we can Create the Different Folder For the
Different Functionality We will Create the Different Folders ).

View(Folder)admin(Folder)[Link](Folder)

[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Admin/Profile</title>
</head>
<body>
<h1> Wellcome to The Profile page Of the admin Folder.</h1>
</body>
</html>

[Link]
<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------

83
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
return view('welcome');
});

/* Here is the Following code in Which we are Creating the Route for the View
Route::get('about',function(){
return view('aboutme');
});
Here is the Following Shortcut Method For Definning the Route For the View
Route::view('about','aboutme');
Here we are Defining The Route For the [Link] page Which Exist inside the
admin Folder
*//*
Route::get('adminprofile',function(){
return view('profile');
});
If we will Define the [Link] Like this then it Will show the Following
Error
View [profile] not found.
Because that File Exist inside the admin Folder of the View Folder To Access that
File We
Should have to Give The proper location of that File.
like that's how We will Give their Location.
return view('[Link]');

*/
/* We can also Access the [Link] File of the admin Folder by the
shortcut method
Route::view('AdminProfile','[Link]');
*/
Route::get('adminprofile',function(){
return view('[Link]');
});

OUTPUT
URL Command:
[Link]:8000/AdminProfile/

84
OUTPUT
Wellcome to The Profile page Of the admin Folder.
Passing Data From Route to View
Now we will See how we can pass the Data From Route to the View.

The Data Should be an Array And the key/Value pair.

Inside your View, you can then access each Value using its Corresponding key.

Example 1:-
Route::get(‘contact’,function() {

return view(‘contactme’,[‘name’ => ‘HUZAIFANOOR’]);

// Here we are using the associative array And the key is “name” and the value is “HUZAIFANOOR”

});

With the Short Cut Method


Example 2:-
Route::view(‘contact’,’contactme’,[‘name’=>’HUZAIFANOOR’])

Passing the Data by “with” Method


You may use the with method to add individual pieces of Data to the View.

Example:
Route::view(‘contactme’)->with(‘name’,’HUZAIFANOOR’)

});

Accessing Data Which is passed From Route to View

85
To Access the Data We have passed Which is passed From Route to View For that we will
use The {{$key }}.

Example:
<h1>Hello {{$name}}</h1>

Creating a new File inside the View Folder Whose name is the
[Link]

[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1> Welcome to the Contact page of the View Folder </h1>
{{-- here we are accessing the Data from the Route the View --}}
<h1>My name is {{$name}}</h1>
<h1>My Age is {{$age}}</h1>
</body>
</html>

[Link]
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/
Route::get('/', function () {

86
return view('welcome');
});

/* now we Will how we can pass the Data From Route To the View
Route::get('contact',function(){
return view('contact',['name'=>'HUZAIFANOOR']);
// here we will use the associative Array in keys and the value pair
});
Now we will See how We can pass the Data From Route to the View With the Short Cut
method
We Are also passing the multiple Data From Route to the View
*/
Route::view('contact','contact',['name'=>'HUZAIFANOOR','age'=>'21']);

OUTPUT
URL Command:
[Link]:8000/contact

OUTPUT
Welcome to the Contact page of the View Folder
My name is HUZAIFANOOR
My Age is 21
Passing the data by “With ” Method
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

87
Route::get('/', function () {
return view('welcome');
});

/* now we Will how we can pass the Data From Route To the View
Route::get('contact',function(){
return view('contact',['name'=>'HUZAIFANOOR']);
// here we will use the associative Array in keys and the value pair
});
Now we will See how We can pass the Data From Route to the View With the Short Cut
method
Route::view('contact','contact',['name'=>'HUZAIFANOOR','age'=>'21']);*/

Route::get('contact',function(){
return view('contact')->with('name','sonam');
});

OUTPUT
URL Command:
[Link]:8000/contact

OUTPUT
Welcome to the Contact page of the View Folder
My name is HUZAIFANOOR
My Age is 21
Now we will See how you Can Return OR Pass the Data When we have the Paramters inside the view.

Passing Parameter inside the view


[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

88
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1> Wellcome to the My User page Of the View Folder.</h1>
<h1> The ID of My User is {{$id}} </h1>
</body>
</html>

[Link]
<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
return view('welcome');
});
/* Now we will See how we can Return View From the Route. */
Route::get('about',function(){
return view('aboutme');
});
/* Now we will How We can Return the View With the parameters */
Route::get('user/{u_id}',function($id){
/* We can pass the Data in View in two Form First in the Form of the array and
Pass the data With "with" method */
return view('myuser',['id'=> $id]);
});

OUTPUT
URL Command:
[Link]:8000/user/927333

89
OUTPUT
Wellcome to the My User page Of the View Folder.
The ID of My User is 982783
Multiple parameter inside the view
[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1> Wellcome to My POst Page Of the view Folder</h1>
<h1> The POST ID : {{$post_id}}</h1>
<h1> The Comment ID : {{$user_id}}</h1>
</body>
</html>

[Link]
<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {

90
return view('welcome');
});
/* Now we will See how we can Return View From the Route. */
Route::get('about',function(){
return view('aboutme');
});
/* Now we will How We can Return the View With the parameters */
Route::get('user/{u_id}',function($id){
/* We can pass the Data in View in two Form First in the Form of the array and
Pass the data With "with" method */
return view('myuser',['id'=> $id]);
});
/* Now we will See how we can pass the multiple parameters to the Views */
Route::get('post/{pt_id}/{user_id}',function($pid,$uid){
/* We can pass the Data in View in two Form First in the Form of the array and
Pass the data With "with" method */
return view('mypost',['post_id'=> $pid,'user_id'=>$uid]);
});

OUTPUT
URL Command:
[Link]:8000/post/1232/232322

OUTPUT
Wellcome to My POst Page Of the view Folder
The POST ID : 1232
The Comment ID : 232322
Optional parameter with View
[Link]
<!DOCTYPE html>
<html lang="en">
<head>

91
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1> Wellcome to the Mystudent File Of the View project.</h1>
<h1> My name is {{$name}}</h1>
</body>
</html>

[Link]
<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
return view('welcome');
});
/* Now we will See how we can Return View From the Route. */
Route::get('about',function(){
return view('aboutme');
});
/* Now we will How We can Return the View With the parameters */
Route::get('user/{u_id}',function($id){
/* We can pass the Data in View in two Form First in the Form of the array and
Pass the data With "with" method */
return view('myuser',['id'=> $id]);
});
/* Now we will See how we can pass the multiple parameters to the Views */
Route::get('post/{pt_id}/{user_id}',function($pid,$uid){
/* We can pass the Data in View in two Form First in the Form of the array and
Pass the data With "with" method */
return view('mypost',['post_id'=> $pid,'user_id'=>$uid]);
});

92
/* Now we will See the Optional parameter With the View */
Route::get('student/{name?}',function($name = null){
return view('mystudent',['name'=>$name]);
});

OUTPUT
URL command:
[Link]:8000/student/

OUTPUT
Wellcome to the Mystudent File Of the View project.
My name is
URL command:
[Link]:8000/student/HuzaifaNoor

OUTPUT
Wellcome to the Mystudent File Of the View project.
My name is HuzaifaNoor

Regular Expression in View


[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>

93
</head>
<body>
<h1> Wellcome to the Product File Of the view </h1>
<h1>Product Name : {{$name}} </h1>
<h1>Product ID : {{$id}} </h1>
</body>
</html>

[Link]
<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
return view('welcome');
});
/* Now we will See how we can Return View From the Route. */
Route::get('about',function(){
return view('aboutme');
});
/* Now we will How We can Return the View With the parameters */
Route::get('user/{u_id}',function($id){
/* We can pass the Data in View in two Form First in the Form of the array and
Pass the data With "with" method */
return view('myuser',['id'=> $id]);
});
/* Now we will See how we can pass the multiple parameters to the Views */
Route::get('post/{pt_id}/{user_id}',function($pid,$uid){
/* We can pass the Data in View in two Form First in the Form of the array and
Pass the data With "with" method */
return view('mypost',['post_id'=> $pid,'user_id'=>$uid]);
});
/* Now we will See the Optional parameter With the View */
Route::get('student/{name?}',function($name = null){
return view('mystudent',['name'=>$name]);
});

94
/* Now we will See the Regular Expression in View
Route::get('product/{id}/{name}',function($id,$name){
return view('myproduct',['id' =>$id,'name'=>$name]);
})->where(['id'=>'[0-9]+','name'=>'[A-Za-z]+']);
Second method of the Regular Expression is the Following */
Route::get('product/{id}/{name}',function($id,$name){
return view('myproduct',['id' =>$id,'name'=>$name]);
})->whereNumber('id')->whereAlpha('name');

OUTPUT
URL command:
[Link]:8000/product/122/HUZaifaNoor

OUTPUT

Redirecting in View
[Link]

95
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>Welcome to the Login page Of the View Folder</h1>
</body>
</html>

[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>Welcome to register page of the View Folder</h1>
</body>
</html>

[Link]
<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
return view('welcome');

96
});
/* Now we will See the redirecting of the view */
/* First of All we Will define their URI then After we will Redirect it*/
Route::view('login','mylogin');
Route::view('register','register');
/* Now we are redirecting the view */
Route::redirect('login','register');

OUTPUT
URL command:
[Link]:8000/login
(if we Write the Login([Link]:8000/login) then it will redirect it to the register View)

OUTPUT
Welcome to register page of the View Folder

Fallback message in View


[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1> Wellcome to the My default Page Of the View Folder </h1>
</body>
</html>

[Link]
<?php

97
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
return view('welcome');
});
/* Now we will See the redirecting of the view */
/* First of All we Will define their URI then After we will Redirect it*/
Route::view('login','mylogin');
Route::view('register','register');
/* Now we are redirecting the view */
Route::redirect('login','register');
/* Now we will See the fallback method inside The View Which return a Default View
Whenever user entered
a random View OR any Error */
Route::fallback(function(){
return view('mydefault');
});

OUTPUT
URL command:
[Link]:8000/register2349823 (Remember this is a Random Command Which Was Randomly input by the user)

OUTPUT
Wellcome to the My default Page Of the View Folder

Terminal Command For Laravel Version


98
php artisan --version

Terminal Command To Create Controller:


php artisan make:controller HomeController

Controllers
Controllers can Group related request handling logic into a Single Class, Instead of Defining All of
your request handling Logic as Closures in Routes Files, you may Wish to Organize this behavior Using
Controller Classes.

In Simple Words Controller is a Class Where you Can Write your business Logic.

The Controller are Stored/Located in the app/http/Controllers directory.

Controller extends the base Controller Class included with Laravel.

Routes/[Link]

Routes::get(‘about’,function() {  Routes

return views(‘aboutme’. [‘name’ => ‘Huzaifa’]);

});

resources/views/[Link]
<h1> Hello Laravel {{name}} </h1>  View

Now instead of Returning View From the Route We will Return the Controller Which Will Controle the View.

Defining Controller Class


To Create the Controller Class you have to Run the Following Command Which is the.

php artisan make:controller controller_name


Example:
php artisan make:controller aboutController

99
(It is Good Approach to Write the name of the Contrller In the Camel case)

After Running that Command the File Will be Created inside the Folder.

app/http/Controllers

( This File Contain Some basic Codes. Like in the Following.)

<?php

namespace App/http/Controllers;

use Illuminate\Http\Requests;

class AboutController extends Controller

………………………………..

(The basic Code For the Controller is already Written inside The File Whenever you hit the Command to Create
the Controller.)

Creating Route For Controller Class


Route Will go to the Controller And From that Controller we will Create the View.

app/Http/Controllers

[Link]

(This File Contain the Following Code.)


<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

100
/* In the Following We are Created a method Which We will Return inside ethe
Route.*/

class AboutController extends Controller

function show();

return “ Hello Controller”;

?>

Location Of the Route is Following.


routes/[Link]
/* In the Following Code we are importing the Controller. It is necessary to import the Controller If we want to
use the Controller.*/

use App\Http\Controllers\AboutController.
Route::get(‘about’.[AboutController::class, ’show’]);

Syntax:
Route::get(‘uri’,[ControllerName::class, ‘method_name’]);

Getting Parameter in Controller


app/Http/Controllers

[Link]

<?php

namespace App/Http/Controllers;

101
use App\Http\Controllers\Controller;

use illuminate\Http\Request;

class AboutController extends Controller

function show($name){

return “Hello Controller”.$name;

Defining the Route For The parameter Controllers


route/[Link]

use App\Http\Controllers\AboutController;

Route::get(‘about/{name}’),

[ AboutConotroller::class , ‘show’]);

Practical of the Controller with parameter and With String

Terminal Command to Create the Controller


Php artisan make:controller AboutController
App  Http  [Link]

[Link]
<?php

/* Here we are Creating a namespace */


namespace App\Http\Controllers;

/* here We are importing a particular request*/


use Illuminate\Http\Request;

102
/* Here We got the about Controller Class */
class AboutController extends Controller
{
// Creating a Method Which Will Do the Controller Returning String
function show(){
return "Hello Controller";
}
}

[Link]
<?php

use Illuminate\Support\Facades\Route;
/* it is neceassary to import The Controller Which We are trying to use
in the Following we are Giving the Location Of that Controller */
Use App\Http\Controllers\AboutController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
return view('welcome');
});
/* Now we are Defining the Route For the Controller
And Returning the Controller with String */
Route::get('about',[AboutController::class,'show']);

OUTPUT
URL Command:
[Link]:8000/about

OUTPUT

103
Hello Controller

Controller With parameter


[Link]
<?php

/* Here we are Creating a namespace */


namespace App\Http\Controllers;

/* here We are importing a particular request*/


use Illuminate\Http\Request;

/* Here We got the about Controller Class */


class AboutController extends Controller
{
// Creating a Method Which Will Do the Controller Returning parameter with String
/* There is no Restriction that the name(parameter) inside The RouteWould be the
Same with the parameter inside the That Function */
function show($nm){
return "Hello Controller ".$nm;
}
}

[Link]
<?php

use Illuminate\Support\Facades\Route;
/* it is neceassary to import The Controller Which We are trying to use
in the Following we are Giving the Location Of that Controller */
Use App\Http\Controllers\AboutController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
return view('welcome');

104
});
/* Now we are Defining the Route For the Controller
And Returning the Controller parameter with the String */
Route::get('about/{name}',[AboutController::class,'show']);

OUTPUT
URL Command:
[Link]:8000/about/HUZAIFANOOR

OUTPUT
Hello Controller HUZAIFANOOR

Returning View From Controller


Class
Now we Will See how we Can return the Route From the Controller and From the
Controller how Can We will return the View.

Route  Controller  View


Code
app/Http/Controllers
[Link]
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class AboutController extends Controller
{
function show(){
return view(‘aboutme’)

105
}
}

Defining their Route


Routes/[Link]
Use App\Http\Controllers\AboutController
Route::get(‘about’ , [AboutController::class, ‘show’]);

Defining their View


resources/views/
[Link]
<html>
<body>
<h1> About me from Controller </h1>
</body>
</html>

Code Execution Flow


Route  Controller  View
Returning View from Controller
Class
app/Http/Controllers
[Link]
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

106
class AdminProfileController extends Controller
{
function show_profile(){
return view(‘[Link]’)
}
}

Defining their Route


Routes/[Link]
use App\Http\Controllers\AdminProfileController;
Route::get(‘profile’,[AdminProfileController::class, ‘show_Profile’]);

Defining their View


resources/views/admin/
[Link]
<html>

<body>

<h1> About me from Controller </h1>

</body>

</html>

Here basically We are Returning The View From the


SubFolder For that We also have to mentioned the
name of the SubFolder.

Route  Controller  View


RouteFile([Link])
<?php

use Illuminate\Support\Facades\Route;
/* it is neceassary to import The Controller Which We are trying to use
in the Following we are Giving the Location Of that Controller */

107
Use App\Http\Controllers\AboutController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
return view('welcome');
});

/* here We are Returning the Controller through the Route */


Route::get('about',[AboutController::class,'show']);

ControllerFile([Link])
<?php

/* Here we are Creating a namespace */


namespace App\Http\Controllers;

/* here We are importing a particular request*/


use Illuminate\Http\Request;

/* Here We got the about Controller Class */


class AboutController extends Controller
{
/* here We are Creating the Function Whhich Will Be Returned With the Help pf the
Route*/
function show(){
/* this Function Will Return the View */
return view('aboutme');
}
}

ViewFile([Link])
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

108
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>About ME page</title>
</head>
<body>
<h1> WelCome to the about me page. </h1>
</body>
</html>

OUTPUT
URL Command:
[Link]:8000/about

OUTPUT
WelCome to the about me page.
What If your View File Exist inside a particular Sub Directory??
For that you Will write the Following method OR The Code.

RouteFile([Link])
<?php

use Illuminate\Support\Facades\Route;
/* it is neceassary to import The Controller Which We are trying to use
in the Following we are Giving the Location Of that Controller */
Use App\Http\Controllers\AdminProfileController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {

109
return view('welcome');
});
/* Here We are Creating the route For he Controller.
And that Controller be handled the View that Exist inside the Sub-Directory */
Route::get('profile',[AdminProfileController::class,'show_profile']);

ControllerFile([Link])
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class AdminProfileController extends Controller


{
/* First Of all We will have to return that Controller to route
After that we will Create the function For the Controller
*/xxxxxxxxxxxxxxxxxxxxxxxxxx
function show_profile(){
return view(' [Link]') ;
}
}

ViewFile()
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class AdminProfileController extends Controller


{
/* First Of all We will have to return that Controller to route
After that we will Create the function For the Controller */
function show_profile(){
return view(' [Link]');
}
}

OUTPUT
URL Commands:

110
[Link]:8000/profile

OUTPUT
Wellcome to the Admin Profile page
@crf token that are used For The post Function
CRTL + D
@if()
@endif()
dd() Which Will try To Catch the debugging.
Getting URL parameter in Controller Class
and Passing to View
Defining Controller
app/Http/Controllers

[Link]

<?php

namespace App/Http/Controllers;

use App\Http\Controllers\Controller;

use illuminate\Http\Request;

class AboutController extends Controller

111
function show($name){

return view(‘aboutme’.[‘nm’ => $name])

Defining Routes
routes/[Link]

use App\Http\Controllers\AboutController;

Routes::get(‘about/{name}’),

[AboutController::class.’show’]);

Defining View
resources/views/

[Link]

<html>

<body>

<h1>{{$nm}} me From Controller <h1>

</body>

</html>

Execution Flow
Route  Controller  View

Practical of Passing parameter Inside RCV


ControllerFile([Link])

112
<?php

/* Here we are Creating a namespace */


namespace App\Http\Controllers;

/* here We are importing a particular request*/


use Illuminate\Http\Request;

/* Here We got the about Controller Class */


class AboutController extends Controller
{
/* Controller returning View With Parameter. */
function show($name){
/* Here It will passing the name as a parameter */
return view('aboutme' , ['nm' => $name]);
}
}

RouteFile([Link])
<?php

use App\Http\Controllers\AboutController;
use Illuminate\Support\Facades\Route;
/* it is neceassary to import The Controller Which We are trying to use
in the Following we are Giving the Location Of that Controller */
Use App\Http\Controllers\AdminProfileController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
return view('welcome');
});

Route::get('about/{name}',[AboutController::class,'show']);

ViewFile([Link])
113
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>About ME page</title>
</head>
<body>
<h1> WelCome to the about me page. </h1>
<h1> My name is {{$nm}} </h1>
</body>
</html>

OUTPUT
URL Command:
[Link]:8000/about/HUZAIFANOOR

OUTPUT
WellCome to the about me page.

My name is HUZAIFANOOR

Passing data From Controller to View


Defining Controller
app/Http/Controllers

[Link]

<?php

namespace App/Http/Controllers;

use App\Http\Controllers\Controller;

use illuminate\Http\Request;

114
class AboutController extends Controller

function show(){

$name = ‘Laravel’;

return view(‘aboutme’,[‘nm’ => $name])

Defining Routes
routes/[Link]

use App\Http\Controllers\AboutController;

Routes::get(‘about’),[AboutController::class,’show’]);

Defining View
resources/views/

[Link]

<html>

<body>

<h1>{{$nm}} me From Controller <h1>

</body>

</html>

Practical of Passing the data in RCV


RouteFile([Link])
<?php

115
use App\Http\Controllers\AboutController;
use Illuminate\Support\Facades\Route;
/* it is neceassary to import The Controller Which We are trying to use
in the Following we are Giving the Location Of that Controller */
Use App\Http\Controllers\AdminProfileController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
return view('welcome');
});

/* Passing the Data Inside The RCV */


Route::get('about',[AboutController::class,'show']);

ControllerFile([Link])
<?php

/* Here we are Creating a namespace */


namespace App\Http\Controllers;

/* here We are importing a particular request*/


use Illuminate\Http\Request;

/* Here We got the about Controller Class */


class AboutController extends Controller
{
/* Controller returning View With Parameter. */
function show(){
/* Passing the Data From the Controller to View */
$name = 'HUZAIFA';
return view('aboutme', ['nm'=>$name]);
}
}

ViewFile([Link])

116
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>About ME page</title>
</head>
<body>
<h1> WelCome to the about me page. </h1>
<h1> My name is {{$nm}} </h1>
</body>
</html>

OUTPUT
URL Command:
[Link]:8000/about (We Are not passing parameter inside the URL)

OUTPUT
WelCome to the about me page.
My name is HUZAIFA
Multiple Methods inside the Controller
Defining Controller
app/Http/Controllers

[Link]

<?php

namespace App/Http/Controllers;

use App\Http\Controllers\Controller;

use illuminate\Http\Request;

117
class AboutController extends Controller

function show1(){

return view(‘aboutme’);

function show2(){

return view(‘aboutme’);

Defining Routes
routes/[Link]

use App\Http\Controllers\AboutController;

Routes::get(‘about1’),[AboutController::class,’show1’]);

Routes::get(‘about2’),[AboutController::class,’show2’]);

Defining View
resources/views/

[Link]

<html>

<body>

<h1>{{$nm}} me From Controller <h1>

</body>

</html>

118
resources/views/

[Link]
<html>

<body>

<h1>{{$nm}} me From Controller <h1>

</body>

</html>

Practical of the multiple Controller Methods

RouteFiles([Link])
<?php

use App\Http\Controllers\AboutController;
use Illuminate\Support\Facades\Route;
/* it is neceassary to import The Controller Which We are trying to use
in the Following we are Giving the Location Of that Controller */
Use App\Http\Controllers\AdminProfileController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
return view('welcome');
});

/* Passing the Data In multiple parameters inside the RCV */

119
Route::get('about1',[AboutController::class,'show1']);
Route::get('about2',[AboutController::class,'show2']);

ControllerFile([Link])
<?php

/* Here we are Creating a namespace */


namespace App\Http\Controllers;

/* here We are importing a particular request*/


use Illuminate\Http\Request;

/* Here We got the about Controller Class */


class AboutController extends Controller
{
/* We will see the multiple methods inside the Controller */
function show1(){
return view('aboutme');
}
function show2(){
return view('aboutyou');
}

ViewFirstFile([Link])
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>About ME page</title>
</head>
<body>
<h1> WelCome to the about me page. </h1>
<h1> My name is {{$nm}} </h1>
</body>
</html>

ViewSecondFile([Link])

120
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1> WelCome to the about You Page </h1>
</body>
</html>

OUTPUT
URL Command:
[Link]:8000/about1

OUTPUT
WelCome to the about me page.
URL Command:
[Link]:8000/about2

OUTPUT
WelCome to the about you page.

Single Action Controller


If you would like to define a Controller That only handles a Single Action, you may place a Single __invoke
method on the controller. To Generate this File run:-

php artisan make::controller ShowAbout –invokable

Controller Code
121
app/Http/Controllers/Show/[Link]

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;

class showAbout extends Controller

function __invoke(Request $request){

return view(‘aboutme’);

Route Defining
routes\[Link]

use App\Http\Controller\ShowAbout;

Route::get(‘about’,ShowAbout::class);

View Defining
resources/views/

[Link]

<h1> Hello About Me page </h1>

Practical part of the invokeable Function


RouteFile([Link])
<?php

use App\Http\Controllers\AboutController;
use Illuminate\Support\Facades\Route;

122
/* it is neceassary to import The Controller Which We are trying to use
in the Following we are Giving the Location Of that Controller */
Use App\Http\Controllers\AdminProfileController;
/* It is necassary To import The invoke Function For the perfectly Runing Of the
Code. */
use App\Http\Controllers\ShowAbout;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
return view('welcome');
});

/* Defining the Route For the invokeable Function */


Route::get('about',ShowAbout::class);

ControllerFile([Link])
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ShowAbout extends Controller


{
/**
* Handle the incoming request.
*/
public function __invoke(Request $request)
{
/* This invoke Function is returning thr view */
return view('aboutme');
}
}

ViewFile([Link])
123
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>About ME page</title>
</head>
<body>
<h1> WelCome to the about me page. </h1>

</body>
</html>

OUTPUT
URL Command:
[Link]:8000/about

OUTPUT
WelCome to the about me page.
All the Bussiness Logic Should be Exist inside the Controller and The View will be
only used For the Presentation

Blade
Blade is the Simple, yet powerful templating Engine that is included with
Laravel. Unlike Some PHP templating engines, Blades does not restrict you From
Using plain PHP Code In your templates.

Blade Template File use the .[Link] File Extension and typically stored in
the resources/views Directory

124
(Insidethe blade File you can Also use the plain_PHP Code And Also use the
HTML and the CSS Code blade File Will basically provide you the Overview of
Our page )

Blade Template
Displaying Data - you may display data that is passed to your Blade views by wrapping the
variable the variable in Curly braces.

Blade’s {{}} echo statements are automatically sent through PHP’s htmlspecialchars function
to prevent XSS attacks.

Example:-
{{name}}

Not only showing the values Of the variable’s.

Calling Function - you may also echo the results of any PHP Function by wrapping the
Function name in curly braces.

Like inside the Double Quotes We will insert the Code HTML inside the PHP. In that we will
use the {{}} To insert the PHP code Inside the Laravel.

Example:
{{time()}}
Note:-
You can Put any PHP code you Wish Inside of a Blade echo Statement.

Comment
When we are using the blade File We will see how Can we write the comment
inside the blade File.

125
The Blade File also allow you to define Comments in your Views. However,
unlike HTML comments are not Include in the HTML returned by your
Application.

There are the Following Way We Write the Comment inside the blade File.

{{ -- This Comment Will Not present in the rendered HTML. --}}

Conditional Directives
 Condition Directives For the if Statements Will be With the @ symbol ,..

@if(Condition)

……………

@endif

 Condition Directives for the if else Statement Will be the Following .

@if(condition)

…………………….

@else

…………………

@endif

 if…. Elseif…..else How can we write the else elseif directives In Blade file

@if(Condition)

…………..

@elseif(Condtion)

……………….

else

……….

126
@elseif

 Unless Directives For the Conditional Directives.


 @unless (condtion)
 ……………..
 @endless
 Isset Directive will be the Following
 @isset (var)
 ……………..
 @endisset
 We can Write the Empty Directives.
 @empty (var)
 ………………..
 @endempty

Authentication Directives
Authentication directives Were basically Used for the Lgoin and Logout page
Authentication.

@auth

// User is Authenticated

@endif

Guest Directives Should be the Following.

@guest

//If Our User is Authenticated then It will be satisfied as the Guest

@endguest

 Auth Directives Should be the following.

@auth('admin’)

// user is Authenticated by the admin

@endif

127
 If the User is not Authenticated then We should Have to Give the Guest
Command. Guest Directives Should be The Following.

@guest (‘admin’)

// User is not authenticated

@endguest

Enviroment Directives
 If we want to Execute Some Code inside The Production For that We
will use the production Directives.
 @prodution

// this Code Will only be Executed When you put your Code Inside
The production. This Code Will not run inside The development.

@endproduction

 We can Also Specific Our environment By using The following


directives(If the User exist inside the Specific Environment then we
should have to Run that Code otherwise it Should have to Show the
Error to the user.).
 @env('env_name’)

// running in env_name

@endenv

 You can also Specify the Multiple Environments By the Following


Directives .

@env([‘env1’,’env2’])

// if our Code Is running in One of that Applications then We


should have to Run that Code.

@endenv

128
Switch Directives
In the Switch Statement the Expression and The cases are Exist. Basically We
will write the Cases On the basis of these Cases they Will match the
Expression.

 @switch(Expression)
@case(Expression 1)

……………

@break

@case(Expression 2)

// If the Above Statement will not Satisfy the Case1 Expression then it will Check out
the case2 Expression.

@break

@case(Expression 3)

……………

@break

@default

// If our Switch Statement Will Not Satisfy all Of the case’s Expression then it Will Run Out
the default Statement.

@endswitch

Loop Directives
There are Lots Of The Directives For The Loop’s.

For loop Directives Should be the Following.


@for( initial; condition; incr/decri )

129
………………………..

@endfor

Foreach Directives Should be The Following.


@foreach (array_name as value)

// every Element Of an Array Should be Gone inside the array And you can print that
value.

@endforeach

Forelse Directives should be the following.


@forelse (array_name as values)

//If Any value Exist inside The array then it Will go inside the loop. Else it will Go inside
the @empty

@empty

…………………….

@endforelse

While Loop Directives Should be the Following.


@while( condition)
…………………….

@endwhile

Note:- We can also Do the nested loop Directives inside The blade of the
Laravel.

Break and Continue Directives


We can Also do the break and The Continue Directives inside the blade Of the Laravel. The
break Will be the terminating Of the Statement and Continue Will said to be the Skipping The o
particular code OR the statement.

130
Break Directives Should be The Following.
@foreach(array_names as values)
…………………..

@if(Condition)

@break

@endif

………………..

@endforeach

Continue Directives Should be The Following.


@foreach (array_name as value)

……………………

@if(Condition)

@continue

@endif

…………………….

@endforeach

We can also Write the break And the Continue Statements


With out using the If.
@foreach(array_names as values)
…………………..

@break(Condition)

@endif

131
………………..

@endforeach

We can also Write the Continue Statement like the above.


@foreach (array_name as value)

……………………

@if(Condition)

@continue

@endif

…………………….

@endforeach

Loop variables
A $loop variable will be available inside of your Loop. This variable provides
access to some useful bits of information such as the Current Loop index and
whether this is the First or last Iteration through the Loop.

Example:-
@foreach($users as $user)

@if ( $loop -> first)

// this Loop variable Will automatically recognize the particular loop is the First
loop OR not if The particular loop is the first then it will Run out that Condtion.

@endif

If you want to use The $loop variable inside the nested Loop for
that you should have to use the parent property.

132
Example:-
@foreach($user as $user)

@foreach ($user-> posts as $post)

@if ($loop->parent-first)

@endif

@endforeach

@endforeach

There are some Following Properties of The loop


Variable.

Displaying the data


Route Files

133
<?php

use Illuminate\Support\Facades\Route;

Route::get('/', function () {
return view('welcome' , ['name' => 'HUZAIFA NOOR']);
});

(view)Blade File
<!DOCTYPE html>

<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1> Wellcome</h1>
{{-- Displaying the Data
for Displaying That data We should have to Define That particular Data. --}}
<h1> {{$name}} </h1>
</body>
</html>

OUTPUT
Wellcome
HUZAIFA NOOR
Returning the View With Controller
Route File
<?php

use Illuminate\Support\Facades\Route;
/* If we want to use the particular Controller for That we will import that
Controller*/

134
use App\Http\Controllers\forview;

Route::get('/', function () {
return view('welcome' , ['name' => 'HUZAIFA NOOR']);
});
/* Here we arre dfining The route for The Controller */
Route::get('contact', [forview::class, 'show']);

Controller File
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class forview extends Controller


{
// Now we are Creating The method according To The route We have Defined
function show() {
return view('contact');
}
}

View File
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1> Wellcome Contact blade File....</h1>
</body>
</html>

OUTPUT
URL Command:

135
[Link]:8000/contact

OUTPUT
Wellcome Contact blade File...
View/Blades Directives and Properties practical
Routes File([Link])
<?php

use Illuminate\Support\Facades\Route;
/* If we want to use the particular Controller for That we will import that
Controller*/
use App\Http\Controllers\forview;

Route::get('/', function () {
return view('welcome' , ['name' => 'HUZAIFA NOOR']);
});
/* Here we arre dfining The route for The Controller */
Route::get('contact', [forview::class, 'show']);

Controller File([Link])
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class forview extends Controller


{
// Now we are Creating The method according To The route We have Defined
function show() {
/* Passing The data With the Controller */
$name = 'HUZAIFA';
$nam1 = 'HAMZA';
$nam2 = 'K';
$nam3 = '';
/* Passing Array to blade file */
$CARS =
['HONDA','HYUNDIA','SUZUKIE','ALTO','KIA','FORD','LEXUSUS','BMW','AUDI','MERCEDIES'];

136
$C =
['HONDA','HYUNDIA','SUZUKIE','ALTO','KIA','FORD','LEXUSUS','BMW','AUDI','MERCEDIES'];
$NO = [];
return view('contact' , ['nm' => $name,'KP' => $nam1,'KP2' => $nam2,'KP3' =>
$nam3 ,'companies'=> $CARS ,'NAA' => $NO ,'CC' => $C]);
}
}

[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1> Wellcome Contact blade File....</h1>
<h2>My name is {{$nm}}</h2>
{{-- calling the Function Inside The blade File --}}
<h2>current Time : {{time()}}</h2>
{{-- calling The Math Function --}}
<h2> Square Root of 493 : {{sqrt(493)}} </h2>
{{-- Now we will See The Conditional Directives inside the blade file --}}
@if($nm == 'HUZAIFA')
<h1> HELLO!! {{$nm}}</h1>
@endif
{{-- Now we will See the if else Condition Directives inside the blade File --}}
@if($KP == 'aa')
<h1> HELLO!! {{$KP}}</h1>
@else
<h1> I can't Recognize you!!!</h1>
@endif

{{-- Now we will See the Directives of the if elseif else inside the blade File
--}}
@if($KP2 == 'HAss')
<h1> HELLO!! {{$KP2}}</h1>

{{-- If the Above Condition Will be true then it will not check out the Further
Conditions --}}
@elseif($KP == 'HAMZA') {{-- that Condition is TRUE --}}
<h1> I Recognize you!!! Your Name is MR.{{$KP}}</h1>
@else
<h1> Sorry !! I can't recognize You </h1>

137
@endif

{{-- Now we will See the unless Directives inside the blade file --}}
@unless($KP == 'HAKDJA')
{{-- Unless mean's If the condition inside the unless Will TRUE then the Code
inside the
unless Will not be Executed. Like So, if the Condtion inside the unless will be
FALSE then the
Code inside The unless Will be Executed. --}}
<h2> YOUR UNLESS CONDITION IS FALSE </h2>
@endunless

{{-- Now we will See the isset Directives Inside the Blade File
Inside the isset we are basically checkin out that the Specific variable Contain
that value OR not --}}
@isset($nm)
<h1> YES!! A VALUE IS SET INSIDE THE VARIABLE </h1>
@endisset

{{-- Now we will see the Empty Directives inside the Blade File
Empty Directives Will basically Check pout that our particular vairable is Empty
OR Not?? --}}
@empty($KP3)
<h1> Your variable is EMPTY</h1>
@endempty

{{-- Now we will See the Production Directives the production Directives Will be
Executed When We are inside the
Production.
--}}
@production
<h1> You are inside the Production </h1>
{{-- We Are inside the Develoopment So that Code Will not be Executed --}}
@endproduction

{{-- If we want to Execute A Particular Code on the Specific Enviroment For that
We will Write the Following Directive --}}
@env('local')
{{-- Recently we are inside the local Enviroment That's we have written local
inside the Condition Of that Enviroment --}}
<h1>You Are inside the Local Enviroment </h1>
@endenv
{{-- If We want to Write the Condition for the Multiple Enviroments for that We will
Use the Following Directives --}}

@env(['local','staging'])
<h1> YOU ARE INSIDE THE LOCAL OR STAGING ENVIROMENT </h1>
@endenv

138
{{-- Now we will See the Directives of the Switch cases --}}
@Switch( 'ADMIN')
@case(1)
<h2> Your First Case is TRUE</h2>
@break
@case('ADMIN')
<h2> Your Second Case is TRUE</h2>
@break
@case(3)
<h2> Your Third Case is TRUE</h2>
@break
@default {{-- Default is Not mendatory it's an Optional --}}
<h2> Your Default Condition is TRUE </h2>
@endswitch

{{-- now we Will See the Loop Directives inside the blade File --}}
{{-- First of all we will See the for Loop --}}
@for($i = 0 ; $i <= 10; $i++)
<h1> The value of I : {{$i}} </h1>
@endfor

{{-- Now we will See the Directives of the foreach loop inside the blade File --}}
@foreach($companies as $GT)
<h2> Company Name is : {{$GT}}</h2>
@endforeach

{{-- Now we Will See the Forelse loop inside The blade File.
forelse is Loop Which will Provide us Facilty that if our Array is
Empty We can Also Show Sepecifc Code OR the statement For that particular Array
--}}
@forelse($NAA as $KYN)
<h1> {{$KYN}}</h1>
@empty
<h2>SORRY!! Your array is Empty </h2>
@endforelse

{{-- Now we will see the While Loop Directives inside the Blade File --}}
{{--
@while(TRUE)
<h1>This While Loop is an infinty Loop That's Why Comment that Loop</h1>
@endwhile --}}

{{-- Now we will the Break and the Continue Statement with the foreach loop --}}
{{-- Now we will See the statement inside the forEach loop --}}
@foreach ($companies as $GTR)
<h1> Comapny Name : {{$GTR}}</h1>
@if ($GTR == 'ALTO')
@break
@endif

139
@endforeach
<hr>
{{-- Now we will See the Continue statement inside the foreach Loop --}}

@foreach ($CC as $N)


<h1> Comapny Name : {{$N}}</h1>
@if ($N == 'BMW')
@continue {{-- That's Not working --}}
@endif
@endforeach

{{-- We can Also use the Break and the Continue Statement With out using id
Statements
Like the Following Example --}}
<hr>
@foreach ($CC as $N)
<h1> Comapny Name : {{$N}}</h1>
@break($N == 'BMW') {{-- That's Not working --}}
@endforeach
<hr>
{{-- Now we will See the Loop variable inside the blade File --}}
@foreach($CC as $OP)
<h1> Comapny Name : {{$OP}}</h1>
@if($loop->first)
<h1> THis is The First LOOP Of The Car Company </h1>
@endif
@if($loop->last)
<h1> THis is The Last LOOP Of The Car Company </h1>
@endif
@endforeach
{{-- You Can Also use It With The Nested Loop --}}
</body>
</html>

OUTPUT
URL Commands:
[Link]:8000/contact
OUTPUT
Wellcome Contact blade File....

140
My name is HUZAIFA
current Time : 1712053278
Square Root of 493 : 22.203603311175

HELLO!! HUZAIFA
I can't Recognize you!!!
I Recognize you!!! Your Name is [Link]
YOUR UNLESS CONDITION IS FALSE

YES!! A VALUE IS SET INSIDE THE VARIABLE


Your variable is EMPTY
You Are inside the Local Enviroment
YOU ARE INSIDE THE LOCAL OR STAGING
ENVIROMENT
Your Second Case is TRUE

The value of I : 0
The value of I : 1
The value of I : 2
The value of I : 3
The value of I : 4
The value of I : 5

141
The value of I : 6
The value of I : 7
The value of I : 8
The value of I : 9
The value of I : 10
Company Name is : HONDA
Company Name is : HYUNDIA
Company Name is : SUZUKIE
Company Name is : ALTO
Company Name is : KIA
Company Name is : FORD
Company Name is : LEXUSUS
Company Name is : BMW
Company Name is : AUDI
Company Name is : MERCEDIES
SORRY!! Your array is Empty

Comapny Name : HONDA


Comapny Name : HYUNDIA
Comapny Name : SUZUKIE
Comapny Name : ALTO

Comapny Name : HONDA


Comapny Name : HYUNDIA

142
Comapny Name : SUZUKIE
Comapny Name : ALTO
Comapny Name : KIA
Comapny Name : FORD
Comapny Name : LEXUSUS
Comapny Name : BMW
Comapny Name : AUDI
Comapny Name : MERCEDIES

Comapny Name : HONDA


Comapny Name : HYUNDIA
Comapny Name : SUZUKIE
Comapny Name : ALTO
Comapny Name : KIA
Comapny Name : FORD
Comapny Name : LEXUSUS
Comapny Name : BMW

143
Comapny Name : HONDA
THis is The First LOOP Of The Car Company
Comapny Name : HYUNDIA
Comapny Name : SUZUKIE
Comapny Name : ALTO
Comapny Name : KIA
Comapny Name : FORD
Comapny Name : LEXUSUS
Comapny Name : BMW
Comapny Name : AUDI
Comapny Name : MERCEDIES
THis is The Last LOOP Of The Car Company
_____________________________________

Ecomerce Project in Laravel


There are Some Following Modules of the Laravel Project Should be Written here.

 Login and Registration


 Home Design Like the E-comerce website

144
 Product Search
 Add to Chart
 User Order placement
 Order Detail
 Order History
 User Profile
 Style and Bootstrap

Project name is : Ecomerce_Project

Setup Database for Project


 Make database
 Connect Database with Project
 Migrate database table
 Data Seeding

Database name is : ecomm_hi


Command to Create Table :
php artisan make:migration create_users_table
To insert the Data into Our Database Table we have to Create the seeder. The terminal
Command to Create the seeder Should be The Following.

Terminal Command For Seeding:


php artisan db:seed --class=user_seeder
php artisan make:seeder user_seeder
The Functionality of the seeder is that it will basically entered the Fake
Data With the help of that Fake Data We can Login the user to Our page.
Seeder Will Also be Created inside The Database Folder.

145
To insert that Fake data into the Table of our Database We should have to Do
Seeding

Steps For Complete login


 Make user Controller
 Make route
 Submit Form
 Make Controller Product
 Make Middleware
 Register Middleware
 Write Code in Middleware for login

Terminal Command to Create the Controller:


php artisan make:controller userController
So, When We got Login then there is no Option to get Loged out ??
We are not going again to the Login page this Should Not be happened till
We not go Logout.
For Doing that
we will Create a middleware

Terminal Command to Create middleware:


php artisan make:middleware UserAuth
Location: App HTTP  middleware

Database For Products:


 Make Migration File

146
 Define and Migrate Table.
 Make Seeder File.
 Inset Seeding in Table.

For Inserting the random data inside the database Table We will Do the
seeding.

Home Page Slider


 Show Products in Slider Table
 Make Model and get it from the database.
 Make view and pass data to view.
 Use Bootstrap carousel.
 Pass Product to Carousel.
 Style.

 First of All we will Create a model So, that we will Fetch the data.

Terminal Command to Create Model:


Php artisan make:model Product
Now we will See how we can Create the trending
Products

Product Detail page


 Make Controller and view for Detail page.
 Get data from DB with id.
 Show Data on Detail Page.
 Add to Chart and Buy now Button.

147
Search Page
 Make Route For Search Page
 Make Search form in header
 Make Search view
 Get Data from the database
 Show on the Search page
 Go to detail Page from Search page.

First of all we will Create the route of the Search page.

Creating the table For Add to


Cart
 Make Migration for add to cart function.
 Add Fields in Cart table.
 It will Combine User and Product data.
 First of all we should have to Run the Command

php artisan make:migration create_cart_table


To run the migration Command we have to write the Following
Command:

php artisan migrate


Saving the product data inside the Cart
table:
Add Product in Cart Table
 Make a Small form for add to cart

148
 Get name form session
 Make route
 Save data in Cart table if user login
 If user Not logged in redirect to login Page.

@csrf
The `@csrf` function in a Laravel Blade file generates a hidden
CSRF token field in an HTML form. This token helps protect
against cross-site request forgery attacks by verifying that the
form submission originates from the correct site.

We want to Save the Data into the cart For that we


have to Create the Module.

Php artisan make:model Cart


Now we are going to Complete the login and logout
functionality Of the User.
 Make Login and logout Menu
 Make Logout route
 show username when User is login
 Test Complete features.
In This Video we going To Show how we can add Element added to the cart

Show Add to Cart Count


 Make A Function For get cart items
 Use this Function in header.
 Test Complete Flow
 First of all Create Function inside the product Controller.

149
Logout and Login Complete
 Make Login and the Logout menu
 Make the Logout Route.
 Show username When User is login
 Test Complete Features.

Adding the cart page Functionality in Our project

Cart Product listing


 Make Route and view for cart list
 Use join to get the data From the Database.
 Pass Data to View
 Add HTML and Style.

We will Create a Route and the View So that We will See that Data Which We
are getting From the Cart table database.

We will Join the Both Tables “cart” and the “product” so that We can Fetch
Easily all the Data Of Our Project their Images their names And Description and
All the other stuffs

Removing a Product From cart


 Add Link Remove Cart
 Make Route
 Function for Remove Cart

Creating the Order


 Make Route for Order now.
 Make Controller and View
 Table of Content.
 Address and the payment methods

150
Creation of Order Table
 Make Migration For Order Table.
 Add Order required Field
 Migrate Table

First of All we will Create the Migration.

php artisan make:migration create_order_table

Placing of the Orders inside the order table


 Make Route and Form
 Add order data In Orders table.
 Remove data From cart table

How can we Show the my order List page??

Show my Order List


 Make Router for my order
 Fetch Data from the Database with join
 Make View for my orders

First of All We will create the Router Which will fetch the data.

Include Directive
Inside the include directive we will see how can we include a View inside Another,….

For that we will use the include Directive ,.

So the description of the include Directive inside the Laravel blade template Engine. “ Blade’s
@include directive allow you to include a Blade view from within another view. All variables
that are available to the parent View Will be made Available to the include view.”

Syntax:-

151
@include(‘view_name’)

If we want to pass an Extra Data inside a view For that you Should have to Select
out the Following Syntax.

@include(‘view_name’,array)

Linking The View without Controller


[Link]
<?php

use Illuminate\Support\Facades\Route;

/* Route::get('/', function () {
return view('welcome');
});
*/
Route::get('/', function () {
return view('welcome',['name'=>'HUZAIFA NOOR']);
});

[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Include Directive</title>
</head>
<body>
<h1> Wellcome Sir !! {{$name}} page of the include Direcitve </h1><hr>
{{-- Any variable that avilable Inside the parent blade File Should Also be
included
inside the Child File also --}}
{{-- you cannot Pass the Data of the Child View inside the parent View
<h1>Your Contact Number is : {{$Pincode}}</h1> --}}
{{-- you can also Pass the data inside an Array as the pincode --}}
@include('contact' ,['Pincode' =>0310124323])
</body>
</html>

152
[Link]
{{-- We donot need to write the Body of The HTML inside here it is Not Necssary and
it's not the
Good that will increase the line of the Code. --}}
<h1> How are you Sir!! {{$name}} This is the Contact page</h1><hr>
<h1>Your Contact Number is : {{$Pincode}}</h1>

OUTPUT
Wellcome Sir !! HUZAIFA NOOR page of the
include Direcitve

How are you Sir!! HUZAIFA NOOR This is the


Contact page

Your Contact Number is : 52472019


@include_directive With the Controller
[Link](Route File)
<?php

use App\Http\Controllers\Include_Directive;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Route;

/* Route::get('/', function () {
return view('welcome');
});
*/
Route::get('/', function () {
return view('welcome',['name'=>'HUZAIFA NOOR']);
});

153
/* Creating the View for the Include_Directive Controlller */
Route::get('product',[Include_Directive::class,'show']);

Controller File(Include_Directive)
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

/* First Of all we should have to Create the Route for that particular Controller */
class Include_Directive extends Controller
{
//Creating the Show that's Route we hae created the previously.
function show(){
/* now we will see Whoelse can use the Data if we pass the data from the
Controller...
(It should be the parent blade file Or The child blade File) */

return view('product',['wn'=>"Click_Cart"]);
}
}

[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Product page</title>
</head>
<body>
{{-- The data inside the Controller Should Always be accessed inside the Parent
blade File. --}}
<h1> Wellcome to the Product Page And {{$wn}}</h1>
<hr>
@include('mobilr',['total_number'=>5])
{{-- We can also include that particualar file more than Once.
include will basically Also provide the reuseability of the code.
@include('mobilr')

154
--}}

</body>
</html>

[Link]
{{-- As we now that inside the nested Blade we Did Not need to write The Body of the
HTML Page
we will just write The Only Code OR the particular Functions. --}}
{{-- We can also Pass the Data in the Child blade File Which We have written inside
the
Controller Files --}}
<h1> The Mobile List and {{$wn}} </h1>
<h3>
<ul>
<li> xioami A13</li>
<li> LG GK5</li>
<li>Apple 14 PRO MAX</li>
<li>SAMSUNG A13</li>
<li>INFINIX HOT 11 Play</li>
<hr>
<li>Total Number Of Mobile is: {{$total_number}}</li>
</ul>
</h3>
<hr>

OUTPUT
URL Command:
[Link]:8000/product

OUTPUT
Wellcome to the Product Page And Click_Cart

The Mobile List and Click_Cart


155
 xioami A13
 LG GK5
 Apple 14 PRO MAX
 SAMSUNG A13
 INFINIX HOT 11 Play

 Total Number Of Mobile is: 5

IncludeIf Directive
If you Would like to include a View that may or may not be Present, you should use the
@includeifDirective.

“ We will use includeIfDirecitive When We are not Sure About


that our View(blade File) Should be Exist or Not???. If our blade
File is Not exist then it will not Show us the ERROR While Other
hand the @inlcude Function Show us the ERROR“

Syntax:-
The Syntax of the includeif and the include Would be the same.
@include(‘view_name’)

@include(‘view_name’, array)

[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Product page</title>
</head>
<body>

156
{{-- The data inside the Controller Should Always be accessed inside the Parent
blade File. --}}
<h1> Wellcome to the Product Page And {{$wn}}</h1>
<hr>
@include('mobilr',['total_number'=>5])
{{-- We can also include that particualar file more than Once.
include will basically Also provide the reuseability of the code.
@include('mobilr')
--}}
{{-- if we are not Sure About the ERROR that Error Should be Exist OR Not
For that we will Write the Following Function --}}
@includeIf('mobile12') {{-- it will not Show Any particualr ERROR --}}

</body>
</html>

[Link]
{{-- As we now that inside the nested Blade we Did Not need to write The Body of the
HTML Page
we will just write The Only Code OR the particular Functions. --}}
{{-- We can also Pass the Data in the Child blade File Which We have written inside
the
Controller Files --}}
<h1> The Mobile List and {{$wn}} </h1>
<h3>
<ul>
<li> xioami A13</li>
<li> LG GK5</li>
<li>Apple 14 PRO MAX</li>
<li>SAMSUNG A13</li>
<li>INFINIX HOT 11 Play</li>
<hr>
<li>Total Number Of Mobile is: {{$total_number}}</li>
</ul>
</h3>
<hr>

OUTPUT
URL Command
[Link]:8000/product

includeWhen & includeUnless Directive


157
if we would like to @include a view if a given Boolean expression evaluates to true
or false, you may use the @inlcude When and @includeUnless Directives.

In Simple Words if you went to include a View on the basis of the


TRUE or the FALSE or on the basis of the Boolean Expression for
that we will use the Following function.

Syntax:
@includeWhen($boolean,’view_name’)
@includeWhen($boolean,’view_name’,array)

@includeUnless($boolean,’view_name’)
@includeUnless($boolean,’view_name’,array)

Include_Directive.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

/* First Of all we should have to Create the Route for that particular Controller */
class Include_Directive extends Controller
{
//Creating the Show that's Route we hae created the previously.
function show(){
/* now we will see Whoelse can use the Data if we pass the data from the
Controller...
(It should be the parent blade file Or The child blade File) */

/* Here we Will Create teh Condition that if our user Type is the admin then
Our user Should be Callled as the TRUE if our user Is not Should the admin
then
it will be Considered as the FALSE */
$user = "NOTS";

158
$userType = $user == 'Admin' ? TRUE : FALSE;
return view('product',['wn'=>"Click_Cart" , 'userType'=> $userType ]);
}
}

[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Product page</title>
</head>
<body>
{{-- The data inside the Controller Should Always be accessed inside the Parent
blade File. --}}
<h1> Wellcome to the Product Page And {{$wn}}</h1>
<hr>
@include('mobilr',['total_number'=>5])
{{-- We can also include that particualar file more than Once.
include will basically Also provide the reuseability of the code.
@include('mobilr')
--}}
{{-- if we are not Sure About the ERROR that Error Should be Exist OR Not
For that we will Write the Following Function --}}
@includeIf('mobile12') {{-- it will not Show Any particualr ERROR --}}
{{-- --}}
@includeWhen($userType, 'Random')
@includeUnless($userType, 'False')
</body>
</html>

[Link]
{{-- As we now that inside the nested Blade we Did Not need to write The Body of the
HTML Page
we will just write The Only Code OR the particular Functions. --}}
{{-- We can also Pass the Data in the Child blade File Which We have written inside
the
Controller Files --}}
<h1> The Mobile List and {{$wn}} </h1>
<h3>
<ul>
<li> xioami A13</li>
<li> LG GK5</li>

159
<li>Apple 14 PRO MAX</li>
<li>SAMSUNG A13</li>
<li>INFINIX HOT 11 Play</li>
<hr>
<li>Total Number Of Mobile is: {{$total_number}}</li>
</ul>
</h3>
<hr>

[Link]
<h2> Wellcome to the TRUE Blade File </h2>

[Link]
<h1>Wellcome to the false blade file </h1>

OUTPUT
URL Command:
[Link]:8000/product

OUTPUT
Wellcome to the Product Page And Click_Cart

The Mobile List and Click_Cart

160
 xioami A13
 LG GK5
 Apple 14 PRO MAX
 SAMSUNG A13
 INFINIX HOT 11 Play

 Total Number Of Mobile is: 5

Wellcome to the Random File

Each Directive
You may combine Loops and Include into one line with blade’s @each directives.

Syntax:
@each(‘view_name’,array,item)

You may also pass a Fourth Argument to the @each Directive. This
Argument determines the view that Will be Rendered if The Given array is
Empty.

Syntax:
@each(‘view_name’,array,item,’view_name’)

Indirective_Directive.[Link]
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

/* First Of all we should have to Create the Route for that particular Controller */
class Include_Directive extends Controller
{
//Creating the Show that's Route we hae created the previously.

161
function show(){
/* now we will see Whoelse can use the Data if we pass the data from the
Controller...
(It should be the parent blade file Or The child blade File) */

/* Here we Will Create teh Condition that if our user Type is the admin then
Our user Should be Callled as the TRUE if our user Is not Should the admin
then
it will be Considered as the FALSE */
$user = "NOTS";
$userType = $user == 'Admin' ? TRUE : FALSE;
/* Array For The each Directives */
$students = [];
return view('product',['wn'=>"Click_Cart" ,'userType'=> $userType ,
'students' => $students ]);
}
}

[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Product page</title>
</head>
<body>
{{-- The data inside the Controller Should Always be accessed inside the Parent
blade File. --}}
<h1> Wellcome to the Product Page And {{$wn}}</h1>
<hr>
@include('mobilr',['total_number'=>5])
{{-- We can also include that particualar file more than Once.
include will basically Also provide the reuseability of the code.
@include('mobilr')
--}}
{{-- if we are not Sure About the ERROR that Error Should be Exist OR Not
For that we will Write the Following Function --}}
@includeIf('mobile12') {{-- it will not Show Any particualr ERROR --}}
{{-- --}}
@includeWhen($userType, 'Random')
@includeUnless($userType, 'False')
{{-- @foreach ($students as $stu)
@include('students')

162
@foreach
OR --}}
@each('students', $students , 'stu' , 'nostudents')

</body>
</html>

[Link]
{{-- As we now that inside the nested Blade we Did Not need to write The Body of the
HTML Page
we will just write The Only Code OR the particular Functions. --}}
{{-- We can also Pass the Data in the Child blade File Which We have written inside
the
Controller Files --}}
<h1> The Mobile List and {{$wn}} </h1>
<h3>
<ul>
<li> xioami A13</li>
<li> LG GK5</li>
<li>Apple 14 PRO MAX</li>
<li>SAMSUNG A13</li>
<li>INFINIX HOT 11 Play</li>
<hr>
<li>Total Number Of Mobile is: {{$total_number}}</li>
</ul>
</h3>
<hr>

[Link]
<h1> The Array of the students Is Empty </h1>

OUTPUT
Wellcome to the Product Page And Click_Cart

The Mobile List and Click_Cart

163
 xioami A13
 LG GK5
 Apple 14 PRO MAX
 SAMSUNG A13
 INFINIX HOT 11 Play

 Total Number Of Mobile is: 5

Wellcome to the false blade file


The Array of the students Should be Empty

Once Directive
The @once directive allows you to define a portion of the template that will Only
be evaluated once per rendering Cycle.

It will be evaluated in just Once Time of the rendering File.

Syntax:-
@once

,…………….

@once

[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Product page</title>
</head>

164
<body>
{{-- The data inside the Controller Should Always be accessed inside the Parent
blade File. --}}
<h1> Wellcome to the Product Page And {{$wn}}</h1>
<hr>
@include('mobilr',['total_number'=>5])
{{-- We can also include that particualar file more than Once.
include will basically Also provide the reuseability of the code.
@include('mobilr')
--}}
{{-- if we are not Sure About the ERROR that Error Should be Exist OR Not
For that we will Write the Following Function --}}
@includeIf('mobile12') {{-- it will not Show Any particualr ERROR --}}
{{-- --}}
@includeWhen($userType, 'Random')
@includeUnless($userType, 'False')
{{-- @foreach ($students as $stu)
@include('students')
@foreach
OR --}}
@each('students', $students , 'stu' , 'nostudents')
@once
<h1> It will be evaluated once Inside the Rendering Cycle </h1>
@endonce
</body>
</html>

OUTPUT
Wellcome to the Product Page And Click_Cart

The Mobile List and Click_Cart


 xioami A13
 LG GK5
 Apple 14 PRO MAX
 SAMSUNG A13
 INFINIX HOT 11 Play

 Total Number Of Mobile is: 5

165
Wellcome to the false blade file
The Array of the students Is Empty
It will be evaluated once Inside the Rendering Cycle

Raw PHP
We will see how can we will write the raw PHP inside the Laravel.
You can use the Blade@php directive to Execute a block of plain PHP
Within your Template.

Syntax:
@php
// php Code
@endphp

[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Php Code Running.</title>
</head>
<body>
<h1> Wellcome page</h1>
@php
echo "HEllo!! This is Our plain PHP Code :";
@endphp
</body>
</html>

166
OUTPUT
Wellcome page
HEllo!! This is Our plain PHP Code :

Components
Components are a reuseable group of elements. This let us build large applications which are
made up reusable, Independent applications which are made up of reuseable, Independent and
decoupled Components.

These are Two approaches to Writing Components.

 Class based Components.


 Anonymous Components.

In Simple Words the Component is a particular Function by using that’s Function We will reuse
the Code More than one Same Component,… the Components Will basically increase the
Reusability Of the Code.

Class based Components


To Create the a Class based Components, you may use the make:component Artisan command.

php artisan make:component component_name


Whenever we will Run This Command will place the component in the

App\view\components Directory
The make:Component command will also create a view template for the component. The View
will be placed in the resources/views/components Directory.

You may also Create Components within Subdirectories.

php artisan make:comopnents directoryName/Component_name

167
Rendering Component
To Display a Component, You may use a Blade Component tag within one of your Blade
template. Blade components tags start with the string x-followed by the kebab case number of
Component class.

Syntax:-
<x-component-name/>

Example:-
<x-card/>

<x-user-profile/>
If your Component is inside the Directory. You can also rendered the components inside the
Subdirectory. In that’s case how can we rendered that Subdirectory if our Component Should
exist inside the subdirectory.

“The component class will be the nested deeper within the App\View\Components
Directory, you may use the, Character to indicate directory Nesting.”

Syntax:-
<[Link]-name/>

Example:-
<[Link]/>

Component practical
[Link]
<!DOCTYPE html>
<html lang="en">

168
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1> This is the Home page</h1>
{{-- Following Code is used to Rendered the Card inside the Blade file --}}
<x-card/>
{{-- There should be the FOllowing code to render the Code inside the
Subdirectory --}}
<[Link]/>
</body>
</html>

[Link](Component File)
<div>
<h2> This is Our Card Title</h2>
<h3> Card Subtitle </h3>
<p> Card Description </p>

</div>
<hr>
{{-- If we want to use that Component(card File) inside the Blade we should have to
rendered that file
--}}

[Link](include/Component)
<div>
<!-- The biggest battle is the war against ignorance. - Mustafa Kemal Atatürk -->
<h1> That's our header </h1>

</div>

OUTPUT
This is the Home page

169
This is Our Card Title
Card Subtitle

Card Description

That's our header


Passing Data to Component
You may pass data to blade Components using HTML attributes.

Hard-coded, primitive values may be passed to the Component using Simple HTML attribute strings.

PHP expressions and variables should be passed to the Component Via attributes that use the : character as a
prefix.

Example:
<x-card title=”Card Title” :description=”$desc”/>

We Did not have to only pass the Data We also have to Define the Data Also.

Defining Data in Component


<?php

namespace App\View\Components;

use illuminate\view\Component;

class Card extends Component {

public $title

public $description

public function__construct($title,$description)

170
// This Constructor will define the class component’s required data inside the
Class Constructor.

$this->title = $title;

$this->description = $description;
}

public function render() {

return view(‘[Link]’)

Remember:
 All the public Properties On a Component will automatically be made available to the
Component’s view.
 It is not necessary to pass the data to the view from the Component’s render method.

Displaying component Data


When your component is rendered , you may display the contents of your
component’s public variables by echoing the variables by name.

Example:
{{$title}}

{{$description}}

Casing
Component Constructor arguments should be specified Using camelCase, While kebab-case
should be used when referencing the argument names in HTML attributes.

171
public function__construct($subTitle)

$this->subtitle= $subTitle;

<x-card sub-title=”Card subtitle” />

Practical Of passing Data in component


[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1> This is the Home page</h1>
<hr>
@php
$desc = "Card Description" ;
@endphp

{{-- Rendering the Component --}}


{{-- We will See how can we will pass the data inside The Componenet
the Following Card Should have their own Data. --}}
{{-- Remeber We should have to Write the : before The Description --}}
<x-card title="CARD TITLE 1" sub-title=" Card Subtitle 1" :description=$desc/>
{{-- That's Not Enough to Pass the data inside
the Component We should have to Define the Title Variable inisde The Card
Componenet inisde The Card File that are located
inside the App ==> View ==>Component==>[Link] --}}
{{-- you Should have to Remember the casing inside the Component --}}
<hr><x-card title="CARD TITLE 2" sub-title=" Card Subtitle 2"
:description=$desc/>
<hr><x-card title="CARD TITLE 3" sub-title=" Card Subtitle 3"
:description=$desc/>
<hr><x-card title="CARD TITLE 4" sub-title=" Card Subtitle 4"
:description=$desc/>

172
</body>
</html>

[Link]
<div>
<h2> {{$title}}</h2>
<h3> {{$subTitle}}</h3>
<p> {{$description}} </p>

</div>
<hr>
{{-- If we want to use that Component(card File) inside the Blade we should have to
rendered that file
--}}

[Link](App=>View=>Compo
nent=>card)
<?php

namespace App\View\Components;

use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;

class card extends Component


{
/**
* Create a new component instance.
*/
/* Here we will define Our card variable So that We will pass the data inside the
Componenet */
public $title;
public $subTitle;
public $description;

public function __construct($title ,$subTitle , $description)


{
/* Here we will do the initizlization of the variable */
$this->title = $title;
/* Here we will do the initizlization of the variable */

173
$this->subTitle = $subTitle;
$this->description = $description;
}

/**
* Get the view / contents that represent the component.
*/

public function render(): View|Closure|string


{
return view('[Link]');
}
}

OUTPUT
This is the Home page

CARD TITLE 1
Card Subtitle 1

Card Description

CARD TITLE 2
Card Subtitle 2

Card Description

CARD TITLE 3
Card Subtitle 3

Card Description

174
CARD TITLE 4
Card Subtitle 4

Card Description

Component Methods
We can also create Our Component Method Inside The component. For that we should have to
Follow the Below process..

 Defining Method in Component

public function addNumber($a)

return $a + 20;

 Calling the Component Method

{{$addNumber(10)}}

Practical
[Link](App=>View=>Component=>card)
<?php

namespace App\View\Components;

use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;

class card extends Component


{
/**
* Create a new component instance.
*/

175
/* Here we will define Our card variable So that We will pass the data inside the
Componenet */
public $title;
public $subTitle;
public $description;

public function __construct($title ,$subTitle , $description)


{
/* Here we will do the initizlization of the variable */
$this->title = $title;
/* Here we will do the initizlization of the variable */
$this->subTitle = $subTitle;
$this->description = $description;
}

/**
* Get the view / contents that represent the component.
*/

public function render(): View|Closure|string


{
return view('[Link]');
}
/* Here we are Creating Our own built-in Method For the Component */
public function addNumber($a){
return $a + 20;

}
}

[Link]
<div>
<h2> {{$title}}</h2>
<h3> {{$subTitle}}</h3>
<p> {{$description}} </p>

</div>
<hr>
{{-- If we want to use that Component(card File) inside the Blade we should have to
rendered that file
--}}
<hr>
{{-- here We are calling the built-in Fucntion of The Component --}}
<div>
{{$addNumber(10)}}
</div>

176
OUTPUT
This is the Home page

CARD TITLE 1
Card Subtitle 1

Card Description

30

CARD TITLE 2
Card Subtitle 2

Card Description

30

CARD TITLE 3
Card Subtitle 3

Card Description

30

CARD TITLE 4
Card Subtitle 4

Card Description

177
30

Component Attributes
 Defining Attributes in Component.

<x-card title=’Card Title 1’ sub-title=’Card Subtitle 1’ :description=$desc


class=”myclass” />

 Using Attributes.

<div {{ $attributes}}>

All of the Attributes that are not the part Of The Component’s Constructor will automatically be
added to the Component’s “attributes bag”. This attribute bag is automatically made available to
the Component via the $attributes variables.

Practical
[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.myclass{
color: blue;
font-size: 70px;
font-family: Georgia, 'Times New Roman', Times, serif
}
.dclass{
font-style: italic;
}
</style>

178
</head>
<body>
<h1> This is the Home page</h1>
<hr>
@php
$desc = "Card Description" ;
@endphp

{{-- Rendering the Component --}}


{{-- We will See how can we will pass the data inside The Componenet
the Following Card Should have their own Data. --}}
{{-- Remeber We should have to Write the : before The Description --}}
<x-card title="CARD TITLE 1" sub-title=" Card Subtitle 1" :description=$desc/>
{{-- That's Not Enough to Pass the data inside
the Component We should have to Define the Title Variable inisde The Card
Componenet inisde The Card File that are located
inside the App ==> View ==>Component==>[Link] --}}
{{-- you Should have to Remember the casing inside the Component --}}
<hr><x-card title="CARD TITLE 2" sub-title=" Card Subtitle 2" :description=$desc
class="myclass"/>
<hr><x-card title="CARD TITLE 3" sub-title=" Card Subtitle 3"
:description=$desc/>
<hr><x-card title="CARD TITLE 4" sub-title=" Card Subtitle 4"
:description=$desc/>

</body>
</html>

[Link]
<div>
<h2> {{$title}}</h2>
<h3> {{$subTitle}}</h3>
<p> {{$description}} </p>

</div>
<hr>
{{-- If we want to use that Component(card File) inside the Blade we should have to
rendered that file
--}}
<hr>
{{-- here We are calling the built-in Fucntion of The Component --}}
<div>
{{$addNumber(10)}}
</div>

179
{{-- here we are Calling the Component's Attributes that Are not defined inside The
component constructor. --}}
{{-- As we Know that this attribute is Class So We will use that Attribute inside the
tag
it will show us the OUTPUT Like that
<h1 class="myclass"> </h1>
--}}
{{-- We can also give the Default Class inside that with the merge Function and
that class will said to
be the dclass --}}
<h1 {{$attributes ->merge(['class'=>'dclass'])}} >Hello </h1>
{{-- It will Show the OUTPUT after that
<h1 class="dclass myclass"> </h1>
--}}

[Link](App=>View=>Compone
nt=>card)
<?php

namespace App\View\Components;

use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;

class card extends Component


{
/**
* Create a new component instance.
*/
/* Here we will define Our card variable So that We will pass the data inside the
Componenet */
public $title;
public $subTitle;
public $description;

public function __construct($title ,$subTitle , $description)


{
/* Here we will do the initizlization of the variable */
$this->title = $title;
/* Here we will do the initizlization of the variable */
$this->subTitle = $subTitle;
$this->description = $description;
}

/**

180
* Get the view / contents that represent the component.
*/

public function render(): View|Closure|string


{
return view('[Link]');
}
/* Here we are Creating Our own built-in Method For the Component */
public function addNumber($a){
return $a + 20;

}
}

OUTPUT
This is the Home page

CARD TITLE 1
Card Subtitle 1

Card Description

30

Hello

CARD TITLE 2
Card Subtitle 2

Card Description

30

181
Hello
CARD TITLE 3
Card Subtitle 3

Card Description

30

Hello

CARD TITLE 4
Card Subtitle 4

Card Description

30

Hello

Anonymous Component
 Anonymous components provide a mechanism for managing a Component via a Single
file. Anonymous Components Utilize a Single view File and have no associated class.
 To define an anonymous component, you only need to place a Blade template within
your resources/views/components directory.

Example:
Resources/views/components/[Link]

182
Rendering Anonymous component
<x-card />

<x-card title=’Card Title 1’ >

Slot
You will often need to pass additional content to your component via “slots”.

The Components Slots are rendered by echoing the $slot variable.

Defining and Using Slot


 Defining Component Slot.

<x-alert>

<span> Hello I am alert </span>

</x-alert>

 Using the slot Inside Component. Anything that are written inside the Opening and the
Closing slot will be taken as the Slot.

<div>

<h3> Alert Components </h3>

{{$slot}}

</div>

Named Slot
 Defining Component Named Slot.

<x-alert>

<x-slot name=”title”> Alert Title </x-slot>

183
<span> Hello I am Alert </span>

</x-alert>

 Using the Slot inside the component.

<div>

<h2> {{$title}} </h2>

<h3> Alert Component</h3>

{{$slot}}

</div>

Note:-
Any Content nor Within an Explicit x-slot tag will be passed to the Component in $slots
variable.

[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1> Home Page</h1>
<hr>
{{-- <x-alert />
We will see How can We will pass the aditional Component Or the slot--}}
<x-alert>
{{-- here we are Creating the named Slot --}}
<x-slot name='title'> Alert Title</x-slot>
<span>Hello i Am Alert </span>
</x-alert>

</body>
</html>

[Link]
184
<div>
<!-- Walk as if you are kissing the Earth with your feet. - Thich Nhat Hanh -->
{{-- Accessing the name slot that we have defined inside The Welcome File --}}
<h2>{{$title}}</h2>
<h3> Alert Component </h3>
{{-- here we are Accessing the Slots that We have passed inside the welcome File
--}}
{{$slot}}
</div>

OUTPUT
Home Page

Alert Title
Alert Component
Hello i Am Alert

Layout
What is the layout in the Laravel And how can we Create The layout in the Laravel.

“Layout In the Laravel is basically used to reduced ( Code redundancy mean’s


that we did not have to Write the same Code in Every page. ) the code redundancy. It
also helps to manage the Code in more Efficient way.”
There are two Ways to Create the layout.
 Layout using Component
 Layout using template Inheritance.

Layout using Component


There are two Steps to Create the layout using the components.

 Defining layout Component.


 Apply the layout Component.

185
Defining Layout Component
The defining Of the Component will be the same like the creating of the Component. So, As we have Seen that
there are two Ways to Create the Components.

 Class based Component


 Anonymous based Component.

You can use anyone of them ,… but The Suggestion Will be used the Class based Component so, that if we
want to pass any Data then the Data Should be the Opened to be passed,…

Create a layout Component

Resources/views/Components/[Link]

<html>

<head>
<title> {{$title}}</title>

</head>

<body>

{{ $slot }}

</body>

</html>

Applying layout Component


By using that layout Which We have defined before We will Create the
Component. Using that Layout we will Create the page.

The Following will be the Named slot.

create blades view file

resources/views/[Link]

<x-layout name=”title”>

186
HOME
</x-slot>
<h1> This is Home Page </h1>
</x-Layout>

Creating blade view File


resources/views/[Link]
<x-layout>
<x-slot named=”title”>

Contact

</x-slot>
<h1> This is Contact page </h1>

</x-layout>

php artisan make:component layout

Layout practical
[Link]
<!-- Because you are alive, everything is possible. - Thich Nhat Hanh -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">

187
{{-- We want the title here Dynamic for that We will use the Curly braces --}}
<title>{{$title}} </title>
{{-- If we want to Apply the Css So that We can apply it here --}}
<link rel="stylesheet" href="#">
</head>
<body>
{{-- this is a Component File we will basically define Our layout here. --}}
{{$slot}}
{{$banner}}
</body>
</html>

[Link]
{{-- Here we will rendered the Basic layout Of the Program that are Written inside
The Component --}}
<x-layout>

<x-slot name='title'> Home </x-slot>


<h1> Home Page </h1>
<hr>
<x-slot name='banner'> <h2>This is Banner</h2></x-slot>

</x-layout>

[Link]
{{-- Here we will rendered the Basic layout Of the Program that are Written inside
The Component --}}
<x-layout>

<x-slot name='title'> Home </x-slot>


<h1> Home Page </h1>
<hr>
<x-slot name='banner'> <h2>This is Banner</h2></x-slot>

</x-layout>

OUTPUT
Home Page

188
This is Banner

For Contact page ([Link]:800.)

Contact Page

This is Banner

“ Layout is used to reduce the Code redundancy . It also helps us to


manage the Code in More Efficient way.
There are two Ways to Create layout.
 Layout using the Component
 Layout using Template inheritance

Layout Using Template inheritance


There are two Steps to use to layout.

 First Step is to define the layout


 Next step is to Extend the layout.

Defining Layout
First of all we will Create the blade file. We can also Create layout inside the Folder If We
have the multiple layout then you Will create the Folder For that layouts.

resources/views/Layout/[Link]

This Is Our layout File here We will Put That Code Which are Important for all the Files,…
Like the Openning Stream and the Closing Stream And all the linked Files Should be Exist
inside there.

<html lang=”en”>

<head> <title> @yeild (‘title’) </title </head>

<body>

189
@yeild(‘page-name’)

@yeild(‘banner’)

@yeild(‘main’)

@section(‘default-content’)

<h4> This Is default text from the Layout </h4>

@show

// yield Directive and the Section Directive Both Will Work Togather,.

// Yield Mean’s It Will receive the data ,..

//Section will Provyeilf Ckgfdzide the Data,.. Secition Will Provide the data Which Will rece

</body>

</html>

Defining layout
The @section Directive, as the name implies, defines a Section of Content.

 The @yield Directive is used to Display the Content Of the given Section. The @yield
Directive also Accepts a default value as its parameter. This Value(inside the second
parameter) will be rendered if the section being yielded is undefined.

(yield Will basically received that Content which Will Provided by The
Section. It Will display that Specific Content.)
 The @endsection directive will only define a Section while @show will define
and immediately yield the section.

Extending the layout


Create blade view File – resources/views/[Link]

@extends(“[Link]”)

190
@extends(“[Link]”)

@section(“title”,”Home”)

@section(‘page-name’) <h1> Home page </h1> @endsection

@section(‘banner’) <h2> This is Home Page banner </h2> @endsection

@section(‘main’)<h2> This is Home page main Content </h2> @endsection

@section(‘default-content’)

@parent

<h4> This is The home Page text </h4>

@endsection

Create blade view files – resources/views/[Link]


@extends(‘[Link]’)
@section(‘title’,’Content’)
@section(‘page-name’)<h1> Contact Page </h1> @endsection
@section(‘banner’)
<h2> This is Contact page banner </h2>
@endsection
@section(‘main’)
<h2> This is Contact Main page Of The Project </h2>
@endsection

191
 @extends Blade directive Specify Which layout the Child view
Should “inherit”.
View Which extend a Blade layout may inject content into the
layout’s sections using @section directives.
 The Content of section will be displayed in the layout using @yeild.
 the @endsection directive will only Define a section While @ show
will define and immediately yield the section.
 @parent directive to append (rather than Overwriting) Content to the
Layout. The @parent directive will be replaced by the Content of the
layout when view is rendered.

Practical
[Link]
<?php

use Illuminate\Support\Facades\Route;

Route::get('/', function () {
return view('Home');
});

Route::get('contact', function () {
return view('contact');
});

Layout(Foldername)[Link]
{{-- Here we will Write the Common Code in our Specified Files to reduce the Code
Redundancy,... --}}
<!DOCTYPE html>
<html lang="en">
<head>

192
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>@yield('title')</title>
</head>
<body>
@yield('page-name')
@yield('banner')
@yield('main')
{{-- Sometime you need the Default page Which have to Run on the All of the pages
--}}
<h3>This Is the default Text From the Layout </h3>
@section('default-content')
<h2>This is the Default Content Of the Section </h2>
@show {{-- instead using the Endsection we have written Show here because it will
Endsection and also yield(show) the Section at a Time --}}
</body>
</html>

[Link]
{{-- So, the layout page will become the parant And that page Will become the Child
Of that Parent layout Page --}}
@extends('[Link]')
{{-- yeild will display the DATA and the @section Will provide the data.--}}
@section('title', 'HOME Page')

{{-- We will Also Give More than one values to section at a Time --}}
@section('page-name')
<h1> This is the Home page of the Project</h1><hr>
@endsection
@section('banner')
<h2> This is the Bruce banner From the Home Page </h1><hr>
@endsection
@section('main')
<h2> This is the main Content of the Home Page </h1><hr>
@endsection
{{-- if we want to override the Default Content Inside the particular page then we
will
Override it with the Following Content --}}
@section('default-content')
<h3> This is default Text from the Home Page </h3>
@endsection

OUTPUT
193
This is the Home page of the Project

This is the Bruce banner From the Home Page

This is the main Content of the Home Page

This Is the default Text From the Layout


This is default Text from the Home Page

[Link]
{{-- So, the layout page will become the parant And that page Will become the Child
Of that Parent layout Page --}}
@extends('[Link]')
{{-- yeild will display the DATA and the @section Will provide the data.--}}
@section('title', 'Contact Page')
@section('page-name')
<h1> This is the Contact page of the Project</h1><hr>
@endsection
@section('banner')
<h2> This is the Bruce banner From the Contact Page </h1><hr>
@endsection
@section('main')
<h2> This is the main Content of the Contact Page </h1><hr>
@endsection
{{-- If We want to Append the default Content for that We will use the Following
Code --}}
@section('default-content')
@parent
<h2> This is Appended Defult-content of the Contact page </h2>
@endsection

OUTPUT
This is the Contact page of the Project

This is the Bruce banner From the Contact Page

194
This is the main Content of the Contact Page

This Is the default Text From the Layout


This is the Default Content Of the Section
This is Appended Defult-content of the Contact page

Adding CSS and JS


There are two Ways to Add the CSS and the JavaScript into your project.

 Internal CSS and the javaScript


 External CSS and javascript

 Inside the public Folder you will Write the External CSS OR JS File

 Inside the Resources Folder you write the External CSS OR JS Files

Practical
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
h1{
color: blue
}
</style>
</head>
<body>
<h1> Hello laravel </h1>

<script>
alert("Hello laravel :")
</script>
</body>

195
</html>

OUTPUT
Hello laravel

Pract
ical
Public(Folder)  CSS (Folder)  [Link]
h1{
color: red;
font-size: 90px;
font-weight: 1000;
font-style: oblique;
font-family: Arial, Helvetica, sans-serif;
}

Public(Folder)  CSS(Folder)  [Link]


alert("Hello!!! Huzaifa Noor");

[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

196
<meta http-equiv="X-UA-Compatible" content="ie=edge">
{{-- <link rel="stylesheet" href="CSS/[Link]"> --}}
<link rel="stylesheet" href={{asset('css/[Link]')}}>
<title>Document</title>
</head>
<body>
<h1> HUZAIFA NOOR</h1>
</body>
{{-- <script src="JS/[Link]"></script> --}}
{{-- <script src={{asset('JS/[Link]')}}></script> --}}
<script src={{url('JS/[Link]')}}></script>
</html>

OUTPUT

HUZAIFA NOOR

Inside the Resources Folder


Whenever you Should have to Write the CSS and the javaScript File inside the
Resources Folder.

 if you want to Compiled Or process your CSS Code For that you Will Write the
CSS Code inside the resources folder otherwise you Will Write it inside the Public
Folder.

 If you want to use the postCSS or SASS in that case you will put the CSS File
inside the Resources Folder.

197
 When you want to Put your CSS and The javascript File inside the resources
Folder you need to setup Some things.

 there are Some Following Requirement you Should have to Follow before
Adding The File inside the resources Folder.

- Install Node – [Link]


- Install Laravel Mix using the npm – the required dependency is already
mentioned in [Link] File so just Run npm Install and Laravel mix
will automatically get installed.
- Create the CSS and JS files inside resources/CSS and resources/js
Folder respectively.
- Open [Link] file and mentioned Create css and js File, later it
will be processed.

Example:
[Link](‘resources/js/[Link]’,’public/js’)
.js(‘resources/js/[Link]’,’public/js’)
.postCss(‘resources/css/[Link]’,’public/css’,[])
.postCss(‘resources/css/[Link]’,’public/css’)
 After doing that you Also have to process that CSS and the javaScript Files for
that we will Follow the below Process.

Development Command(Under-development):
- Now run npm run dev This Command will run all mix tasks and
all of your application’s CSS and javaScript assets will be completed
and placed in your Application’s public Directory (Non-minified).

Production Command(Finilize):

198
- OR run npm run prod This command will run All mix tasks and
all of your application’s CSS and javaScript assets will be Compiled
and placed in your application’s public directory (Minified code)

So, Whenever you make changes inside the CSS Folder you have to run
One of The Command from the above Folder if you do not want to do
this For that you will write out the Following Command.

- Then run npm run watch command Which will continue


running in your terminal and watch all relevant CSS and javaScript files
for changes. Webpack will automatically recompile your assets when it
detects a Change to one of these files.

 Now you can write css and js code inside resources folder and it will
automatically compiled and will be available inside the public folder.

How to add image inside the Laravel


We will How can use the images inside the Laravel ,..

And We will also See Where We should have to put Images,.

Inside Which Folder We should have to put the images.

 Inside The public Folder.

Practical
[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Welcome Page</title>
</head>

199
<body>
<h1>
Home Page
</h1><hr>
<h2> Image Of My Love is This </h2>
{{-- you Should have to put the images inside the public Folder. --}}
{{-- <img src="image/[Link]" alt=""> --}}
{{-- <img src={{asset('image/[Link]')}} alt="" height="600px"
width="900px"> --}}
<img src={{url('image/[Link]')}} alt="" height="600px" width="900px">
</body>
</html>

OUTPUT

200
Adding the Bootstrap in Laravel
Here We will See how Can We will Add the bootstrap to Our Laravel Project.

There are three Ways to link the bootstrap to Our Project.

 Using the CDN (The CDN links that We got from the bootstrap)

 Inside the Public Folder (Download the CSS Files inside the public Folder Then
links that Files With our tamplelte and the layouts.)

 Inside the resources folder you Will use that Bootstrap Files.

“ Insidethe Downloaded Bootstrap File Version We have to


Create two Folder inside the Public Folder “css” and the
“js” inside The css Folder We will Put the CSS File of the
Bootstrap and Inside The js Folder We will put The JS files
Of The bootstrap.”

Practical
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
{{-- <link href={{asset('css/[Link]')}} rel="stylesheet"> --}}
<link href={{url('css/[Link]')}} rel="stylesheet">
<title>Bootstrap Linking </title>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-
target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-
expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>

201
</button>

<div class="collapse navbar-collapse" id="navbarSupportedContent">


<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-
only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown"
role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search"
aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0"
type="submit">Search</button>
</form>
</div>
</nav>
<br>
<hr>
<h1>My Name is HUZAIFA NOOR.</h1>
<hr>
<button type="button" class="btn btn-primary">Primary</button>
<button type="button" class="btn btn-secondary">Secondary</button>
<button type="button" class="btn btn-success">Success</button>
<button type="button" class="btn btn-danger">Danger</button>
<button type="button" class="btn btn-warning">Warning</button>
<button type="button" class="btn btn-info">Info</button>
<button type="button" class="btn btn-light">Light</button>
<button type="button" class="btn btn-dark">Dark</button>

<button type="button" class="btn btn-link">Link</button>

202
<script src={{asset('js/[Link]')}} ></script>
<script src={{asset('js/[Link]')}} ></script>
<script src={{asset('js/[Link]')}} ></script>
</body>
</html>

OUTPUT

Inside the resources Folder


 Install Node – [Link]
 Install Laravel Mix using npm - The required dependency is already Mention in
[Link] File so just run npm install and Laravel mix Will Automatically get
installed ,..
 Install Bootstrap and [Link]

- npm install –save-dev bootstrap@next


- npm install –save-dev @popper/core

 Create a Folder named sass inside resources Folder then Create a File named [Link]
 resources/sass/[Link]
 Open [Link] File then write.

@import ‘~bootstrap/scss/bootstrap’;

203
 Open resources/[Link] File then write.

Import (‘bootstrap’);

 Open [Link] File and mentioned Created scss and js files, Later it will be
processed.

Example:
[Link](‘resources/js/[Link]’ , ‘public/js’)

.scss(‘resources/scss/[Link]’,’public/css’)

 Now run npm run dev This command will run all mix tasks and all of your
application’s CSS and javaScript assets will be Compiled and placed in your
Application’s public directory(non-minified code)
 If you Want the minified Code For that you will Run up the Following Command,..
 OR run npm run prod This command will run all mix tasks and all of your
application’s CSS and javascript assets will be compiled and placed in your application’s
public directory (Minified Code),.
 Then run npm run watch command which will continue running in your Terminal and
watch all relevant CSS and javascripts files for changes. Webpack will automatically
recompile your assets when it detects a Change to one Of these files,…

Named Routes
Named routes allow the convenient generation of URLs or redirects for specific routes,. You
may Specify a name for a route by chaining the name method onto the route definition. Route
names should always be Unique,..

Route::get(‘about’,function() {return view(‘aboutme’)})->name(‘abt’);

// You can directly define the route with the Help Of that name,..

And if your route contain the Controller then it will have the Following route

Route::get(‘about’,[AboutController::class,’show’])->name(‘abt’);

So, once you have assigned a name to a given route, you may use the route’s name when
generating URLs or redirects via Laravel’s route and redirects helper functions,.

Example:-
204
Route(‘abt’)

Redirect()->route(‘abt’)

Practical
Route([Link])
<?php
use App\Http\Controllers\ContactController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

Route::get('/', function () {
return view('Home');
})->name('Ghar');

Route::get('about', function () {
return view('about');
})->name('AboutMe');
/*
{{-- Here we are Passing the parameter inside the named routes --}} */
Route::get('Post/{catagory}', function ($cat) {
return view('Post',['cat'=>$cat]);
})->name('ManyPost');
Route::get('contact',[ContactController::class,'show'])->name('rabtakro');

[Link]
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

205
class ContactController extends Controller
{
function show()
{// here We are Creating the Function For the Routes
return view('contact');
}}

[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1> This is the Home Page </h1>
<li><a href="/">Home</a></li>
<li><a href="/about">about</a></li>

{{-- This is the new method And More Correct method --}}
<li><a href="{{route('Ghar')}}">Home</a></li>
<li><a href="{{route('AboutMe')}}">about</a></li><hr>
{{-- Here we are Passing the parameter inside the named routes --}}
<li><a href="{{route('ManyPost',['catagory' => 'mobile'])}}">POST</a></li><hr>
<li><a href="{{route('rabtakro')}}">Contact </a></li><hr>
</body>
</html>

[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>This is About Page </h1>
{{-- This Is the Old Method --}}
<li><a href="/">Home</a></li>

206
<li><a href="/about">about</a></li><hr>
{{-- This is the new method And More Correct method --}}
<li><a href="{{route('ManyPost',['catagory' => 'mobile'])}}">POST</a></li><hr>
{{-- Here we are Passing the parameter inside the named routes --}}
<li><a href="{{route('Ghar')}}">Home</a></li>
<li><a href="{{route('AboutMe')}}">about</a></li><hr>
<li><a href="{{route('rabtakro')}}">Contact </a></li><hr>
</body>
</html>

[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1> This is Contact View Page </h1><hr>
{{-- This Is the Old Method --}}
<li><a href="/">Home</a></li>
<li><a href="/about">about</a></li><hr>

{{-- Here we are Passing the parameter inside the named routes --}}
<li><a href="{{route('ManyPost',['catagory' => 'mobile'])}}">POST</a></li><hr>
<li><a href="/contact">Contact</a></li><hr>
{{-- This is the new method And More Correct method --}}
<li><a href="{{route('Ghar')}}">Home</a></li>
<li><a href="{{route('AboutMe')}}">about</a></li>
<li><a href="{{route('rabtakro')}}">Contact </a></li><hr>
</body>
</html>

[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>

207
<h1>This is Post page</h1>
{{-- This Is the Old Method --}}
<li><a href="/">Home</a></li>
<li><a href="/about">about</a></li><hr>
<li><a href="/contact">Contact</a></li><hr>
{{-- This is the new method And More Correct method --}}
<li><a href="{{route('Ghar')}}">Home</a></li>
<li><a href="{{route('AboutMe')}}">about</a></li>
<li><a href="{{route('rabtakro')}}">Contact </a></li><hr>

{{-- Here we are Passing the parameter inside the named routes --}}
<li><a href="{{route('ManyPost',['catagory' =>
'mobile'])}}">POST</a></li><hr>
</body>
</html>

OUTPUT

208
209
Layout using the Components
Creating the resume Project1
RouteFile([Link])
<?php

use App\Http\Controllers\ContactController;
use App\Http\Controllers\ServiceController;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
return view('Home');
})->name('home');
/* here we are defining the Routes For
Our Blade Files OR the View Files */
Route::get('skill', function () {
return view('skill');
})->name('skill');
/* here we will define the Routes For The
Services and the Controller blade Files */
Route::get('service',[ServiceController::class,'show'])->name('service');
Route::get('Contact',[ContactController::class,'show'])->name('contact');

210
Baldes Files
Include(folder)->[Link]
<?php

use App\Http\Controllers\ContactController;
use App\Http\Controllers\ServiceController;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
return view('Home');
})->name('home');
/* here we are defining the Routes For
Our Blade Files OR the View Files */
Route::get('skill', function () {
return view('skill');
})->name('skill');
/* here we will define the Routes For The
Services and the Controller blade Files */
Route::get('service',[ServiceController::class,'show'])->name('service');
Route::get('Contact',[ContactController::class,'show'])->name('contact');

Component(folder)->[Link]
{{-- here we will Create Basic Layout
And we will use that basic layout In All Of The Files.--}}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link href={{asset('css/[Link]')}} rel="stylesheet">
<link href={{asset('css/[Link]')}} rel="stylesheet">
{{-- Adding the Fontawsome Files --}}
<link href={{asset('css/[Link]')}} rel="stylesheet">
{{-- our Title Is Dynamic mean's Every page have their Different Title
That's why we have written the Title Like that --}}
{{-- Links for the Google Fonts --}}
<link rel="stylesheet" href="[Link]
family=Satisfy&display=swap">
<title>{{$title}}</title>
</head>

211
<body>
<div class="container-fluid bg-dark">
<div class="row">
<div class="col-sm-2">
{{-- here we are including Our Sidebar File For that we will
use the include keyword --}}
@include('[Link]')
</div>
<div class="col-sm-10">
{{$content}}
</div>
</div>
</div>
<script src={{asset('js/[Link]')}} ></script>
<script src={{asset('js/[Link]')}} ></script>
<script src={{asset('js/[Link]')}} ></script>
<script src={{asset('js/[Link]')}} ></script>

</body>
</html>

[Link]
<x-layout>
<x-slot name='title'>
Contact
</x-slot>
<x-slot name="content" >
<div class="container mt-5">
<h1 class="text-warning mb-5 border-bottom" >
Contact Us
</h1>
<div class="row text-white mb-5">
<p class="mx-auto mb-5">
Do you have any Question? Please do Not hestate
to Contact. I will Come Back to you within a metter of
Hours to help now.
</p>
<div class="col-sm-9 mb-5">
<form action="">
<div class="row g-3">
<div class="col-md-6">
<label for="inputName">Your Name</label>
<input type="text" class="form-control mt-2"
id="inputName">
</div>
<div class="col-md-6">

212
<label for="inputEmail">Your Email </label>
<input type="email" class="form-control mt-2"
id="inputEmail" required>
</div>

<div class="col-md-12">
<label for="inputSubject"> Your Subject</label>
<input type="text" class="form-control mt-2"
id="inputSubject">
</div>
<div class="col-md-12 mb-3">
<label for="inputTextarea"> Your Message </label>
<textarea class="form-control mt-2" id="inpuTextarea"
required></textarea>
</div>
</div>
<button class="btn btn-primary" type="submit">Send</button>
</form>
</div>
<div class="col-sm-3 text-center">
<ul class="list-unstyled">
<li >
<i class="fas fa-map-marker-alt fa-2x i-color"></i>
<p>Taunsa sharif,D.G Khan,Punjab,Pakistan</p>
</li>
<li>
<i class="fas fa-phone mt-4 fa-2x i-color">
</i>
<p>+923101669426</p>
</li>
<li>
<i class="fas fa-envelope mt-4 fa-2x i-color"></i>
<p> hn764889@[Link]</p>
</li>
</ul>
</div>
</div>
</div>
<div class="text-center">
<a href="#" target="_blank"><i class="fab fa-twitter i-color"></i></a>
<a href="#" target="_blank"><i class="fab fa-facebook-f i-color mx-
3"></i></a>
<a href="#" target="_blank"><i class="fab fa-instagram i-
color"></i></a>
<a href="#" target="_blank"><i class="fab fa-dribbble i-color mx-
3"></i></a>
</div>
</x-slot>
</x-layout>

213
[Link]
<x-layout>
<x-slot name='title'>
HOME
</x-slot>
<x-slot name='content'>
<div class="mt-5">
<div class="text-center">
<img src="{{asset('imgs/[Link]')}}" alt=""
class="img-thumbnail" width="250px" height="150px">
</div>
</div>
<div class="mt-5 text-white mx=5 text-justify">
<h1 class="fw-bold st-font"> Hello</h1>
<div class="px-4">
<p style="text-indent: 100px;">
My Name is
<b class="text-warning st-font"> Huzaifa Noor</b>
I am BS(computer Scince) Student. Lorem ipsum dolor sit amet,
consectetur adipisicing elit. Id soluta dicta dolor
perferendis fugit porro tempora eos vel quo?
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quibusdam
dolor quaerat aliquid fuga aperiam
nihil velit, reiciendis perspiciatis possimus nobis doloribus
cumque sapiente esse ex unde repellat? Recusandae, expedita!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quibusdam
dolor quaerat aliquid fuga aperiam
</p>

</div>
</div>
<div class="text-center">
<a href="{{route('contact')}}" class="btn btn-outline-warning mx-5 my-3">
Hire Me</a>
<a href="{{route('contact')}}" class="btn btn-outline-info mx-5 my-3">
Contact </a>
</div>
</x-slot>
</x-layout>

[Link]
<x-layout>
<x-slot name='title'>
Skill

214
</x-slot>
<x-slot name="content" >
<div class="container mt-5">
<h1 class="text-warning mb-5 border-bottom">Skills</h1>
<div class="row text-white">
<div class="col-sm-5">
<h3 class="mt-5">HTML/CSS</h3>
<div class="progress">
<div class="progress-bar bg-danger" role="progressbar"
style="width: 100%" aria-valuenow="100" aria-valuemin="0"
aria-valuemax="100">
100%
</div>
</div>
</div>
<div class="col-sm-5 offset-sm-2">
<h3 class="mt-5">JavaScript</h3>
<div class="progress">
<div class="progress-bar progress-bar-striped
progress-bar-animated" role="progressbar"
style="width: 95%" aria-valuenow="95" aria-valuemin="0"
aria-valuemax="100">
95%
</div>
</div>
</div>
<div class="col-sm-5">
<h3 class="mt-5"> Java Programming</h3>
<div class="progress">
<div class="progress-bar progress-bar-striped
progress-bar-animated" role="progressbar"
aria-valuenow="90" aria-valuemin="0" aria-valuemax="100"
style="width: 90%">
90%
</div>
</div>
</div>
<div class="col-sm-5 offset-sm-2">
<h3 class="mt-5">Python</h3>
<div class="progress">
<div class="progress-bar progress-bar-striped
progress-bar-animated" role="progressbar" aria-
valuenow="95"
aria-valuemax="100" style="width: 95%">
95%
</div>
</div>
</div>
<div class="col-sm-5">

215
<h3 class="mt-5"> SQL </h3>
<div class="progress">
<div class="progress-bar progress-bar-striped
progress-bar-animated" role="progressbar"
aria-valuenow="95" aria-valuemin="0" aria-
valuemax="100"
style="width: 95%">
95%
</div>
</div>
</div>
<div class="col-sm-5 offset-sm-2">
<h3 class="mt-5"> Django</h3>
<div class="progress">
<div class="progress-bar progress-bar-striped
progress-bar-animated" role="progressbar"
aria-valuenow="85" aria-valuemin="0" aria-
valuemax="100"
style="width: 85%">
85%
</div>
</div>
</div>
<div class="col-sm-5 ">
<h3 class="mt-5"> Dart Programming</h3>
<div class="progress">
<div class="progress-bar progress-bar-striped
progress-bar-animated" role="progressbar"
aria-valuenow="55" aria-valuemin="0" aria-
valuemax="100"
style="width: 55%">
55%
</div>
</div>
</div>
<div class="col-sm-5 offset-sm-2">
<h3 class="mt-5"> Julia Programming</h3>
<div class="progress">
<div class="progress-bar progress-bar-striped
progress-bar-animated" role="progressbar"
aria-valuenow="35" aria-valuemin="0" aria-
valuemax="100"
style="width: 35%">
35%
</div>
</div>
</div>
</div>
</div>

216
</x-slot>
</x-layout>

[Link]
<x-layout>
<x-slot name='title'>
Skill
</x-slot>
<x-slot name="content" >
<div class="container mt-5">
<h1 class="text-warning mb-5 border-bottom">Skills</h1>
<div class="row text-white">
<div class="col-sm-5">
<h3 class="mt-5">HTML/CSS</h3>
<div class="progress">
<div class="progress-bar bg-danger" role="progressbar"
style="width: 100%" aria-valuenow="100" aria-valuemin="0"
aria-valuemax="100">
100%
</div>
</div>
</div>
<div class="col-sm-5 offset-sm-2">
<h3 class="mt-5">JavaScript</h3>
<div class="progress">
<div class="progress-bar progress-bar-striped
progress-bar-animated" role="progressbar"
style="width: 95%" aria-valuenow="95" aria-valuemin="0"
aria-valuemax="100">
95%
</div>
</div>
</div>
<div class="col-sm-5">
<h3 class="mt-5"> Java Programming</h3>
<div class="progress">
<div class="progress-bar progress-bar-striped
progress-bar-animated" role="progressbar"
aria-valuenow="90" aria-valuemin="0" aria-valuemax="100"
style="width: 90%">
90%
</div>
</div>
</div>
<div class="col-sm-5 offset-sm-2">
<h3 class="mt-5">Python</h3>
<div class="progress">

217
<div class="progress-bar progress-bar-striped
progress-bar-animated" role="progressbar" aria-
valuenow="95"
aria-valuemax="100" style="width: 95%">
95%
</div>
</div>
</div>
<div class="col-sm-5">
<h3 class="mt-5"> SQL </h3>
<div class="progress">
<div class="progress-bar progress-bar-striped
progress-bar-animated" role="progressbar"
aria-valuenow="95" aria-valuemin="0" aria-
valuemax="100"
style="width: 95%">
95%
</div>
</div>
</div>
<div class="col-sm-5 offset-sm-2">
<h3 class="mt-5"> Django</h3>
<div class="progress">
<div class="progress-bar progress-bar-striped
progress-bar-animated" role="progressbar"
aria-valuenow="85" aria-valuemin="0" aria-
valuemax="100"
style="width: 85%">
85%
</div>
</div>
</div>
<div class="col-sm-5 ">
<h3 class="mt-5"> Dart Programming</h3>
<div class="progress">
<div class="progress-bar progress-bar-striped
progress-bar-animated" role="progressbar"
aria-valuenow="55" aria-valuemin="0" aria-
valuemax="100"
style="width: 55%">
55%
</div>
</div>
</div>
<div class="col-sm-5 offset-sm-2">
<h3 class="mt-5"> Julia Programming</h3>
<div class="progress">
<div class="progress-bar progress-bar-striped
progress-bar-animated" role="progressbar"

218
aria-valuenow="35" aria-valuemin="0" aria-
valuemax="100"
style="width: 35%">
35%
</div>
</div>
</div>
</div>
</div>
</x-slot>
</x-layout>

PublicFolder Files
[Link]
/* Font For the name */
.st-font{
font-family:"Satisfy";
}
html,body{
height:100%;
}

.container-fluid{
min-height: 100%;
}
/* Service Icon Color */
.i-color{
color:chartreuse
}

/* Service Subtitle Color */


.ss-color{
color:silver;
}

[Link]-link {
color:whitesmoke;
}
[Link]-link:hover {
color:black;
background-color: #e9cd79;
}
[Link]{

219
color:black;
background-color: #ffc107;
font-weight:bold;
}

Controller Files
[Link]
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ContactController extends Controller


{
//This is The Controller For the Contact blade File
function Show() {
return view('Contact');
}
}

[Link]

220
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ServiceController extends Controller


{
//This is The Controller For The Service blade File
function Show() {
return view('services');
}
}

OUTPUT

221
222
Layout using the template inheritance
RouteFile([Link])
<?php

use App\Http\Controllers\ContactController;
use App\Http\Controllers\ServiceController;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
return view('Home');
})->name('home');
/* here we are defining the Routes For
Our Blade Files OR the View Files */
Route::get('skill', function () {
return view('skill');
})->name('skill');
/* here we will define the Routes For The
Services and the Controller blade Files */
Route::get('service',[ServiceController::class,'show'])->name('service');
Route::get('Contact',[ContactController::class,'show'])->name('contact');

Controller Files

223
[Link]
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class contactController extends Controller


{
//This is The Controller For the Contact blade File
function Show() {
return view('Contact');
}
}

[Link]
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ServiceController extends Controller


{
//This is The Controller For The Service blade File
function Show() {
return view('services');
}
}

ViewFiles
include(folder)->[Link]
{{-- Here we will not write the code Of the layout of the HTML
because it is already written inside the layout File if we write it
again then it will not show us any error but it will cause the redundancy of the
code --}}
<div class="border-end border-warning h-100">
<div class="text-center">

224
<img src="{{asset('imgs/[Link]')}}" alt="" class="img-fluid rounded-
circle mt-5">
<h3 class="text-white mt-3 st-font"> Huzaifa Noor</h3>
</div>
{{-- mt-4 Will be the margin from the Top 4 --}}
<nav class="nav flex-column text-center mt-4">
{{-- here we using the links of
view Files by their Named Routes --}}
<a href="{{route('home')}}" class="nav-link {{
Request::routeIs('home') ? 'active' : ''}} " > Home </a>
<a href="{{route('service')}}" class="nav-link {{
Request::routeIs('service') ? 'active' : ''}} " > Services </a>
<a href="{{route('skill')}}" class="nav-link {{ Request::routeIs('skill')
? 'active' : ''}}" > Skill </a>
<a href="{{route('contact')}}" class="nav-link {{
Request::routeIs('contact') ? 'active' : ''}}" > Contact </a>
</nav>
</div>

layouts(Folder)->[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link href={{asset('css/[Link]')}} rel="stylesheet">
<link href={{asset('css/[Link]')}} rel="stylesheet">
{{-- Adding the Fontawsome Files --}}
<link href={{asset('css/[Link]')}} rel="stylesheet">
{{-- our Title Is Dynamic mean's Every page have their Different Title
That's why we have written the Title Like that --}}
{{-- Links for the Google Fonts --}}
<link rel="stylesheet" href="[Link]
family=Satisfy&display=swap">
{{-- Our Title Should be Dynamic that's why have
Written yield here
to get the Random Title --}}
<title> @yield('title') </title>
</head>
<body>
<div class="container-fluid bg-dark">

<div class="row">
<div class="col-sm-2">
@include('[Link]')
</div>

225
<div class="col-sm-10">
@yield('content')
</div>
</div>
</div>

<script src={{asset('js/[Link]')}} ></script>


<script src={{asset('js/[Link]')}} ></script>
<script src={{asset('js/[Link]')}} ></script>
<script src={{asset('js/[Link]')}} ></script>
</body>
</html>

[Link]
@extends('[Link]')
@section('title','contact')
@section('content')
<div class="container mt-5">
<h1 class="text-warning mb-5 border-bottom" >
Contact Us
</h1>
<div class="row text-white mb-5">
<p class="mx-auto mb-5">
Do you have any Question? Please do Not hestate
to Contact. I will Come Back to you within a metter of
Hours to help now.
</p>
<div class="col-sm-9 mb-5">
<form action="">
<div class="row g-3">
<div class="col-md-6">
<label for="inputName">Your Name</label>
<input type="text" class="form-control mt-2"
id="inputName">
</div>
<div class="col-md-6">
<label for="inputEmail">Your Email </label>
<input type="email" class="form-control mt-2"
id="inputEmail" required>
</div>

<div class="col-md-12">
<label for="inputSubject"> Your Subject</label>
<input type="text" class="form-control mt-2"
id="inputSubject">
</div>

226
<div class="col-md-12 mb-3">
<label for="inputTextarea"> Your Message </label>
<textarea class="form-control mt-2" id="inpuTextarea"
required></textarea>
</div>
</div>
<button class="btn btn-primary" type="submit">Send</button>
</form>
</div>
<div class="col-sm-3 text-center">
<ul class="list-unstyled">
<li >
<i class="fas fa-map-marker-alt fa-2x i-color"></i>
<p>Taunsa sharif,D.G Khan,Punjab,Pakistan</p>
</li>
<li>
<i class="fas fa-phone mt-4 fa-2x i-color">
</i>
<p>+923101669426</p>
</li>
<li>
<i class="fas fa-envelope mt-4 fa-2x i-color"></i>
<p> hn764889@[Link]</p>
</li>
</ul>
</div>
</div>
</div>
<div class="text-center">
<a href="#" target="_blank"><i class="fab fa-twitter i-color"></i></a>
<a href="#" target="_blank"><i class="fab fa-facebook-f i-color mx-
3"></i></a>
<a href="#" target="_blank"><i class="fab fa-instagram i-
color"></i></a>
<a href="#" target="_blank"><i class="fab fa-dribbble i-color mx-
3"></i></a>
</div>
@endsection

[Link]
@extends('[Link]')
@section('title','Home')
@section('content')
<div class="mt-5">
<div class="text-center">
<img src="{{asset('imgs/[Link]')}}" alt=""
class="img-thumbnail" width="250px" height="150px">

227
</div>
</div>
<div class="mt-5 text-white mx=5 text-justify">
<h1 class="fw-bold st-font"> Hello</h1>
<div class="px-4">
<p style="text-indent: 100px;">
My Name is
<b class="text-warning st-font"> Huzaifa Noor</b>
I am BS (computer Scince) Student. Lorem ipsum dolor sit amet,
consectetur adipisicing elit. Id soluta dicta dolor perferendis fugit
porro tempora eos vel quo?
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quibusdam dolor
quaerat aliquid fuga aperiam
nihil velit, reiciendis perspiciatis possimus nobis doloribus cumque
sapiente esse ex unde repellat? Recusandae, expedita!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quibusdam dolor
quaerat aliquid fuga aperiam
</p>

</div>
</div>
<div class="text-center">
<a href="{{route('contact')}}" class="btn btn-outline-warning mx-5 my-3"> Hire
Me</a>
<a href="{{route('contact')}}" class="btn btn-outline-info mx-5 my-3"> Contact </a>
</div>
@endsection

[Link]
@extends('[Link]')
@section('title','Skill')
@section('content')
<div class="container mt-5">
<h1 class="text-warning mb-5 border-bottom">Skills</h1>
<div class="row text-white">
<div class="col-sm-5">
<h3 class="mt-5">HTML/CSS</h3>
<div class="progress">
<div class="progress-bar bg-danger" role="progressbar"
style="width: 100%" aria-valuenow="100" aria-valuemin="0"
aria-valuemax="100">
100%
</div>
</div>
</div>
<div class="col-sm-5 offset-sm-2">
<h3 class="mt-5">JavaScript</h3>

228
<div class="progress">
<div class="progress-bar progress-bar-striped
progress-bar-animated" role="progressbar"
style="width: 95%" aria-valuenow="95" aria-valuemin="0"
aria-valuemax="100">
95%
</div>
</div>
</div>
<div class="col-sm-5">
<h3 class="mt-5"> Java Programming</h3>
<div class="progress">
<div class="progress-bar progress-bar-striped
progress-bar-animated" role="progressbar"
aria-valuenow="90" aria-valuemin="0" aria-valuemax="100"
style="width: 90%">
90%
</div>
</div>
</div>
<div class="col-sm-5 offset-sm-2">
<h3 class="mt-5">Python</h3>
<div class="progress">
<div class="progress-bar progress-bar-striped
progress-bar-animated" role="progressbar" aria-
valuenow="95"
aria-valuemax="100" style="width: 95%">
95%
</div>
</div>
</div>
<div class="col-sm-5">
<h3 class="mt-5"> SQL </h3>
<div class="progress">
<div class="progress-bar progress-bar-striped
progress-bar-animated" role="progressbar"
aria-valuenow="95" aria-valuemin="0" aria-
valuemax="100"
style="width: 95%">
95%
</div>
</div>
</div>
<div class="col-sm-5 offset-sm-2">
<h3 class="mt-5"> Django</h3>
<div class="progress">
<div class="progress-bar progress-bar-striped
progress-bar-animated" role="progressbar"

229
aria-valuenow="85" aria-valuemin="0" aria-
valuemax="100"
style="width: 85%">
85%
</div>
</div>
</div>
<div class="col-sm-5 ">
<h3 class="mt-5"> Dart Programming</h3>
<div class="progress">
<div class="progress-bar progress-bar-striped
progress-bar-animated" role="progressbar"
aria-valuenow="55" aria-valuemin="0" aria-
valuemax="100"
style="width: 55%">
55%
</div>
</div>
</div>
<div class="col-sm-5 offset-sm-2">
<h3 class="mt-5"> Julia Programming</h3>
<div class="progress">
<div class="progress-bar progress-bar-striped
progress-bar-animated" role="progressbar"
aria-valuenow="35" aria-valuemin="0" aria-
valuemax="100"
style="width: 35%">
35%
</div>
</div>
</div>
</div>
</div>
@endsection

[Link]
@extends('[Link]')
@section('title','Service')
@section('content')
<div class="container mt-5">
<h1 class="text-warning mb-5 border-bottom"> Services</h1>
<div class="row text-center text-white mb-5">
<div class="col-sm-4">
<i class="fas fa-search-dollar fa-2x mb-3 i-color"></i>
<h3>SEO</h3>
<p class="ss-color">Lorem ipsum dolorCorrupti culpa deserunt dicta
nobis facilis.</p>

230
</div>
<div class="col-sm-4">
<i class="fas fa-palette fa-2x mb-3 i-color"></i>
<h3> Web Design </h3>
<p class="ss-color">Lorem, ipsum excepturi pariatur officiis
in nisi.</p>
</div>
<div class="col-sm-4">
<i class="fas fa-code fa-2x mb-3 i-color"></i>
<h3> Web Development </h3>
<p class="ss-color">Lorem, ipsum dolorsaepe praesentium ducimus
laborum quos numquam.</p>
</div>
</div>

<div class="row text-center text-white mb-5">


<div class="col-sm-4">
<i class="fab fa-android fa-2x mb-3 i-color"></i>
<h3> Andriod </h3>
<p class="ss-color"> Lorem ipsum dolorEsse modi ipsum vitae
soluta, incidunt praesentium?</p>
</div>
<div class="col-sm-4">
<i class="fab fa-apple fa-2x mb-3 i-color"></i>
<h3> IOS</h3>
<p class="ss-color">Lorem ipsum, elit. Tenetur vitae minus
commodi atque, laboriosam nostrum?</p>
</div>
<div class="col-sm-4">
<i class="fas fa-ad fa-2x mb-3 i-color"></i>
<h3> Advertising</h3>
<p class="ss-color">Lorem ipsum dolor,. Quisquam dolorem et
possimus, ipsam cupiditate laudantium.</p>
</div>
</div>

<div class="row text-center text-white mb-5">


<div class="col-sm-4">
<i class="fas fa-pencil-alt fa-2x mb-3 i-color"></i>
<h3>Logo Design</h3>
<p class="ss-color">Lorem, Exercitationem,sequuntur adipisci neque
cupiditate incidunt.</p>
</div>
<div class="col-sm-4">
<i class="fas fa-database fa-2x mb-3 i-color"></i>
<h3>Hosting</h3>
<p class="ss-color">Lorem ipsum Quaerat ex doloribus qui laborum ut
quibusdam.</p>
</div>

231
<div class="col-sm-4">
<i class="fas fa-headset fa-2x mb-3 i-color"></i>
<h3> Support </h3>
<p class="ss-color">Lorem ipsum dolor Amet dolores officiis
recusandae minima quod incidunt?</p>
</div>
</div>
</div>
@endsection

[Link]
@extends('[Link]')
@section('title','contact')
@section('content')
<div class="container mt-5">
<h1 class="text-warning mb-5 border-bottom" >
Contact Us
</h1>
<div class="row text-white mb-5">
<p class="mx-auto mb-5">
Do you have any Question? Please do Not hestate
to Contact. I will Come Back to you within a metter of
Hours to help now.
</p>
<div class="col-sm-9 mb-5">
<form action="">
<div class="row g-3">
<div class="col-md-6">
<label for="inputName">Your Name</label>
<input type="text" class="form-control mt-2"
id="inputName">
</div>
<div class="col-md-6">
<label for="inputEmail">Your Email </label>
<input type="email" class="form-control mt-2"
id="inputEmail" required>
</div>

<div class="col-md-12">
<label for="inputSubject"> Your Subject</label>
<input type="text" class="form-control mt-2"
id="inputSubject">
</div>
<div class="col-md-12 mb-3">
<label for="inputTextarea"> Your Message </label>
<textarea class="form-control mt-2" id="inpuTextarea"
required></textarea>

232
</div>
</div>
<button class="btn btn-primary" type="submit">Send</button>
</form>
</div>
<div class="col-sm-3 text-center">
<ul class="list-unstyled">
<li >
<i class="fas fa-map-marker-alt fa-2x i-color"></i>
<p>Taunsa sharif,D.G Khan,Punjab,Pakistan</p>
</li>
<li>
<i class="fas fa-phone mt-4 fa-2x i-color">
</i>
<p>+923101669426</p>
</li>
<li>
<i class="fas fa-envelope mt-4 fa-2x i-color"></i>
<p> hn764889@[Link]</p>
</li>
</ul>
</div>
</div>
</div>
<div class="text-center">
<a href="#" target="_blank"><i class="fab fa-twitter i-color"></i></a>
<a href="#" target="_blank"><i class="fab fa-facebook-f i-color mx-
3"></i></a>
<a href="#" target="_blank"><i class="fab fa-instagram i-
color"></i></a>
<a href="#" target="_blank"><i class="fab fa-dribbble i-color mx-
3"></i></a>
</div>
@endsection

Public(Folder)
[Link]
/* Font For the name */
.st-font{
font-family:"Satisfy";
}
html,body{
height:100%;

233
}

.container-fluid{
min-height: 100%;
}
/* Service Icon Color */
.i-color{
color:chartreuse
}

/* Service Subtitle Color */


.ss-color{
color:silver;
}

[Link]-link {
color:whitesmoke;
}
[Link]-link:hover {
color:black;
background-color: #e9cd79;
}
[Link]{
color:black;
background-color: #ffc107;
font-weight:bold;
}

234
OUTPUT

235
Middleware
Middleware provide a Convenient mechanism for inspecting and filtering
HTTP requests entering your applications.

236
All of these middleware are located in the app/Http/Middleware Directory.

Defining/Creation of Middleware:-
php artsian make:middleware MiddlewareName
After Creating and Defining The middleware there will be
need to register the middleware,..

Registering Middleware
There are Three ways to Register the middleware ,.
 Global Middleware.
 Assigning Middleware to Routes.
 Middleware Groups

Global Middleware
If you want a middleware to run during every HTTP request to your application,
list the middleware class in the $middleware property of your
app/Http/[Link].
You will have to register the middleware Inside the Middleware property.

“Global Middleware mean’s that it will Applied For


all the request inside the Route. In Simple All of the
Routes We have Defined will go to the under
Construction”

237
App -> middleware(Folder)  UnderConstruction
[Link]
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
/* Here we are throwing some exception */
use Symfony\Component\HttpKernel\Exception\HttpException;
class UnderConstruction
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\
HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
throw new HttpException(503);
}
}

OUTPUT
238
[Link]
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
/* Here we are throwing some exception */
use Symfony\Component\HttpKernel\Exception\HttpException;
class UnderConstruction
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\
HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
throw new HttpException(503);
}
}

239
Resources(Folder)->view(Folder)->errors(Folder)

[Link]
(The Folder name and the File name Should be same
otherwise it will not Show the ERROR)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>503 Error File </title>
</head>
<body>
<h1> This Site Is Under Construction </h1>
</body>
</html>

OUTPUT

240
If you want to Create the default ERROR page
inside the Laravel For that you have to Run the
Following Command.
php artisan vendor:publish --tag=laravel-errors

[Link]
@extends('errors::minimal')

@section('title', __('Service Unavailable'))


@section('code', '503')
@section('message', __('Website Construction '))

OUTPUT

241
242
(If you want to Request the HTTP request for
the Specific Route For that we will Follow the
below process.)

Assigning Middleware to Route


In this method of the middleware we will Assign the ERROR OR the
HTTP request to the Particular Routes,..
Inside this we will Assign the Middleware to the Specific Route.

“ if you Would like to Assign middleware to Specific routes,


you have to add your own middleware to List and assign it a
key of your Choosing in the $routeMiddleware property of
your application’s app/Http/[Link]”.

After creating the middleware you will have to know


that how can we use that middleware.

Assigning Middleware to Routes


243
Once the Middleware has been defined in the HTTP kernel, you may use
the Middleware method to assign middleware to a route,..

Route::get(‘/profile’,function({
//
})->middleware(‘auth’);

Multiple Middleware to Routes:


You may Assign Multiple Middleware to the Route by passing an
array of middleware names to the middleware method,.

Route::get(‘/’, function(){
//
})->middleware([‘first’,’second’]);
App(Folder)->HTTP(Folder)

[Link]
<?php

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel


{
/**

244
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array<int, class-string|string>
*/
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\UnderConstruction::class,
\App\Http\Middleware\TrustProxies::class,
\Illuminate\Http\Middleware\HandleCors::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
];

/**
* The application's route middleware groups.
*
* @var array<string, array<int, class-string|string>>
*/
protected $middlewareGroups = [
'web' => [
\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,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],

'api' => [
// \Laravel\Sanctum\Http\Middleware\
EnsureFrontendRequestsAreStateful::class,
\Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];

/**
* The application's middleware aliases.
*
* Aliases may be used to conveniently assign middleware to routes and groups.
*
* @var array<string, class-string|string>
*/
protected $middlewareAliases = [
'auth' => \App\Http\Middleware\Authenticate::class,

245
'[Link]' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'[Link]' => \Illuminate\Session\Middleware\AuthenticateSession::class,
'[Link]' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'[Link]' => \Illuminate\Auth\Middleware\RequirePassword::class,
'signed' => \App\Http\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'construction'=> \App\Http\Middleware\UnderConstruction::class,
];
}

[Link]
<?php

use App\Http\Controllers\ReportController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/
Route::get('/', function () {
return view('Home');
});
Route::get('dashboard', function () {
return view('dashboard');
});
Route::get('stock', function () {
return view('stock');
})->middleware('construction');//Ti Will Apply Middleware To That Code
Route::get('report',[ReportController::class,'show']);

OUTPUT
246
It will Show The ERROR Only On the Stock File,.. Else files will be
Running Properly,..

247
[Link](Middleware on Controller)

<?php

248
use App\Http\Controllers\ReportController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/
Route::get('/', function () {
return view('Home');
});
Route::get('dashboard', function () {
return view('dashboard');
});
Route::get('stock', function () {
return view('stock');
})->middleware('construction');//Ti Will Apply Middleware To That Code

/* Here we are putting the Middleware On the Constructor */


Route::get('report',[ReportController::class,'show'])->middleware('construction');

OUTPUT

249
Middleware Groups
If you want to group the Several middleware under a Single key to make them easier to assign to routes. You may
accomplish this using the $MiddlewareGroups property of you HTTP kernel.

250
Here this is the following method to Define the Middleware groups.

App(Folder) ->HTTP(Folder)->[Link]
<?php

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel


{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array<int, class-string|string>
*/
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
\Illuminate\Http\Middleware\HandleCors::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
];

/**
* The application's route middleware groups.
*
* @var array<string, array<int, class-string|string>>
*/

251
protected $middlewareGroups = [
'web' => [
\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,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],

'api' => [
// \Laravel\Sanctum\Http\Middleware\
EnsureFrontendRequestsAreStateful::class,
\Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
/* here we are Defining our Own built-in middleware */
'construction' => [
\App\Http\Middleware\UnderConstruction::class,
/* We called it A group because it can Exist more than one middleware
Also
That's why it is also known as the group middleware */

]
];

/**
* The application's middleware aliases.
*
* Aliases may be used to conveniently assign middleware to routes and groups.
*
* @var array<string, class-string|string>
*/
protected $middlewareAliases = [
'auth' => \App\Http\Middleware\Authenticate::class,
'[Link]' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'[Link]' => \Illuminate\Session\Middleware\AuthenticateSession::class,
'[Link]' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'[Link]' => \Illuminate\Auth\Middleware\RequirePassword::class,
'signed' => \App\Http\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
];
}

[Link]
252
<?php

use App\Http\Controllers\ReportController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/
Route::get('/', function () {
return view('Home');
});
Route::get('dashboard', function () {
return view('dashboard');
});

/* here group keyword is used to assign the middleware to the group Of the Routes */
Route::middleware(['construction'])->group(function(){
Route::get('stock', function () {
return view('stock');
})->middleware('construction');//Ti Will Apply Middleware To That Code
/* Here we are putting the Middleware On the Constructor */
Route::get('report',[ReportController::class,'show'])->middleware('construction');
});

OUTPUT

253
You can also Pass the extra OR the additional information inside the
middleware.

Middleware([Link])
<?php

254
namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
/* Here we are throwing some exception */
use Symfony\Component\HttpKernel\Exception\HttpException;
class UnderConstruction
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\
HttpFoundation\Response) $next
*/
/* we have to register this Middleware inside the kernel File */
public function handle(Request $request, Closure $next, $role): Response
{
if($role === 'guest'){
return redirect('/');
}
throw new HttpException(503);
}
}

[Link]
<?php

namespace App\Http;

use Illuminate\Foundation\Http\Kernel as HttpKernel;

class Kernel extends HttpKernel


{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array<int, class-string|string>
*/
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
\Illuminate\Http\Middleware\HandleCors::class,

255
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
];

/**
* The application's route middleware groups.
*
* @var array<string, array<int, class-string|string>>
*/
protected $middlewareGroups = [
'web' => [
\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,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],

'api' => [
// \Laravel\Sanctum\Http\Middleware\
EnsureFrontendRequestsAreStateful::class,
\Illuminate\Routing\Middleware\ThrottleRequests::class.':api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
/* here we are Defining our Own built-in middleware */

];

/**
* The application's middleware aliases.
*
* Aliases may be used to conveniently assign middleware to routes and groups.
*
* @var array<string, class-string|string>
*/
protected $middlewareAliases = [
'auth' => \App\Http\Middleware\Authenticate::class,
'[Link]' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'[Link]' => \Illuminate\Session\Middleware\AuthenticateSession::class,
'[Link]' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'[Link]' => \Illuminate\Auth\Middleware\RequirePassword::class,
'signed' => \App\Http\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,

256
'role' => \App\Http\Middleware\UnderConstruction::class,
];
}

OUTPUT

Form
257
Now we will learn how Can we Create the Form inside the Laravel.

- Creating the Form


- Accessing the Form From their Data
- Validating the Form Data

Creating The Form


As we know that our Form Should be Created inside the HTML File and We will Write the HTML File Inside the Blade
File. The Location of the File Should be the Following.

resources/views/[Link]

<form action=”” method=”post”>

@crsf //Whenever you Will have decide your post method you Should have to use the csrf So that
your Form Should be protected from Some Attaches,.. Otherwise you will Face ERROR inside this

Name :<input type=”text” name=”name” id=”name”><br><br>

Email :<input type=”email” name=”email” id=”email”><br><br>

Password :<input type=”password” name=”password” id=”password”><br><br>

<input type=”submit” value=”submit”>

</form>

@csrf
Cross-site request forgeries are a type of malicious exploit whereby unauthorized commands are performed on behalf of an
authenticated user. Thankfully, Laravel makes it easy to protect your application from cross-site request forgery(CSR)
attacks,...

You may use the @csrf Blade Directive to generate the hidden token input Fields.

Accessing Form Data


App\Http\Controller\RegistrationConstroller

function signup(Request $request){

//Inside the request Class object All of the data is Coming

dd($request);

return view(‘registration’);

258
}

- How can you access All of the Input Data.


- How can you access All of the Input data as an Associative Array.
- How can you access any individual Data,.
- How can you access input Via Dynamic Properties,..
- How can you access a Portion Of input Data,.
- Determining if Input is Present.
- How can we do flashing Input to the Session.

Form Practical
[Link]
<?php
use App\Http\Controllers\RegistrationController;
use Illuminate\Support\Facades\Route;
/* We need Controller here because inside the Controller We Will access All of the
Data of the FORM */
Route::get('/', [RegistrationController::class,'showform']);
Route::post('/', [RegistrationController::class,'signup']);
Route::view('olddata','olddata')->name('old');

[Link]
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class RegistrationController extends Controller


{
//Here We will Create the method For the Function which will import the Function.
function showform(){
return view('Registration');
}

/* here we will Create the Function For the Signup method we are accessing the
Post method
So, All of the operation will be performed here,.*/
function signup(Request $request){ /* This is The Request Class in Which All Of
the Form data Should be exist
and we have to create the object of that class All Of Our Form Data Will be
Come inside these Parameters*/
/* dd($request); */

259
// dd is the built-in Function of the laravel
/* ********************************* OUTPUT OF THE DD
****************************************
Illuminate\Http\Request {#37 ▼ // app\Http\Controllers\[Link]
+attributes:
Symfony\Component\HttpFoundation

ParameterBag {#42 ▶}
\

+request:
Symfony\Component\HttpFoundation

InputBag {#38 ▶}
\

+query:
Symfony\Component\HttpFoundation

InputBag {#45 ▶}
\

+server:
Symfony\Component\HttpFoundation

ServerBag {#40 ▶}
\

+files:
Symfony\Component\HttpFoundation

FileBag {#44 ▶}
\

+cookies:
Symfony\Component\HttpFoundation

InputBag {#43 ▶}
\

+headers:
Symfony\Component\HttpFoundation

HeaderBag {#39 ▶}
\

#content: null
#languages: null
#charsets: null
#encodings: null
#acceptableContentTypes: null
#pathInfo: "/"
#requestUri: "/?name=HUZAIFA+NOOR&email=hn764889%[Link]&password=asdas"
#baseUrl: ""
#basePath: null
#method: "POST"
#format: null
#session:
Illuminate\Session

Store {#274 ▶}
\

#locale: null
#defaultLocale: "en"

260
-preferredFormat: null
-isHostValid: true
-isForwardedValid: true
-isSafeContentPreferred: ? bool
-trustedValuesCache: []
-isIisRewrite: false
#json: null

#userResolver: Closure($guard = null) {#240 ▶}


#convertedFiles: null

#routeResolver: Closure() {#249 ▶}


basePath: ""
format: "html"
} */

/* We can Access All of the Data of Form in following two methods,..


- print_r($request->all())
- print_r($request->input()) */
/* Inside The Following Code We will Access the indiviual/Single data of The
Form
- print_r($request->input('name23')) // that is the name of Our
particular input Field
- print_r($request->input('email'))
- print_r($request->input('password')) */
/* Inside the Following Code we will See how can We access the form Data With the
Dynamic Properties
- print_r($request->name23);
- print_r($request->password);
- print_r($request->email); */
/* now we will Check that the input is Exist Or not ?? inside the Following
code */
/* if($request->has('name23')){
print_r($request->input('name23'));
}
*/
/* if($request->has(['name23' , 'password' , 'email'])){
print_r($request->input('name23'));
}
==> hasAny is the laravel method which will return True if anyone Input from
that is inserted OR it is TRUE*/
/* if($request->hasAny(['name23' , 'password' , 'email'])){
print_r($request->input('name23'));
} */
/* ==> there is also a filled function with that we will Check inside the
request Function the Value is present OR NOT your Data is Filled OR Not
Inside the Filled your Requested Data Will be filled
if($request->filled(['name23' , 'password' , 'email'])){
print_r($request->input('name23'));
}

261
==> missing there Is Also Another method Which will tell you that your key
is Missing OR Not?? that will run
when the user data is missing

if($request->missing(['username23','password','email'])){
print_r("UserName is Missing");
}
*/
/* There Will be also A method Which Will Run the Closure Function */
/*
This Function Will be Run When the Value inside it will be the Empty ,..
$request->whenHas('name23', function($input){
print_r('Data has Modified');
});
==> The next Function will be the whenfilled Whenfilled will be work the Valus
inside it will
be Present
*/
/* ****************** Important Function ***********************
==> flash()-- inside this Function you will See how Can you Preseerved your Old
Data,..
that you Entered inside Your input Field
$request->flesh(); This Will Put the Current input inside the Session So that
we
Will get it inside the next request
By USing the Following Code you can access the input Field Of your Old Data
print_r($request->old('names23'))
print_r($request->old('email'))
print_r($request->old('password'))
==> fleshOnly -- we will Perseverd the data particular input Field ,..

*/
/* $request->fleshOnly('name23','email');
print_r($request->old('names23'));
print_r($request->old('email'));

==>fleshExcept it will preserved All of the Data of the input Field except the
That input
field Which We have written inside this Preserved Function,.
$request->fleshExcept('password');
*/
/*
********************************************************************************** */
/* After inputing All of the Data how can you redirect the data to the
particular page,. */
/* return redirect('olddata')->withInput();

****************** Redirecting Using the named Route ****************


In the Following code We will See how Can we redirect using the named Route

262
*/
/* return redirect()->Route('old')->withInput();

************************************
If We Did Not want to redirect the particular field For that We will write up the
Following Code */
/* return redirect('olddata')->withInput($request->except('password'));
*/
return redirect()->Route('old')->withInput();

return view('Registration');
}
}

[Link]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Registration Form </title>
</head>
<body>
{{-- --}}
<form action="" method="POST">
@csrf
{{-- It will Protect us from the csrf Attacks,..
This method will easy to protect your application from cross-site
request forgery(CSR) attacks,... --}}
Name: <input type="text" name="name23" id="name"
value="{{old('name23')}}"><br><br>
E-mail: <input type="email" name="email" id="email" value="{{old('email')}}"
><br><br>
Password: <input type="password" name="password" id="password"
value="{{old('email')}}" ><br><br>
<input type="submit" value="submit">

</form>

</body>
</html>

[Link]
<!DOCTYPE html>
<html lang="en">

263
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>OLD Data blade File</title>
</head>
<body>

<h1> Form With the Old Data </h1>


<form action="" method="POST">
@csrf
{{-- It will Protect us from the csrf Attacks,..
This method will easy to protect your application from cross-site
request forgery(CSR) attacks,... --}}
Name: <input type="text" name="name23" id="name"><br><br>
E-mail: <input type="email" name="email" id="email"><br><br>
Password: <input type="password" name="password" id="password"><br><br>
<input type="submit" value="submit">

</form>

</body>
</html>

OUTPUT

264
Once We migrate a File it After that We
Cannot Add new Data inside the Column.
after running the
Command php artisan migrate

It is getting The data from the People


Database:
People::get() is used to access all the Data
People::Where(‘id’,$id)->first()  to Access the
particular data inside the Database table. And we
will Edit that data

265
Command To make Migration:
php artisan make:migration create_table_name
Databases names
ecomm_hi

emailverification

firstproject

hn1

jobholders

laraveldb

phppdo

how to Create the Admin panel in the Laravel


Command To Create admin panel in Laravel ,..

composer require open-admin-org/open-admin

Second Commmand For the Creation of the admin panel

php artisan vendor:publish --provider="OpenAdmin\Admin\


AdminServiceProvider"

Third command for the Creation Of The Admin panel,.

php artisan admin:install


Downloading link For the bootstrap theme

266
Mono - Admin Template ([Link])

267

You might also like