Thursday, March 24, 2016

LARAVEL : Introduction

Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling. Laravel attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as authentication, routing, sessions, and caching.



Laravel aims to make the development process a pleasing one for the developer without sacrificing application functionality. Happy developers make the best code. To this end, we've attempted to combine the very best of what we have seen in other web frameworks, including frameworks implemented in other languages, such as Ruby on Rails, ASP.NET MVC, and Sinatra.

Laravel is accessible, yet powerful, providing powerful tools needed for large, robust applications. A superb inversion of control container, expressive migration system, and tightly integrated unit testing support give you the tools you need to build any application with which you are tasked.

How many PHP frameworks are you trying? Have you ever tried wearing laravel framework? Or do not understand what PHP framework? Ok I'll explain in advance what PHP framework. Framework is a tool that will enable us to create the program. Suppose you want to make clothes, you have to buy yarn, turning it into the fabric, make a pattern, cut the fabric and then sew it. With the framework you do not need to do it all because it has provided the fabric and pattern of her dress so that you only need to sew. Likewise with PHP, within a framework already provided various functions frequently used such as Form, Validation, Request / Response, Localization, etc.

Laravel itself is a PHP MVC framework developed by Taylor Otwell in 2011 and has now reached version 4.2. There are so many features that greatly assist us in this laravel framework. And what's interesting is the slogan of laravel "PHP THAT DOES NOT HURT. CODE HAPPY & ENJOY THE FRESH AIR. "Laravel makers believe that the process of program development should be fun, so we can imagine what it's like to program with this laravel.

Why should we try laravel? We'll see of its features which I will explain one by one

1. RESTful Routing

RESTful is a new way of managing the request, for more details, I suggest you watch the video of this one Teach A Dog To Rest essence we are talking to the website with those methods REST standards such as GET, POST, PUT, PATCH, DELETE, STORE, etc.

Laravel itself is a framework that is quite unique, if usually we only need to make controller and contain certain methods eg "UserController with showUser method" then we can access www.situskita.com/user, in laravel we have to do something different to be able to access the url it is adding

Route::get('/user', array('uses' => 'showUser@UserController'));

Reviewed routes.php file. That is the request by method "GET" and the user will be redirected to the url UserController showUser method. What are the benefits? of course with the file routes.php we know what the url and features available in our website and where his run (controller) memudahakan certainly we in the process of development and improvement of error.

2. Composer Powered

As a PHP programmer especially our many "reinvent the wheel" does not mean repeating work that we need to do more, we create a real-world examples Library to validate the data, but we have to download and use. Degan their composer, greatly facilitated our work.

Composer itself is depedency Management PHP that helps us find a library that we want to use and install, all hosted in the library of the composer's own laravel packagist.org and we also installed via Composer.

Cases that we usually encounter is
a. Find a library that we like, but in other frameworks
b. Finding the correct library tp bothered to install any new project start

With composer we just need to create a file called composer.json containing the library of what we need for example, we need the Carbon library for the manipulation of dates, we only need to type

{
"require": {
"brinanesbit/carbon": "~1.6"
}
}

After that

curl -s http://getcomposer.org/installer | php
php composer.phar install

and lastly include vendor / autoload at the beginning of your index.php file

require 'vendor/autoload.php';

and the library can be your own carbon use

Oh yes, to know more please visit the website composer composer on how to install on your computer and complete documentation composer, and wait for my next discussion about the composer

3. Command Line Tools (Artisan)

What operating system do you use? Linux? If so you may already be familiar with the command line, for those not familiar do not be discouraged because it controls the command line is not as difficult as we think, we can even do the job faster. This tutorial.

Laravel itself has been equipped with command line tools called "Artisan" anything that can be done by artisan?
1. Database Migration
2. Serve application (without the need to put in htdocs, cool is not it?)
3. Changing the status of an application be down and up
4. Seeding Database (Entering initial data into the database)
5. Tail (View the log server in realtime)
6. And many more


4. Test Driven Development Ready

Test driven development is a new way to develop software, we write test code first before we write the actual code. Laravel myself use as a test PHPUnit procurement framework, for more details you can learn here

5. Beautiful Templating Engine
Templating engine, is a program that parses the syntax in the HTML template engine. Laravel itself has a powerful templating engine called blade, in fact in making programs in laravel, we can choose to use a pure PHP or templating engines just with the file naming. To use the file naming blade viewnya be namafile.blade.php

As to whether delish blade

Di PHP Biasa
Nama anda <?php echo $nama; ?>

Di Blade
Nama anda {{ $nama }}

Di PHP Biasa
if (isset($nama)) {
Nama anda <?php echo $nama; ?>
}

Di Blade
@if (isset($nama)) 
Nama anda {{ $nama }}
@endif

Di PHP Biasa
foreach ($dataKaryawan as $karyawan){
echo $karyawan->nik;
echo $karyawan->nama;
}

Di Blade
@foreach ($dataKaryawan as $karyawan)
{{ $karyawan->nik }}
{{ $karyawan->nama }}
@endforeach

and in this blade we can create a layout, usually when we create a website that changes the contents only tp header, menu and footer is not, how full is in Blade Template Engine

6. Elegant Code

Laravel constructed facade design pattern, meaning we do not need to deal with the API of libraries that complicated, we just need to access it in a way very easily without having to load the class and the class menginstansiasi. Example:

Session::set('nama', 'David');
Route::get('/user', 'uses' => 'index@UserController');
Form::text('nama');

quick and easy is not it? we do not need menginstansiasi class and mengincludenya as below

$sess = new Session();
dll

7. Eloquent ORM

ORM (Object Relational Model) laravel named Eloquent has several advantages from other ORM, I'll show you how good use of this Eloquent ORM

Menentukan Table
nama table bersifat plural dan model singular. Contoh:
nama Model:User
nama Tabel:users

atau jika nama table berbeda
protected $table = 'karyawan';

Menentukan Primary Key
protected $primaryKey = 'nik';

Select Semua User
User::all();

Insert Data 
User::create('nik' => 1234, 'nama' => 'David');

Delete Data
$user = User::find(1234);
$user->destroy();

Kriteria Select
User::where('nama', '=', $nama)->get();

Relationship
public function post()
    {
        return $this->belongsTo('Post');
    }

8. Features WOW

1. Queue
2. SSH
3. Authentication
4. Pagination
5. Session
6. Redis Support
7. Schema Builder
8. Mail
9. Validator
10. Session

Are you interested in trying laravel? Wait for the next tutorial about how to install laravel and how to create a website with a very fast and easy to use laravel.

Artikel Terkait

LARAVEL : Introduction
4/ 5
Oleh