18
Introduction to Laravel

Introduction to Laravel

Embed Size (px)

DESCRIPTION

This is a basic introduction to the Laravel PHP framework. Provided by the Tampa Bay Laravel meetup group.

Citation preview

Page 1: Introduction to Laravel

Introduction to Laravel

Page 2: Introduction to Laravel

ABOUT ME

• Started with PHP in 2000• Experience with Java, ASP, C++, etc...• Freelance web developer since 2009• Mostly CodeIgniter and Wordpress• Started the Laravel meet up to bring devs together and help

the framework gain traction in Tampa Bay

Page 3: Introduction to Laravel

WHAT IS LARAVEL“...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.”

Page 4: Introduction to Laravel

BETTER THAN THE REST?• Authentication• Routing• Sessions• Packages (Called Bundles in L3)• Command-line utility (Artisan)• Eloquent ORM• Migrations• Unit-Testing• Well tested, over 900 tests on core

Use what makes sense for your project!

Page 5: Introduction to Laravel

REQUIREMENTS• PHP >= 5.3.7• MCrypt PHP Extension• PHP 5.5 may need PHP JSON Extension• Composer to manage dependencies

Page 6: Introduction to Laravel

COMPOSERThe problem that Composer solves is this:

a) You have a project that depends on a number of libraries.b) Some of those libraries depend on other libraries.c) You declare the things you depend on.d) Composer finds out which versions of which packages need to be installed, and installs them (meaning it downloads them into your project).

https://packagist.org

Page 7: Introduction to Laravel

GETTING STARTED

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

Make app/storage writable, that’s pretty much it

Page 8: Introduction to Laravel

REQUEST LIFECYCLERequest

Route

Controller

View

Model

Start Files

Events

Filters

Page 9: Introduction to Laravel

ROUTING• GET• POST• PUT• DELETE• ANY• Filters (auth)

Page 10: Introduction to Laravel

CONTROLLERS• Better organization• All controllers extend BaseController• Shared logic goes in BaseController• Dependency injection

Page 11: Introduction to Laravel

VIEWS (BLADE)• Contain your HTML• Separate controller logic from presentation logic• Build your own or use Blade• @section and @parent• Passing variables

Page 12: Introduction to Laravel

ELOQUENT ORM

class User extends Eloquent {

protected $table = 'my_users';

}

$users = User::all();$user = User::find(123);

Page 13: Introduction to Laravel

INSERT, UPDATE, DELETE$user = new User;$user->name = 'John';$user->save();

$user = User::find(123);$user->email = '[email protected]';$user->save();

$user->delete();

Page 14: Introduction to Laravel

RELATIONSHIPS• One To One• One To Many• Many To Many• Polymorphic Relations

Page 15: Introduction to Laravel

OTHER COOL STUFF• Timestamps• Eager loading• Accessors & Mutators• Model Events• Converting To Arrays / JSON• and more...

Page 16: Introduction to Laravel

MIGRATIONS• Version control for you database• Paired with Schema builder• Run with Artisan

Page 17: Introduction to Laravel

UNIT TESTING• Supports PHPUnit out of the box• Easy to get started with Composer• Allows you to simulate a web browser

Page 18: Introduction to Laravel

THANK YOU!

@eliwheatonfacebook.com/eliwheaton

http://eliwheaton.com

Other Resources:codehappy.daylerees.com (L3)codebright.daylerees.com (L4)

culttt.comnet.tutsplus.com

Let’s keep the meetups going!