0% found this document useful (0 votes)
18 views

Laravel Part-1

Uploaded by

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

Laravel Part-1

Uploaded by

waver58650
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Video-1 (What is framework):-

------------------------------------------
Q. What is the framework?
A framework is a set of conceptual structure and guidelines, used to build
Something useful.

A framework may include predefined classes and functions that can be used
to process input, manage hardware devices, and interact with system
software.

The purpose of the framework is to allow developers to focus on building a


unique feature for their projects rather than writing code from scratch.

Q Why use a framework?


1. Collection of tools
2. No need to start from scratch(beginning).
3. Save time
4. Improve Productivity
5. Clean code
6. Reusable Code
7. Testing
8. Debugging

Video-2 (What is web framework):-


------------------------------------------------
Q. What is web Framework?
A web framework or web application framework which helps to build web
application.

Web frameworks provide tools and libraries to simplify common web


development operations. This can include web services,APIs, and other
resources.

Web frameworks help with a variety of tasks, from templating and database
access to session management and code reuse.

More than 80% of all web app frameworks rely on the Model View Controller
(MVC) architecture.

Some Web Framework:-


1. Laravel (PHP)
2. Codeigniter (PHP)
3. Zend
4. Django (Python)
5. Spring (Java)

Video-3 (Visual Studio Code Crash Course):-


---------------------------------------------------------------
1. Download VsCode link:-
https://code.visualstudio.com/
Go to the documentation and check the “setup” for all O.S.

Video-4 (How to install XAMPP):-


-------------------------------------------
1. Download XAMPP link:-
https://www.apachefriends.org/download.html

Video-5 (How to Fix PHP Fatal Error while running Laravel ):-
------------------------------------------------------------------------------------
1. This is an error regarding the version.
Solution:-
a. Update Composer:- composer self-update

b. Delete Vendor folder and then run:- composer update


c. Go to the “composer.json” file and update the php version
php : “7.3|^8.1
and then run the command:-composer update.
NOTE:-
All solution are different please check one by one and also check error is
removed or not

Video-6 (Composer A dependency manager for PHP ):-


----------------------------------------------------------------------------
Q. What is a Composer?
1. A composer is a tool for a dependency manager in PHP.
2. It allows you to declare the libraries your project depends on and it will
manage (install/update) them for you.
3. Composer is not a package manager in the same sense as “yum or apt”
are. Yes, it deals with “packages” or libraries, but it manage them on a per
-project basis,installing them in a directory (e.g. vendor) inside your
project.

4. By default it does not install anything globally. Thus, it is a dependency


manager. It does however support a “global” project for convenience via
the global command.

Q. Why do we use Composer?


Suppose:-
1. You have a project that depends on a number of libraries.
2. Some of those libraries depend on other libraries.

Composer:-
1. Enable you to declare the libraries you depend on.
2. Finds out which versions of which packages can and need to be installed,
and install them (meaning it downloads them into your project)

Q. How to install Composer?


Composer requires PHP 5.3.2+ version to run.

There are two ways to install composer:-


1. Download composer “.exe” from the official website then install it.
2. Use command line installation.
a. May need to set Path or use php composer.phar init

1. Check it composer is already install or not in your system:-


composer -v

2. How to update composer:-


composer self-update

3. How to Rollback composer update (It means if you have any problem in
updated version then go back to the previous version):-
composer self-update --rollback

4. List all composer command:-


composer

5. How to get help:-


compose help
6. Get help for command:-
composer help command_name
composer help self-update
OR
php composer.phar self-update (When we have not set the path)

Q. What is composer.json?
1. It is the main composer.json that defines your project requirement.
2. It is created through composer tools.

Q. How to set up a new or existing package?


1. You can also say how to create composer.json file in a project to make it
package.
2. There are two ways to create composer.json file:-
a. Using composer init command
composer init :- It is used to set up a new or existing package. The
init command creates a basic composer.json file in the current
directory.
Every project is a package.
As soon as you have a composer.json in a directory, that directory
is a package.
Asking question when we run the init command:-
i. Package Name:-
syntax:- vendorname/packagename
example:- geekyshows/geek

ii. Descriptions:-A short description of the package. Usually this is


