Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Getting Started With Laravel 4
Search
Christopher Pitt
April 04, 2014
Technology
4
1.1k
Getting Started With Laravel 4
Christopher Pitt
April 04, 2014
Tweet
Share
More Decks by Christopher Pitt
See All by Christopher Pitt
Making Robots (PHP Unicorn Conf)
chrispitt
1
140
Transforming Magento (NomadMage 2017)
chrispitt
2
81
Forget What You Know
chrispitt
1
120
Monads In PHP → php[tek]
chrispitt
3
450
Breaking The Enigma → php[tek]
chrispitt
0
150
Turn on the Generator!
chrispitt
0
150
Implementing Languages (FluentConf)
chrispitt
1
300
Async PHP (Sunshine)
chrispitt
0
400
Helpful Robot
chrispitt
0
94
Other Decks in Technology
See All in Technology
B2B SaaSから見た最近のC#/.NETの進化
sansantech
PRO
0
750
Shopifyアプリ開発における Shopifyの機能活用
sonatard
4
250
Amplify Gen2 Deep Dive / バックエンドの型をいかにしてフロントエンドへ伝えるか #TSKaigi #TSKaigiKansai #AWSAmplifyJP
tacck
PRO
0
370
リンクアンドモチベーション ソフトウェアエンジニア向け紹介資料 / Introduction to Link and Motivation for Software Engineers
lmi
4
300k
マルチプロダクトな開発組織で 「開発生産性」に向き合うために試みたこと / Improving Multi-Product Dev Productivity
sugamasao
1
300
エンジニア人生の拡張性を高める 「探索型キャリア設計」の提案
tenshoku_draft
1
120
スクラム成熟度セルフチェックツールを作って得た学びとその活用法
coincheck_recruit
1
140
これまでの計測・開発・デプロイ方法全部見せます! / Findy ISUCON 2024-11-14
tohutohu
3
370
OCI Network Firewall 概要
oracle4engineer
PRO
0
4.1k
隣接領域をBeyondするFinatextのエンジニア組織設計 / beyond-engineering-areas
stajima
1
270
[CV勉強会@関東 ECCV2024 読み会] オンラインマッピング x トラッキング MapTracker: Tracking with Strided Memory Fusion for Consistent Vector HD Mapping (Chen+, ECCV24)
abemii
0
220
dev 補講: プロダクトセキュリティ / Product security overview
wa6sn
1
2.3k
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
32
1.5k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
89
How to train your dragon (web standard)
notwaldorf
88
5.7k
Agile that works and the tools we love
rasmusluckow
327
21k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Transcript
getting started with laravel 4
about me ! ›❯ i live in cape town ›❯
i work for http://n.joepublic.co.za ›❯ i love programming ›❯ i have written a book on mvc framework development ›❯ i am finishing a book on laravel applications
the disclaimers ! ›❯ much of this is my opinion
›❯ i have a vested interest in the success of laravel
laravel ! ›❯ laravel is an mvc framework ›❯ laravel
installs with composer ›❯ laravel uses 24 community packages (11 from symfony)
artisan ! ›❯ artisan is a command-line utility ›❯ artisan
ships with laravel 4 ›❯ artisan automates complicated and laborious tasks
// terminal ! ›❯ php artisan env Current application environment:
production ! ›❯ php artisan down Application is now in maintenance mode.
// continued... ! ›❯ php artisan Laravel Framework version 4.1.24
! Usage: [options] command [arguments] ...
routes ! ›❯ routes link a url to a function
›❯ routes are specified by request method
// app/routes.php ! Route::get("products", function() { return "show the products";
}); ! Route::post("product", function() { return "save the product"; });
// terminal ! ›❯ php artisan serve Laravel development server
started on http://localhost:8000 ! ›❯ curl -X GET "http://localhost:8000/products" show the products
// app/routes.php ! Route::get("product/{id}", function($id) { return "show the product
{$id}"; }); ! Route::get("category/{id?}", function($id = 1) { return "save the category {$id}"; });
// continued... ! Route::get("user/{id}", function($id) { return "show the user
{$id}"; })->where("id", "[a-z]+");
// continued... ! Route::pattern("product_id", "[0-9]+"); ! Route::get("product/{product_id}", function($product_id) { return
"show the product {$product_id}"; }); ! Route::get("product/{product_id}/images", function($product_id) { return "show the product images for {$product_id}"; });
// terminal ! ›❯ curl -X GET "http://localhost:8000/bridge/gimly" run, fools
! ›❯ curl -X GET "http://localhost:8000/bridge/balrog" YOU SHALL NOT PASS
views ! ›❯ views are where php meets html ›❯
views can be plain php ›❯ blade is a template engine
// app/routes.php ! Route::get("/", function() { return View::make("hello"); });
// app/views/hello.php ! <!doctype html> <html lang="en"> <head> <meta charset="UTF-8">
<title>Laravel PHP Framework</title> ...
// app/routes.php ! Route::get("products", function() { return View::make("products/index"); });
// app/views/products/index.php ! <div class="products"> show the products </div>
// app/routes.php ! Route::get("products", function() { $products = [ ["the
red one", 12.99], ["the blue one", 13.99], ["the black one", 11.99] ]; ! return View::make("products/index", compact("products")); });
// app/views/products/index.php ! <div class="products"> <?php foreach ($products as $product):
?> <div class="product"> <?php echo $product[0]; ?> <span class="price"><?php echo $product[1]; ?></span> </div> <?php endforeach; ?> </div>
// app/views/products/index.blade.php ! <div class="products"> @foreach ($products as $product) <div
class="product"> {{ $product[0] }} <span class="price">{{ $product[1] }}</span> </div> @endforeach </div>
// continued... ! @extends("layout") ... ! @section("content") ... @stop
// app/views/layout.blade.php ! @yield("content", "default") ... ! @include("includes/header") ...
controllers ! ›❯ controllers connect data to views ›❯ controllers
redirect requests ›❯ controllers shouldn't be doing much more than that
// terminal ! ›❯ php artisan controller:make UsersController Controller created
successfully! ! ›❯ php artisan controller:make PostsController Controller created successfully! ! ›❯ php artisan controller:make TagsController Controller created successfully!
// app/controllers/UsersController.php ! class UsersController extends \BaseController { ... }
// app/routes.php ! Route::get("users", [ "as" => "users.index", "uses" =>
"UsersController@index" ]);
migrations ! ›❯ migrations are scripted database changes ›❯ migrations
have a special dsl ›❯ migrations need to be run
// terminal ! ›❯ php artisan migrate:make create_posts_table Created Migration:
2014_04_01_025625_create_posts_table Generating optimized class loader ! ›❯ php artisan migrate:make create_users_table Created Migration: 2014_04_01_025631_create_users_table Generating optimized class loader
// continued... ! ›❯ php artisan migrate:make create_tags_table Created Migration:
2014_04_01_025656_create_tags_table Generating optimized class loader ! ›❯ php artisan migrate:make create_posts_tags_table Created Migration: 2014_04_01_025701_create_posts_tags_table Generating optimized class loader
// app/database/migrations/[timestamp]_create_users_table.php ! use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; ! class CreatePostsTable
extends Migration { ... }
// continued... ! Schema::create("users", function(Blueprint $table) { $table->increments("id"); $table->string("username"); $table->string("password");
$table->string("email"); $table->timestamps(); });
// terminal ! ›❯ php artisan migrate Migration table created
successfully. Migrated: 2014_04_01_025625_create_posts_table Migrated: 2014_04_01_025631_create_users_table Migrated: 2014_04_01_025656_create_tags_table Migrated: 2014_04_01_025701_create_users_tags_table
seeders ! ›❯ seeders are scripted database populators ›❯ seeders
can insert as much or as little data as required ›❯ seeders need to be run
// app/database/seeds/DatabaseSeeder.php ! class DatabaseSeeder extends Seeder { ... }
// continued... ! public function run() { $this->call("UsersTableSeeder"); }
// app/database/seeds/UsersTableSeeder.php ! DB::table("users")->insert([ [ "username" => "chrispitt", "password" =>
Hash::make("password"), "email" => "
[email protected]
", "created_at" => time(), "updated_at" => time() ] ]);
// terminal ! ›❯ php artisan db:seed Seeded: UsersTableSeeder
query builder ! ›❯ query builder builds sql queries ›❯
query builder has its own dsl
eloquent ! ›❯ eloquent is a programmatic wrapper for database
tables ›❯ eloquent is best for single instances
authentication ! ›❯ authentication is about blocking the wrong users
and allowing the right ones ›❯ authentication needs a special eloquent model ›❯ alternatives exist
thanks ! ›❯ follow http://twitter.com/followchrisp ›❯ learn http://tutorials.io ______ <
moo! > ------ \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || ||