Laravel Part-1
Laravel Part-1
------------------------------------------
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.
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.
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
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)
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
Q. What is composer.json?
1. It is the main composer.json that defines your project requirement.
2. It is created through composer tools.
vi. Licence:- The licence of the package. This can be either a string
or an array of strings. Ex:- MIT
b. composer config –list (-l) :- It shows all the current config variables.
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
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
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
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.
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.*”
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”]
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"
}
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.
],
"classmap": [
"./realme/realmemobile.php",
“./redmi/redmimobile.php”,
],
"exclude-from-classmap": [
"./myclass/class2.php"
}
}
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>
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.
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
Laravel Requirement:-
1. PHP 7.2.0 or High
2. XAMPP/WAMPP/LAMPP/MAMP
3. Composer
4. Text Editor
5. Web Browser
Note:-
Remove the global composer:- composer global remove laravel/installer