one line long.It is required for published packages(libraries).

iii. Authors:- The authors of the package. This is an array of objects.


Each author object can have following properties:-
a. name:- The author’s name. Usually their real name.
b. email:- The author’s email address.
c. homepage:- An URL to the author’s website
d. role:- The author’s role in the project(e.g. developer or
translator)

iv. Minimum stability:- composer accepts these flags as minimum


-stability settings. The default setting for minimum-stability if not
provided is assumed to be stable, but you could define any of the
flags down the hierarchy.
a. stable (most stable)
b. rc
c. beta
d. alpha
e. dev (least stable)
v. Package Type:- Package types are used for custom installation
logic. If you have a package that needs some special logic, you
can define a custom type. It defaults to the library.
a. Library
b. Project
c. Metapackage
d. Composer-plugin

vi. Licence:- The licence of the package. This can be either a string
or an array of strings. Ex:- MIT

b. Manually creating composer.json file


i. You have to create “composer.json” file and write JSON code your
Self with required properties.
{
“name” : ”geekyshows/geeky”,
“description” : “This is my first package”
}

7. Composer Config Command:-


a. composer config –global (-g) :- Operate on the global config file
located at $COMPOSER_HOME/config.json by default. Without this
option, this command affected the local composer.json file.

b. composer config –list (-l) :- It shows all the current config variables.

c. . composer config setting-key “setting-value”- It sets the config key


to the value.
Keys:-
. name
. version
. type
. description
. licence
. homepage
. keywords
Example:- composer config name “exampleben/examplepack”
composer config --unset description
composer config --editor # local
composer config --global --editor #global

d. composer config –unset :- It removes the configuration element


named by setting-key.

e. composer config - -editor (-e) :- Opens the config file (composer.


json) in an editor. Use the –global flag to edit the global config
(config.json).
Q. How to install/add Package ?
composer require VendorName/PackageName:- This command installs
a package, and any packages that it depends on.

Syntax:-
a. composer require VendorName/PackageName
b. composer require VendorName/PackageName:tag
c. composer require VendorName/PackageName:version

Example:-
a. composer require fzaninotto/faker
b. composer require fzaninotto/faker:dev-master
c. composer require fzaninotto/faker:1.9.0
Note:-
--dev:- Add package to require -dev
composer require VendorName/PackageName --dev

Website Name for package:-https://packagist.org/

Q. How to uninstall/Remove Package?


composer remove VendorName/PackageName:- The remove command
removes packages from the composer.json file from the current directory.

Syntax:-
composer remove VendorName/PackageName
composer remove VendorName/PackageName1 VendorName/
PackageName2

Example:-
composer remove fzaninotto/faker
Note:-
--dev:- It removes packages from require -dev
Example:- composer remove fzaninotto/faker --dev
Q. How to use a package?
There are three steps to use packages:-
a. Install Package
Composer require fzaninotto/faker

b. Include autoload.php file.


require_once(‘vendor/autoload.php’);

c. Now you can use the package.


<?php
require_once(‘vendor/autoload.php’);
$faker = Faker\Factory::create();
echo $faker->name;
echo $faker->address;
echo $faker->text;
?>
Q. How to use Update Command?
composer update VendorName/PackageName:-This command is
used to get the latest versions of the dependencies and to update the
“composer.lock” file. If no package name is specified,all packages in
the specified location will be updated.

Syntax:-
a. composer update
b. composer update VendorName/PackageName
c. composer update VendorName/PackageName1 VendorName/
PackageName2
d. composer upgrade VendorName/PackageName
e. composer u VendorName/PackageName

Example:-
a. composer update fzaninotto/faker

Q. How to use install/i Command?


composer install :- The install command reads the “composer.json” file from
the current directory,resolves the dependencies and installs them into the
vendor.

If there is a “composer.lock” file in the current directory, it will use the exact
versions from there instead of resolving them. This ensures that everyone
using the library will get the same versions of the dependencies.
If there is no “composer.lock” file, composer will create one after dependency
resolution.
Example:-
composer install
Q How to clear a cache?
composer clear-cache

Q Global Command:- 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 a hidden,global (per-user on the machine) directory that is
Shared between all projects.

