by jay patel
Laravel Framework is a popular PHP framework that is taking the web development community by storm. Laravel is the Most Starred PHP Framework on Github: more than 30 000 developers from all over the world (mostly from the USA) use it for custom software development.
Installing Laravel Homestead Virtual Machine
Use Laravel Homestead (pre-packaged Vagrant box) as your development environment. Vagrant is the command line utility for building and maintaining portable virtual development environments.
Laravel Homestead runs on any Windows, Mac, or Linux system, and includes the Nginx web server, PHP 7.0, MySQL, Postgres, Redis, Memcached and a variety of other useful utilities. With Laravel Homestead it is not required to separately install PHP, a web server, and any other server software on your local machine.
https://laracasts.com/series/laravel-5-fundamentals/episodes/2 (Video: Virtual Machines and Homestead)
https://scotch.io/tutorials/getting-started-with-laravel-homestead
https://code.tutsplus.com/courses/get-started-with-laravel-5/lessons/working-from-linux-or-os-x
Laravel framework consists of many separate components that are downloaded and put together automatically into a framework through a special tool called “Composer” (a tool for dependency management in PHP). So, before using Laravel, make sure you have Composer installed on your machine.
https://laracasts.com/series/laravel-5-fundamentals/episodes/1 (Video: Meet Composer)
https://laracasts.com/series/laravel-5-from-scratch/episodes/1(Video: Initial Setup)
Artisan is the command-line interface included with Laravel. Artisan offers many useful commands that can help you perform various tasks, such as generating migrations or publishing a package's assets. In addition to the built-in commands, you can extend Artisan with your own commands.
Artisan comes with Laravel by default. If your php
command works fine, then the only thing you need to do is to navigate to the project's root folder. The root folder is the parent folder of the app
folder.
The "hello world" for frameworks is to figure out how to process a given URI, and display the appropriate HTML on the page.
Routes define the endpoints of a web application, the final destinations of incoming requests. All Laravel routes are defined in the route files, which are located in the routes
directory. These files are automatically loaded by the framework. For most applications, you will begin by defining routes in your routes/web.php
file.
Views are used to build up the resulting page that the user will see in their browser when they click on a link or submit a form. Typically a view is the HTML response returned by the application to the browser initiating the request. Views can be loaded directly from the routing file. Views are stored in the resources/views
directory. View files have a .php file extension or a .blade.php file extension if you use the Blade templating engine.
Using route closures (defining all of your request handling logic as closures in route files, without controllers) is very useful for small projects that don't require too much functionality. Closure based routes cannot be cached. To use route caching, you must convert any closure routes to controller classes.
https://laracasts.com/series/laravel-5-from-scratch/episodes/2 (Video: Your First View and Route)
https://laracasts.com/series/laravel-5-fundamentals/episodes/4 (Video: Passing Data to Views)
For most projects you may wish to organize request handling logic using controllers. Controllers are PHP classes that contain application’s logic and are called from the application’s routing files. Controllers contain methods called “actions” that direct the execution flow of a web application by working with application’s data (models), producing output (views) or redirecting. Controllers can group related request handling logic into a single class. The controllers need to be connected to the routing mechanisms in order to be executed when the application runs. Controllers are stored in the app/Http/Controllers
directory.
By creating a controller and specifying which routes in the routing file use its member functions you are able to take full advantage of MVC pattern in your Laravel applications.
Another important advantage of using controllers with routes instead of putting all code into the “route.php” file is that using separate PHP classes to build application’s functionality brings the full benefits of Object Oriented Programming (OOP) such as dependency injection, encapsulation, inheritance and more. This aspect of application architecture is incredibly important for developers who practice good design patterns in their applications.
If your application is using controller based routes, you should take advantage of Laravel's route cache. Using the route cache will drastically decrease the amount of time it takes to register all of your application's routes. In some cases, your route registration may even be up to 100x faster.
https://laracasts.com/series/laravel-5-fundamentals/episodes/3 (Video: A Gentle Introduction to Routing, Controllers, and Views)
https://laracasts.com/series/laravel-5-from-scratch/episodes/4 (Video: Routing to Controllers)
Laravel uses its own view template engine called “Blade”. Blade template engine is fantastic for reducing or simplifying the code that you write in your view. Blade template engine also allows you to easily create layouts, extend them and include partials to prevent you from repeating the same HTML in multiple files. Using Blade makes it is possible to combine many templates (for example, header.blade.php, footer.blade.php and sidebar.blade.php) into a single HTML output. To reduce duplication, Blade provides "layout files." Within these files, you can define the wrapping HTML, which nests the content from each of your views.
https://laracasts.com/series/laravel-5-from-scratch/episodes/3 (Video: View Data and Blade)
https://laracasts.com/series/laravel-5-from-scratch/episodes/5 (Video: Layout Files)
https://laracasts.com/series/laravel-5-fundamentals/episodes/5 (Video: Blade)
When it comes to including your assets (CSS and JavaScript files), you can create directories within your public folder and add it directly in your view file. This is great for small projects.
But if you need to use CSS preprocessors, or concatenate some files and minify them, Laravel Elixir (a tool to integrate Gulp into your Laravel projects, a task runner built as a wrapper around Gulp) will help you.
Gulp is a well-known JavaScript-based task runner - an automated tool for performing repetitive tasks like concatenation, minification, unit testing, linting etc. With Gulp you can create tasks to watch, compile, concatenate, minify and auto-prefix your CSS and Sass/Less, concatenate and minify JS, minify HTML and optimise images.
Elixir is built on top of Gulp, so to run your Laravel Elixir tasks you only need to run the gulp
command in your terminal. Make sure that you install Gulp globally first.
https://laracasts.com/series/laravel-5-from-scratch/episodes/6 (Video: How to Manage Your CSS and JS)
https://laracasts.com/series/laravel-5-fundamentals/episodes/19 (Video: Manage Your Assets)
https://www.sitepoint.com/meet-elixir-the-laravel-way-of-compiling-assets/
Currently, Laravel supports four database systems: MySQL, Postgres, SQLite, SQL Server. The database configuration for your application is located at config/database.php
. In this file you may define all of your database connections, as well as specify which connection should be used by default.
Laravel interprets the data stored in the database into objects that you can easily manipulate like you would manipulate any other PHP object. This allows the developer to focus on other parts of the application instead of figuring out complex Structured Query Language (SQL) queries necessary to work with the data.
Laravel comes with two powerful sets of features to execute database operations, by using its own Query Builder or by using concept of “models” in Eloquent ORM. You can use both in the same application (even combine both to get the most flexibility out of DB operations).
Laravel’s Query Builder provides a clean and simple interface for executing database queries. It is a powerful tool that can be used for various database operations such as retrieving records, inserting new records, deleting records, updating records, performing “Join” queries, executing raw SQL queries, filtering, grouping and sorting of records
Laravel makes interacting with databases extremely simple usingthe Eloquent ORM (the most preferred way to fetch data and render it in the view). The Eloquent ORM provides an ActiveRecord implementation to work with your database. This means that each model corresponds to a table in your database. We can use Eloquent to interact with our database and do the basic CRUD functions, set up and use one-to-one relationships, one-to-many relationships, AND many-to-many relationships.
Some of the advanced database operations that Laravel provides out of the box are managing database tables and fields through special files called “migrations”, populating database with sample data (also called “seeding”), working with separate read/write databases, pagination, many different relationship types and advanced methods of querying relations, database transactions and query logging.
https://laracasts.com/series/laravel-5-from-scratch/episodes/7 (Video: Fetching data)
https://laracasts.com/series/laravel-5-fundamentals/episodes/7 (Video: Migrations)
https://laracasts.com/series/laravel-5-from-scratch/episodes/8 (Video: Defining Relationships With Eloquent)
https://laracasts.com/series/laravel-5-fundamentals/episodes/8 (Video: Eloquent)
https://laracasts.com/series/laravel-5-fundamentals/episodes/9 (Video: Basic Model/Controller/View Workflow)
https://laracasts.com/series/laravel-5-fundamentals/episodes/11 (Video: Dates, Mutators, and Scopes)
https://laracasts.com/series/laravel-5-fundamentals/episodes/27 (Video: Loose Ends and Wrapping Up)
https://scotch.io/tutorials/a-guide-to-using-eloquent-orm-in-laravel
http://www.laravelsd.com (Laravel Schema Designer)
Forms exist in just about every single web application. How does it work in Laravel? Let's review the basic workflow for submitting a form, fetching the data that was sent through, and then creating a record in the database.
You'll of course need to modify existing records in the database. Let's review the process of creating an "edit" page to handle this very task. Along the way, we'll also get a chance to review PATCH requests and the concept of eager loading and the problems it solves.
Along the way, you'll be introduced to custom packages, service providers, and much more.
https://laracasts.com/series/laravel-5-from-scratch/episodes/9 (Video: Forms)
https://laracasts.com/series/laravel-5-fundamentals/episodes/10 (Video: Forms)
https://laracasts.com/series/laravel-5-from-scratch/episodes/10 (Video: Updating Records and Eager Loading)
Laravel provides several different approaches to validate your application's incoming data. Let's look at a complete example of validating a form and displaying the error messages back to the user.
https://laracasts.com/series/laravel-5-from-scratch/episodes/11 (Video: Validation and More)
https://laracasts.com/series/laravel-5-fundamentals/episodes/12 (Video: Form Requests and Controller Validation)
https://www.youtube.com/watch?v=UzoktoyzUM0 (Video: Add Validation Request Rules)
Most applications will require some form of authentication. With Laravel, it is simple. Let's setup registration, authentication, and password resets in minutes.
https://laracasts.com/series/laravel-5-from-scratch/episodes/13 (Video: Authenticate Your Users)
https://laracasts.com/series/laravel-5-fundamentals/episodes/15 (Video: Easy Auth)
Middleware provide a convenient mechanism for filtering HTTP requests entering your application. There are many more cases where you would like to use a middleware: changing the site language based on locale, enabling site-wide maintenance, sniffing bot traffic, logging etc. There are several middleware included in the Laravel framework, including middleware for authentication and CSRF protection. All of these middleware are located in the app/Http/Middleware
directory. Additional middleware can be written.
https://laracasts.com/series/laravel-5-from-scratch/episodes/14 (Video: Understanding Middleware)
https://laracasts.com/series/laravel-5-fundamentals/episodes/16 (Video: Ogres Are Like Middleware)
https://scotch.io/tutorials/understanding-laravel-middleware
Often, you'll want to send a quick notification to the user when they perform some kind of action in your application. "Good job, your task has been created." Or: "You are now logged out." So it seems that we need a way to store things in the session for just a single request. There are some clean ways to handle this in Laravel!
https://laracasts.com/series/laravel-5-from-scratch/episodes/15 (Video: Flashing to the Session)
https://laracasts.com/series/laravel-5-fundamentals/episodes/20 (Video: Flash Messaging)
Laravel's service container (also known as the IoC container) is the heart of Laravel. It is a powerful tool for managing class dependencies and performing dependency injection.
Basically the IoC Container is just an ordinary PHP class. But we can place or “Bind” in it everything we need from interfaces implementations to directories paths and so on. Now, since we have a single Object that contains all of our various bindings, it is very easy to retrieve them back or “resolve” them at any point in our code.
https://laracasts.com/series/laravel-5-from-scratch/episodes/16 (Video: Automatic Resolution and the Service Container)
https://laracasts.com/series/laravel-5-fundamentals/episodes/26 (Video: The Service Container)
http://stackoverflow.com/questions/37038830/what-is-the-concept-of-service-container-in-laravel
Service providers are the central place of all Laravel application bootstrapping. Your own application, as well as all of Laravel's core services, are bootstrapped via service providers.
But, what do we mean by "bootstrapped"? In general, we mean registering things, including registering service container bindings, event listeners, middleware, and even routes. Service providers are the central place to configure your application. For example, when installing a package, you have to give application access to that package - one of the best solutions is through Service Providers list and a Facade.
Laravel ships with many facades which provide access to almost all of Laravel's features. In a Laravel application, a facade is a class that provides access to an object from the container.
Facades have many benefits. They provide a terse, memorable syntax that allows you to use Laravel's features without remembering long class names that must be injected or configured manually. Furthermore, because of their unique usage of PHP's dynamic methods, they are easy to test. However, some care must be taken when using facades.
https://laracasts.com/series/laravel-5-from-scratch/episodes/17 (Bootstrapping With Service Providers)
https://laracasts.com/discuss/channels/lumen/why-use-service-providers-any-examples
Videos are obviously useful without a doubt. However, many will agree that nothing compares to a working example of a functional code.
https://github.com/sroutier/laravel-5.1-enterprise-starter-kit
https://github.com/mrakodol/Laravel-5-Bootstrap-3-Starter-Site
https://scotch.io/tutorials/build-a-support-ticket-application-with-laravel-part-1
https://www.youtube.com/watch?v=_dd4-HEPejU (Laravel 5.2 PHP Build a social network - Setup & Introduction)
https://www.youtube.com/watch?v=R8B4og-BeCk&list=PLwAKR305CRO-Q90J---jXVzbOd4CDRbV (How to Build a Blog with Laravel)
Laravel Community are free discussion forums for asking and answering questions about using Laravel framework.
Taylor Otwell, Dayle Rees, Shawn McCool, Jeffrey Way, Chris Fidao, Phil Sturgeon, Jens Segers, Ben Corlett, Matt Stauffer, Graham Campbell, Belitsoft, Advanceideainfotech
Ref: Belitsoft
Your email address will not be published. Required fields are marked *