Showing posts with label Laravel. Show all posts
Showing posts with label Laravel. Show all posts
Structure of a Laravel application
Unknown
Structure of a Laravel application.
In the next two chapters, we will be installing Laravel and creating our first application. Any new project already has a complete directory tree and even some placeholder files to get you up and running in very little time. This structure is a great starting point, but as we will see in the final chapter of this book, it is also customizable. Here is what it looks like:
|
./app/
|
# Your Laravel application
|
|
./app/commands/
|
# - Command line scripts
|
|
./app/config/
|
# - Configuration files
|
|
./app/controllers/
|
# - Controllers
|
|
./app/database/
|
# - Database migrations and
seeders
|
|
./app/lang/
|
# - Localisation variables
|
|
./app/models/
|
# - Classes used to
represent entities
|
|
./app/start/
|
# - Startup scripts
|
|
./app/storage/
|
# - Cache and logs
directory
|
|
./app/tests/
|
# - Test cases
|
|
./app/views/
|
# - Templates that are
rendered to HTML
|
|
./app/filters.php
|
# -
Filters executed before/after a request
|
|
./app/routes.php
|
# - URLs and actions
|
|
./bootstrap/
|
# Application bootstrapping
scripts
|
|
./public/
|
# Document root
|
|
./public/.htaccess
|
# - Sends incoming requests
to index.php
|
|
./public/index.php
|
# - Starts Laravel
application
|
|
./vendor/
|
# Third-party dependencies
installed
|
|
|
through Composer
|
|
./artisan*
|
# Artisan command line
utility
|
|
./composer.json
|
# Project dependencies
|
|
./phpunit.xml
|
# Test configuration file
for PHPUnit
|
|
./server.php
|
# Local development server
|
Like
the rest of Laravel, the naming is expressive, and it is easy to guess what
each folder is for. On the first level, there are four directories, app/,
bootstrap/,
public/,
and vendor/. All your server-side code will reside in
the app/ directory,
inside which you will find the three
directories that hold the files for the controllers, models, and views. We will
explore the responsibilities of each directory further in the next chapters.
01:45
Laravel
Laravel's Advantages
Unknown
Laravel's Advantages
Let us now look at what you get when you start a project with Laravel and how these
features can help you boost your productivity:
• Modularity: Laravel was built on top of over 20 different libraries and is itself split up into individual modules. Tightly integrated with Composer Dependency Manager, it can be updated with ease.
• Testability: Built from the ground up to ease testing, Laravel ships with several helpers that let you visit routes from your tests, crawl the resulting HTML, ensure that methods are called on certain classes, and even impersonate authenticated users.
• Routing: Laravel gives you a lot of flexibility when you define the routes of your application. For example, you may manually bind a simple anonymous function to a route with an HTTP verb, such as GET, POST, PUT, or DELETE.This feature is inspired by micro-frameworks, such as Sinatra (Ruby) and Silex (PHP). Moreover, it is possible to attach filter functions that are
executed on particular routes.
• Configuration management: More often than not, your application will be running in different environments, which means that the database or e-mail server credentials settings or the displaying of error messages will be different when your app is running on a local development server than when
it is running on a production server. Laravel lets you define settings for each environment and then automatically selects the right settings depending on
where the app is running.
• Query builder and ORM: Laravel ships with a fluent query builder, which lets you issue database queries with a PHP syntax where you simply chain methods instead of writing SQL. In addition to this, it provides you with an Object relational mapper (ORM) and ActiveRecord implementation, called Eloquent, which is similar to what you would find in Ruby on Rails to help you define interconnected models. Both the query builder and the ORM are compatible with different databases, such as PostgreSQL, SQLite, MySQL,
and SQL Server.
• Schema builder, migrations, and seeding: Also inspired by Rails, these features allow you to define your database schema with PHP code and keep track of any changes with the help of database migrations. A migration is a simple way of describing a schema change and how to revert to it. Seeding allows you to populate selected tables of your database, for example, after running a migration.
• Template engine: Partly inspired by the Razor template language in ASP. NET MVC, Laravel ships with Blade, a lightweight template language with which you can create hierarchical layouts with predefined blocks where dynamic content is injected.
• E-mailing: With its Mail class, which wraps the popular SwiftMailer library, Laravel makes it very easy to send an e-mail, even with rich content and attachments, from your application.
• Authentication: Since user authentication is such a common feature in web applications, Laravel provides you with the tools to register, authenticate, and even send password reminders to users.
• Redis: It is an in-memory key-value store that has a reputation for being extremely fast. If you give Laravel a Redis instance that it can connect to, it can use it as a session and general-purpose cache and also give you the possibility to interact with it directly.
• Queues: Laravel integrates with several queue services, such as Amazon SQS and IronMQ, to allow you to delay resource-intensive tasks, such as the e-mailing of a large number of users, and run them in the background rather than keep the user waiting for the task to complete.
01:28
Laravel
What is Laravel
Unknown
What is Laravel ?
In the jungle of PHP frameworks, the latest newcomer, Laravel, has been getting
more and more attention recently. On many discussion forums, it has even
dethroned CodeIgniter and Symfony as the number one recommended framework.
What is it about this framework that makes both young and seasoned developers
rave about it?
In this chapter, we will cover the following topics:
• How web application frameworks help to increase productivity
• The fundamental concepts and the key features of Laravel
• The general structure and conventions of a Laravel application
• General advice if this is the first time you are working with a
Model-View-Controller (MVC) framework
• Migration tips for users of the previous version of Laravel
We will look at its key features and how they have made Laravel an indispensable
tool for many web developers. We will present the limitations of PHP, especially
when it is used without a modern framework, and how Laravel helps you to
overcome those shortcomings and write more robust, and more structured,
applications. Then, we will take a closer look at the anatomy of a Laravel application
and present the different features of PHP as well as the third-party packages it
leverages. After reading this chapter, you will have all the conceptual knowledge
that is required to get started and build your first application.
The need for frameworks
Of all the server-side programming languages, PHP undoubtedly has the weakest
entry barriers. It is almost always installed by default on even the cheapest web
hosts, and it is also extremely easy to set up on any desktop operating system. For
newcomers who have some experience with HTML, the concepts of variables, inline
conditions, and include statements are easy to grasp. PHP also provides many
commonly used functions that one might need when developing a website. All of
this contributes to what some refer to as the immediacy of PHP. However, this instant
gratification comes at a cost. It gives a false sense of productivity to beginners, who
almost inevitably end up with unnecessarily complex and tangled code as they add
more features to their site. This is mainly because PHP, out of the box, does not do
much to encourage the separation of concerns.
The limitations of homemade tools
If you already have a few PHP projects under your belt, but have not used a web
application framework before, then you will probably have your personal collection
of commonly used functions or classes that you have amassed from one project to the
next. These utilities help you solve recurring problems, such as sanitizing database
calls, authenticating users, and including pages dynamically. You might also have a
predefined directory structure where these classes and the rest of your application
code reside. However, all of this will exist in complete isolation; you would be solely
responsible for the maintenance, inclusion of new features, and documentation.
This can be a tedious and time-consuming task. Not to mention that if you were
to collaborate with other developers on the project, they would first have to get
acquainted with the way you build applications.
Laravel to the rescue
This is exactly where a web application framework such as Laravel comes to the
rescue. Laravel re-uses and assembles existing components to provide you with
a cohesive layer upon which to build your web applications in a more structured
and pragmatic way. Drawing inspiration from popular frameworks written in both
PHP and other programming languages, Laravel offers a robust set of tools and an
application architecture that incorporates many of the best features of CodeIgniter,
Yii, ASP.NET MVC, Ruby on Rails, and Sinatra.
If you have already used one of those tools or a different framework that implements
the Model-View-Controller (MVC) paradigm, you will find it very easy to get
started with Laravel 4.
In the jungle of PHP frameworks, the latest newcomer, Laravel, has been getting
more and more attention recently. On many discussion forums, it has even
dethroned CodeIgniter and Symfony as the number one recommended framework.
What is it about this framework that makes both young and seasoned developers
rave about it?
In this chapter, we will cover the following topics:
• How web application frameworks help to increase productivity
• The fundamental concepts and the key features of Laravel
• The general structure and conventions of a Laravel application
• General advice if this is the first time you are working with a
Model-View-Controller (MVC) framework
• Migration tips for users of the previous version of Laravel
We will look at its key features and how they have made Laravel an indispensable
tool for many web developers. We will present the limitations of PHP, especially
when it is used without a modern framework, and how Laravel helps you to
overcome those shortcomings and write more robust, and more structured,
applications. Then, we will take a closer look at the anatomy of a Laravel application
and present the different features of PHP as well as the third-party packages it
leverages. After reading this chapter, you will have all the conceptual knowledge
that is required to get started and build your first application.
The need for frameworks
Of all the server-side programming languages, PHP undoubtedly has the weakest
entry barriers. It is almost always installed by default on even the cheapest web
hosts, and it is also extremely easy to set up on any desktop operating system. For
newcomers who have some experience with HTML, the concepts of variables, inline
conditions, and include statements are easy to grasp. PHP also provides many
commonly used functions that one might need when developing a website. All of
this contributes to what some refer to as the immediacy of PHP. However, this instant
gratification comes at a cost. It gives a false sense of productivity to beginners, who
almost inevitably end up with unnecessarily complex and tangled code as they add
more features to their site. This is mainly because PHP, out of the box, does not do
much to encourage the separation of concerns.
The limitations of homemade tools
If you already have a few PHP projects under your belt, but have not used a web
application framework before, then you will probably have your personal collection
of commonly used functions or classes that you have amassed from one project to the
next. These utilities help you solve recurring problems, such as sanitizing database
calls, authenticating users, and including pages dynamically. You might also have a
predefined directory structure where these classes and the rest of your application
code reside. However, all of this will exist in complete isolation; you would be solely
responsible for the maintenance, inclusion of new features, and documentation.
This can be a tedious and time-consuming task. Not to mention that if you were
to collaborate with other developers on the project, they would first have to get
acquainted with the way you build applications.
Laravel to the rescue
This is exactly where a web application framework such as Laravel comes to the
rescue. Laravel re-uses and assembles existing components to provide you with
a cohesive layer upon which to build your web applications in a more structured
and pragmatic way. Drawing inspiration from popular frameworks written in both
PHP and other programming languages, Laravel offers a robust set of tools and an
application architecture that incorporates many of the best features of CodeIgniter,
Yii, ASP.NET MVC, Ruby on Rails, and Sinatra.
If you have already used one of those tools or a different framework that implements
the Model-View-Controller (MVC) paradigm, you will find it very easy to get
started with Laravel 4.
00:13
Laravel
Subscribe to:
Posts
(
Atom
)