By default it points to C:\User\<user>\AppData\Roaming\Composer on


windows.

Q. How to list all packages?


composer show :- This command is used to list all of the available packages.
composer show VendorName/PackageName :- This command is used to
see the details of a certain package.
Example:- composer show fzaninotto/faker
composer show fzaninotto/faker 1.8.0
--all :- List all packages available in all your repositories.
--name-only (-N):- List package names only.
--path (-P) :- List package path
--tree (-t) :- List your dependencies as a tree.If you pass a package
Name it will show the dependency tree for that package.
--available (-a) :- List available package only.

Q. Create Project from a Package:-


composer create-project VendorName/PackageName ProjectName:-You
can use composer to create new projects from an existing package.

To create a new project using composer you can use the create-project
command. Pass it a package name, and the directory to create the project
in. you can also provide a version as third argument, otherwise the latest
version is used.
If the directory does not currently exist, it will be created during installation.
Example:-
composer create-project laravel/laravel myproject
composer create-project laravel/laravel myproject “5.8.*”

Composer.JSON OR Composer.Lock file:-


1. name:- It consists of vendor name and project name, separated by /.
Example:- “name” : “geekyshows/geeky”

2. description :- A short description of the package.


Example:- “description” : “Hello I am description”

3. version :- The version of the package.


Example:- “version” : “v0.8.3”

4. type:- The type of the package. It defaults to the library.


Example:- “type” : “library”

5. keywords:- An array of keywords that the package is related to. These can
be used for searching and filtering.
Example:- “keywords” : [“css”,”parser”,”stylesheet”]

6. homepage:- An URL to the website of the project.


Example:- “homepage” : “https://github.com/geekyshows/geek”

7. time:- Release date of the version.


Example:- “time” : “2018-12-14T02:40:31+00:00”

8. _readme :- A relative path to the readme document


