Understanding Laravel Framework Basics
Understanding Laravel Framework Basics
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.
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.
4
How to roll back the Composer update:
composer self-update --rollback.
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
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.
[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”: {}
}
}
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”
}
]
}
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
This command will guide you through creating your [Link] config.
13
Package Type (e.g. library, project, metapackage, composer-plugin) []:
License []:
{
"name": "vendorkaname/huzaifa",
"description": "\"This is my First package\"",
"autoload": {
"psr-4": {
"Vendorkaname\\Huzaifa\\": "src/"
}
},
"authors": [
{
"name": "HuzaifaNoor",
"email": "contact@[Link]"
}
],
"require": {}
}
[Link]
{
"name": "vendorkaname/huzaifa",
"description": "\"This is my First package\"",
"autoload": {
"psr-4": {
"Vendorkaname\\Huzaifa\\": "src/"
}
},
"authors": [
{
14
"name": "HuzaifaNoor",
"email": "contact@[Link]"
}
],
"require": {}
}
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": {}
}
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
}
17
}
},
"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": {}
}
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.
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;
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.
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
27
└──php >=5.3.3
PS C:\Users\LENOVO\OneDrive\Documents\XAMPP\htdocs\CMP>
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.
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.
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.
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.
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/”
]
}
}
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
==>Remember
For Functions we will use the Files of the Composer.
For classes we will use the Classmap of the composer.
*/
displaymodel1();
displaymodel2();
displaymodel3();
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
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.
[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;
[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
Composer Documentation
[Link]
All Commands
[Link]
Packages
[Link]
43
View
It represent how data should be presented to the application user. User can read or
write the data from view.
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.
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.
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.
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.
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.
49
CSS
JAVASCRIPT
SQL
PHP OOP
MVC
Composer
Laravel/installer
Laravel/installer
50
We just Have to Run Only that Command.
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.
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.
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
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.
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.
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(){
});
Example:
60
Route::get(‘about’,function(){}
Example:
Route::get(‘about’,function() {
});
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;
});
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.
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.
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.
return $id.$name;
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.
Syntax:
Route::redirect(‘/here’,’/there’);
Example:
Route::redirect(‘/login-success’,’/dashboard’);
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);
});
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.
});
huzaifanoor routes [Link] ( Here we will Start Our Work in Case if our Project is working Perfectly)
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.*/
});
OUTPUT
Write the command in URL
[Link]:8000/about
OUTPUT
Hello World
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.*/
});
OUTPUT
The URI Command is the following because
[Link]:8000/user/933434
OUTPUT
933434
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
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;
});
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
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!
|
*/
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.)
//
}) 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!
*/
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!
*/
OUTPUT
Before Redirecting URL Command:
[Link]:8000/yaha2
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 ??";
});
OUTPUT
Correct URL Command:
[Link]:8000/name
OUTPUT
HELLO HOW ARE YOU ??
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 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>
</body>
</html>
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’);
})
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>
</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
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>
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.
Inside your View, you can then access each Value using its Corresponding key.
Example 1:-
Route::get(‘contact’,function() {
// Here we are using the associative array And the key is “name” and the value is “HUZAIFANOOR”
});
Example:
Route::view(‘contactme’)->with(‘name’,’HUZAIFANOOR’)
});
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.
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
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
[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
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.
Routes/[Link]
Routes::get(‘about’,function() { Routes
});
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.
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
<?php
namespace App/http/Controllers;
use Illuminate\Http\Requests;
………………………………..
(The basic Code For the Controller is already Written inside The File Whenever you hit the Command to Create
the Controller.)
app/Http/Controllers
[Link]
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.*/
function show();
?>
use App\Http\Controllers\AboutController.
Route::get(‘about’.[AboutController::class, ’show’]);
Syntax:
Route::get(‘uri’,[ControllerName::class, ‘method_name’]);
[Link]
<?php
namespace App/Http/Controllers;
101
use App\Http\Controllers\Controller;
use illuminate\Http\Request;
function show($name){
use App\Http\Controllers\AboutController;
Route::get(‘about/{name}’),
[ AboutConotroller::class , ‘show’]);
[Link]
<?php
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
[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
105
}
}
106
class AdminProfileController extends Controller
{
function show_profile(){
return view(‘[Link]’)
}
}
<body>
</body>
</html>
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');
});
ControllerFile([Link])
<?php
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;
ViewFile()
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
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;
111
function show($name){
Defining Routes
routes/[Link]
use App\Http\Controllers\AboutController;
Routes::get(‘about/{name}’),
[AboutController::class.’show’]);
Defining View
resources/views/
[Link]
<html>
<body>
</body>
</html>
Execution Flow
Route Controller View
112
<?php
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
[Link]
<?php
namespace App/Http/Controllers;
use App\Http\Controllers\Controller;
use illuminate\Http\Request;
114
class AboutController extends Controller
function show(){
$name = ‘Laravel’;
Defining Routes
routes/[Link]
use App\Http\Controllers\AboutController;
Routes::get(‘about’),[AboutController::class,’show’]);
Defining View
resources/views/
[Link]
<html>
<body>
</body>
</html>
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');
});
ControllerFile([Link])
<?php
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>
</body>
</html>
118
resources/views/
[Link]
<html>
<body>
</body>
</html>
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');
});
119
Route::get('about1',[AboutController::class,'show1']);
Route::get('about2',[AboutController::class,'show2']);
ControllerFile([Link])
<?php
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.
Controller Code
121
app/Http/Controllers/Show/[Link]
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
return view(‘aboutme’);
Route Defining
routes\[Link]
use App\Http\Controller\ShowAbout;
Route::get(‘about’,ShowAbout::class);
View Defining
resources/views/
[Link]
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');
});
ControllerFile([Link])
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
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}}
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.
Conditional Directives
Condition Directives For the if Statements Will be With the @ symbol ,..
@if(Condition)
……………
@endif
@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
Authentication Directives
Authentication directives Were basically Used for the Lgoin and Logout page
Authentication.
@auth
// User is Authenticated
@endif
@guest
@endguest
@auth('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’)
@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
// running in env_name
@endenv
@env([‘env1’,’env2’])
@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.
129
………………………..
@endfor
// every Element Of an Array Should be Gone inside the array And you can print that
value.
@endforeach
//If Any value Exist inside The array then it Will go inside the loop. Else it will Go inside
the @empty
@empty
…………………….
@endforelse
@endwhile
Note:- We can also Do the nested loop Directives inside The blade of the
Laravel.
130
Break Directives Should be The Following.
@foreach(array_names as values)
…………………..
@if(Condition)
@break
@endif
………………..
@endforeach
……………………
@if(Condition)
@continue
@endif
…………………….
@endforeach
@break(Condition)
@endif
131
………………..
@endforeach
……………………
@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)
// 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)
@if ($loop->parent-first)
@endif
@endforeach
@endforeach
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;
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;
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 --}}
{{-- 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
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
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
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
_____________________________________
144
Product Search
Add to Chart
User Order placement
Order Detail
Order History
User Profile
Style and Bootstrap
145
To insert that Fake data into the Table of our Database We should have to Do
Seeding
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.
First of All we will Create a model So, that we will Fetch the data.
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.
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.
149
Logout and Login Complete
Make Login and the Logout menu
Make the Logout Route.
Show username When User is login
Test Complete Features.
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
150
Creation of Order Table
Make Migration For Order Table.
Add Order required Field
Migrate Table
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,….
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)
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
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
IncludeIf Directive
If you Would like to include a View that may or may not be Present, you should use the
@includeifDirective.
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
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
160
xioami A13
LG GK5
Apple 14 PRO MAX
SAMSUNG A13
INFINIX HOT 11 Play
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
163
xioami A13
LG GK5
Apple 14 PRO MAX
SAMSUNG A13
INFINIX HOT 11 Play
Once Directive
The @once directive allows you to define a portion of the template that will Only
be evaluated once per rendering Cycle.
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
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.
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.
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.
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
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.
namespace App\View\Components;
use illuminate\view\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;
}
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.
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;
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;
173
$this->subTitle = $subTitle;
$this->description = $description;
}
/**
* Get the view / contents that represent the component.
*/
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..
return $a + 20;
{{$addNumber(10)}}
Practical
[Link](App=>View=>Component=>card)
<?php
namespace App\View\Components;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
175
/* Here we will define Our card variable So that We will pass the data inside the
Componenet */
public $title;
public $subTitle;
public $description;
/**
* Get the view / contents that represent the component.
*/
}
}
[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.
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
</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;
/**
180
* Get the view / contents that represent the component.
*/
}
}
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 />
Slot
You will often need to pass additional content to your component via “slots”.
<x-alert>
</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>
{{$slot}}
</div>
Named Slot
Defining Component Named Slot.
<x-alert>
183
<span> Hello I am Alert </span>
</x-alert>
<div>
{{$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.
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.
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,…
Resources/views/Components/[Link]
<html>
<head>
<title> {{$title}}</title>
</head>
<body>
{{ $slot }}
</body>
</html>
resources/views/[Link]
<x-layout name=”title”>
186
HOME
</x-slot>
<h1> This is Home Page </h1>
</x-Layout>
Contact
</x-slot>
<h1> This is Contact page </h1>
</x-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-layout>
[Link]
{{-- Here we will rendered the Basic layout Of the Program that are Written inside
The Component --}}
<x-layout>
</x-layout>
OUTPUT
Home Page
188
This is Banner
Contact Page
This is Banner
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”>
<body>
189
@yeild(‘page-name’)
@yeild(‘banner’)
@yeild(‘main’)
@section(‘default-content’)
@show
// yield Directive and the Section Directive Both Will Work Togather,.
//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.
@extends(“[Link]”)
190
@extends(“[Link]”)
@section(“title”,”Home”)
@section(‘default-content’)
@parent
@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
[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
194
This is the main Content of the Contact Page
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;
}
[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
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.
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.
Now you can write css and js code inside resources folder and it will
automatically compiled and will be available 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.
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.
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>
202
<script src={{asset('js/[Link]')}} ></script>
<script src={{asset('js/[Link]')}} ></script>
<script src={{asset('js/[Link]')}} ></script>
</body>
</html>
OUTPUT
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,..
// 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
}
[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;
[Link]
220
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
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;
[Link]
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
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>
[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>
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
}
[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.
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')
OUTPUT
241
242
(If you want to Request the HTTP request for
the Specific Route For that we will Follow the
below process.)
Route::get(‘/profile’,function({
//
})->middleware(‘auth’);
Route::get(‘/’, function(){
//
})->middleware([‘first’,’second’]);
App(Folder)->HTTP(Folder)
[Link]
<?php
namespace App\Http;
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
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;
/**
* 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;
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.
resources/views/[Link]
@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
</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.
dd($request);
return view(‘registration’);
258
}
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;
/* 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
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();
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>
</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
265
Command To make Migration:
php artisan make:migration create_table_name
Databases names
ecomm_hi
emailverification
firstproject
hn1
jobholders
laraveldb
phppdo
266
Mono - Admin Template ([Link])
267