Example:- “readme”:[
“This file lock the dependencies of your project to a known state”,
“Read more about it at https://getcomposer.org/doc/01-basic-usage
.md#installing-dependencies”,
“This file is @generated automatically”
]
9. licence :- The licence of the package. This can be either a string or an
array of strings. Example:-MIT
{
“licence” :”MIT”
}
10. authors:- The authors of the package. This is an array of objects. Each
author object can have following properties:
--name:- The author’s name. Usually their real properties.
--email:- The author’s email address
--homepage :- An URL to the author’s website.
--role:- The author’s role in the project (e.g.developer or translator)
"authors": [
{
"name": "Alexander",
"email": "[email protected]",
“homepage” : “https://www.geekyshows.com”,
“role” : ”Developer”
}

11. require:- Lists packages required by this package. The package will not
be installed unless those requirements can be met.
Example:-
"require": {
"dasprid/enum": "^1.0.3",
"ext-iconv": "*",
"php": "^7.1 || ^8.0"
}
12. require-dev:- Lists packages required for developing this package, or
running tests, etc. The dev requirements of the root package are
Installed by default.
Example:-
"require-dev": {
"phly/keep-a-changelog": "^2.1",
"phpunit/phpunit": "^7 | ^8 | ^9",
"spatie/phpunit-snapshot-assertions": "^4.2.9",
"squizlabs/php_codesniffer": "^3.4"
}

13. autoload:- Autoload mapping for a PHP autoloader.


PSR-4
Classmap
Files

14. autoload-dev:- This section allows to define autoload rules for


Development purpose.
PSR-4
Classmap
Files
Autoloading Concept:-
1. autoload:- Autoload mapping for a PHP autoloader.
2. autoload-dev:- This section allows defining autoload rules for development
purposes.
a. files
b. classmap
c. psr-4

Command:- dump-autoload/dumpautoload
If you need to update te autoloader because of new classes in a classmap
package for example,you can use dump-autoload to do that having to go
through an install or update.
Example:- composer dump-autoload

a. Files:-
1. 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 functions that cannot be autoloaded by
PHP.

2. The files references are all combined,into a single key => value
array which may be found in the generated file Vendor/composer/
autoload_files.php

composer.json:-
{
"autoload": {
"files": [
"src/MyLibrary/functions.php",
“realme/realme2.php”,
“redmi/redmi2.php”,
“redmi/redmi3.php”

]
}
}

b. Classmap:-
1. This scanning for classes in all .php and .inc files in the given
directories/files.
2. The 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.

3. You can use the classmap generation support to define autoloading


for all libraries that do not follow PSR-0/4.
Example:-
composer.json
{
"autoload": {
"files": [
"src/MyLibrary/functions.php",
“realme/realme2.php”,
“redmi/redmi2.php”,
“redmi/redmi3.php”

],

"classmap": [

"./realme/realmemobile.php",

“./redmi/redmimobile.php”,

“myclass/” // this is a directoy

],

"exclude-from-classmap": [

"./myclass/class2.php"

// Excluding this file

}
}
c. PSR-4:-
1. Under the PSR-4 key you define a mapping from namespaces to paths,
relative to the package root.
2. The PSR-4 references are all combined, during install/update, into a
single key => value array which may be found in the generated file
vendor/composer/autoload_psr4.php.
3. You can use the classmap generation support to define autoloading for all
libraries that do not follow PSR-0/4.
Composer.json
{
"autoload": {
"psr-4": {
“Product\\”:”Product/”
“Product\\cool\\”:”Items/”
/* Here Items is a folder name*/
}
}
}
Specification:
\<NamespaceName>(\<subNamespceNames>)*\<className>

Classmap V/S PSR-4 :-


1. PSR-4 does not need repeated dumpautoload for every change or
addition of new files.
while classmap requires dumpautoload for every change
in existing files containing classes or addition of new file in specified
directory.

Video-7 (What is MVC):-


---------------------------------
Q. What is MVC?
1. The MVC is an architectural pattern that separates an application into
three main logical components Model,View and Controller.
2. Each of these components has their own role in a project.
3. MVC model was first introduced in 1987 in the smalltalk programming
language.
4. More than 80% of all web app frameworks rely on the model view
Controller architecture.

Q. What is a Model?
The Model is responsible for getting data from a database, packaging it in
Data objects that can be understood by other components, and delivering
those objects, most of which will happen in response to input from the
Controller.

Q. What is a View?
1. It represents how data should be presented to the application user. Users
can read or write the data from view.
2. Basically it is responsible for showing end user content, we can say it is a
user interface. It may contain HTML, CSS, JS.
Q. What is a Controller?
1. The user can send request by interacting with view, the controller handles
these requests and sends to model then get appropriate response from
the model, sends response to view.
2. It may also have required logics
3. It works as a mediator between views and models.

Q. Why use MVC?


1. Organised code
2. Independent Block
3. Reduce the complexity of web applications
4. Easy to maintain
5. Easy to modify

Video-8 (Download and run laravel study material):-


-----------------------------------------------------------------------

Video-9 (Introduction of laravel):-


-----------------------------------------------
Q. What is laravel?
1. Laravel is a free, open-source PHP based web framework for
building high end web application, following the model view controller
architecture pattern and based on Symfony.

2. It was created by Taylor Otwell.


3. Laravel source code : http://github.com/laravel/framework

Advantage of laravel:-
1. Open source
2. Collection of tools
3. Save time
4. Improve productivity
5. Robust and easy
6. Security of the application
7. Authentication
8. Routing
9. Templating

Video- 10 (Requirement of learning laravel):-


-------------------------------------------------------------
1. HTML
2. CSS
3. JavaScript
4. SQL
5. PHP OOPS
6. MVC
7. Composer

Laravel Requirement:-
1. PHP 7.2.0 or High
2. XAMPP/WAMPP/LAMPP/MAMP
3. Composer
4. Text Editor
5. Web Browser

Video-11 (How to install laravel and create project):-


-----------------------------------------------------------------------
Q. How to install laravel?
There are two ways to install laravel :-
1. Download the laravel installer using composer :-
a. composer global require laravel/installer
Then use laravel new command will create a fresh Laravel
Installation in the directory you specify.

b. laravel new projectname

Note:-
Remove the global composer:- composer global remove laravel/installer

2. Using create-project command :-


composer create-project --prefer-dist laravel/laravel projectname

You might also like