Upgrade to Pro — share decks privately, control downloads, hide ads and more …

給你一個使用 Laravel 的理由

給你一個使用 Laravel 的理由

於 2014-07-03 受邀於 PHP 也有 Day #4 分享 Laravel Framework,主題為:給你一個使用Laravel的理由

簡報相關素材下載:
當日錄影:http://youtu.be/nMDNWXZ65aQ
投影片:http://bit.ly/VJJzdB
示範影片:http://bit.ly/1mqcEpg
示範原始碼:http://bit.ly/1vE8ji2

更多訊息請見:http://www.laravel-dojo.com/post/90735874491/laravel

Shengyou Fan

July 03, 2014
Tweet

More Decks by Shengyou Fan

Other Decks in Programming

Transcript

  1. ຊ೔ओ୊ • PHP ۙظݱگɺߋ৽ਐల • PHP ᐽՍ૰᧸ٴᐽՍબᎩܾࡦ • બᎩ Laravel

    తݪҼ • 10 ݸ㑊ᱜ؆հ Laravel ։ᚙྲྀఔ • Laravel ላशɺ։ᚙࢿݯ • Q&A ަྲྀ
  2. • PHP 5.3 • Namespaces • Closures • PHP 5.4

    • Square bracket array syntax • Built-in web server • Traits • PHP 5.5 • Generators • PHP 5.6 • PHPNG ৽‧PHP
  3. Laravel Framework • ༝ Taylor Otwell ओಋ։ᚙɼ໨લ 4.2 ൛ɿ -

    ჩߟ Ruby on RialsɺASP.NET MVC ٴ Sinatra తޠ๏࿨Սߏɼ׌େྔ࢖༻ Symfony ݩ݅ • ֩৺ཧ೦ɿ - ؆ᄸ༏ඒతޠ๏ɼᩋ։ᚙऀ༇շత PHP ᐽՍʂ
  4. ։ᚙ؀ڥधٻ • PHP (PHP 5.4 ᢛ mcrypt extension) • Composer

    • ໢ท࢕෰ث • ࢿྉݿ (ᢛ Client App) • ฤाث / IDE (ᢛ൛ຊ߇੍ Client App) • ᖣ᧸ث ˒ ჩߟɿhttp://laravel.com/docs/installation#server-requirements
  5. 1. Installation • ࡾछํࣜɿ - laravel-installer - composer - manual

    install ˒ ჩߟɿhttp://laravel.com/docs/installation
  6. 2. Artisan • $ php artisan {command} • Laravel ሢሱతࢦྩྻ޻۩ɼڠॿզ၇׬੒

    ೔ৗൟᘭ޻࡞ࣄ຿ɼ೗ɿ - 㗞ੜ auto-loadɺਗ਼շऔɺ࠷ՂԽ - 㗞ੜ migrationɺ߇੍ queue - ҡޢ໛ࣜ ˒ ჩߟɿhttp://laravel.com/docs/artisan
  7. 3. Configuration • app/config/{config}.php - app.php (debug mode, service provider...)

    - database.php (mysql...) - mail.php (gmail, mailgun...) - queue.php (beanstalkd...) • ࢕෰ث root ࢦ޲ public ˒ ჩߟɿhttp://laravel.com/docs/configuration
  8. ։ᚙྲྀఔ • ෆಉ֊ஈత։ᚙྲྀఔ [development] ։ᚙ༻ɺଌࢼ༻ [local] ຊػ୺։ᚙ [staging] ֊ஈੑᚙ䆋 [production]

    ਖ਼্ࣜઢ 㑌ݸ։ᚙᆿ൐ຊػ୺ ᘐཱ։ᚙɼ։ᚙ׬੒ ޙૹճ൛ຊ߇੍ܥ౷ [version control] ݪ࢝ᛰ؅ཧ ఆظኺ൛ຊ߇੍ܥ౷ औग़ޙɼਐߦ੔߹ɺ ᄸݩ౳ଌࢼ ሢҊ֊ஈ׬੒ޙɼਐ ߦ֊ஈੑᚙ䆋ɼڅ٬ 㖽ଌࢼɺ֬ೝ ॴ༗֊ஈ׬੒ޙ䆋ॺ ࢸਖ਼ࣜओػɼሣ֎ެ ։࢖༻
  9. ࡌೖ؀ڥઃఆ • app/config/{environment}/*.php - Laravel ။ࣗಈࠜᎦ໨લత؀ڥɼࡌೖሣ ጯతઃఆ䈕ɼ෴ሜ༬ઃઃఆ • .env.{environment}.php -

    Laravel 4.1੔߹ phpenv ౟݅ɼ௚઀ሡ؀ ڥᏓᏐࡌೖޙɼ෴ሜ༬ઃઃఆ ˒ ჩߟɿhttp://laravel.com/docs/configuration#protecting-sensitive-configuration
  10. 4. Migration • ଟਓ։ᚙ࣌ࠔ৙ - 㑌ਓత։ᚙ֊ஈෆಉɺ DB 㐫ଶ໵ෆ ಉɼ੔߹࣌ແ๏஌ಓࠩҟ -

    ए௚઀मվ DB ᔒ༗ل㑚໵ᔒ㭎๏ճ෮ • ղܾํҊɿಋೖ Migration
  11. ԿҦ Migrationʁ • app/database/migrations/{migration}.php - ॴ༗ሣ DB ૢ࡞తಈ࡞ɼ౎Ḥሜሣጯత ఔࣜᛰိ׬੒ (Laravel

    Schema builder) - ෼੒ up/down (લਐ/ޙୀ) - 㑌ݸਓ፤౸ߋ৽൛ຊޙɼಁաࣥߦ migrate बՄҎ༗૬ಉత DB ݁ߏɼए༗ ໰୊໵ՄҎ rollback ճ೭લత㐫ଶ ˒ ჩߟɿhttp://laravel.com/docs/migrations
  12. 5. Model • app/models/{model}.php - Laravel ཫૢ࡞ DB త ORM

    ੋ Eloquent - Ұݸ resource ሣጯ౸ DB ཫతҰݸ table - Ұݸ model ሣጯ౸ table ཫతҰݸ row - model ੋᄸᏐɺtable ੋෳᏐ - ኺ Eloquent औग़ိత౦੢ੋ Collection
  13. 6. Seeding • app/database/seeds/{seeder}.php - ࡏ։ᚙ࣌ɼԟԟ။धཁࢿྉိ၏ᰖࣔɺ ႟আိଌࢼఔࣜɼୠࢿྉత㚎༰ෆඞੋ ਅతɼୠࣗݾݐଠྦྷྃ… - ಁա

    Laravel త table seederɼՄҎշ଎ తሡ၊ࢿྉ౗ਐࢿྉݿɼํศ։ᚙ CRUD ṜछҎࢿྉૢ࡞ҝओతޭೳ ˒ ჩߟɿhttp://laravel.com/docs/migrations#database-seeding
  14. 7. Route • app/routes.php - Route बੋ App ҰᑍҰᑍత໳ېنଇɼ نଇ㚎ࢦఆ㑌Ұݸ࿏༝ՄҎ઀डతಈ࡞

    (GETɺPOST) ٴधཁၚೖతჩᏐ - ኺ্ࣕԼஞҰൺሣɻූ߹ब။ࣥߦɺए ፙෆ౸ब။ճၚ 404 (Not Found) - Մ౥഑ groupɺprefixɺnamespaceɺsub- domain ၏ኧੑઃܭ ˒ ჩߟɿhttp://laravel.com/docs/routing
  15. 8. View • app/views/{view}.blade.php - جԙ Response ෺݅ɼճၚ HTML ท໘

    㚎༰ɼฒ݁߹ሢሱతᒬ൘Ҿ№ Bladeɼํ ศಈଶత㗞ੜ㚎༰ - Blade Մಁա៺ঝओ൘ɺ෴ሜეմɺᎷॆ ݩ݅၏ኧੑ૊߹ ˒ ჩߟɿhttp://laravel.com/docs/responses
  16. 9. Controller • app/controllers/{controller}.php - ሡෳᯑతఔࣜૢ࡞ᬓाɼኺ Route ൖ౸ Controller Ҏ

    Class తํࣜਐߦ෼ྨҎར ҡޢ - Controller ຊ਎ଈ IoC ContainerɼՄࣗ ಈ dependency injection ˒ ჩߟɿhttp://laravel.com/docs/controllers
  17. 10. Package • Package ؆ᄸိ㘸बੋ Laravel తᎷॆఔ ࣜɼಁա҆᧋ Package बՄҎ௚઀࢖༻ผ

    ਓሜ޷తޭೳɼՃշ։ᚙ଎౓ • ࡏ 3.0 ࣌ڣ Bundleɼ4.0 Ҏޙվ᜝ Package • ֓೦ಉ Symfony త BundleʀRails త Gems
  18. Կ႔ਘፙ packagesʁ • ፺ਘҾ№ɿ - Laravel Packages Registry - Packalyst

    • ᡒ େਆ/ಉࣄ/๎༑ తਪન • ؃ผਓత Open Source ཫ༻䬟ࠣʁ ߋଟਗ਼ᄸՄჩߟɿhttp://www.laravel-dojo.com/recommend-packages
  19. ೗ԿબᎩ packageʁ • ჩߟ Package ፺ਘҾ№্త Downloadsɺ TrustɺPopularity ౳Ꮠ值၏ჩߟࢦඪ •

    ؃ Package త࡞ऀੋ୭ʁ • ᡒผਓతਪનɺ෦མ֨తհ঺ • ଟࢼزݸಉྨܕత Packageɼፙग़࠷ॱࣗ ݾखతိ༻
  20. ೗Կ҆᧋/࢖༻ʁ • ࢔ࡉ㕕ᩇ README (֬ೝ൛ຊɺن֨) • ௐ੔ composer.json / composer

    update • ઃఆ ServiceProviderɺAlias (ࢹधٻ) • Publish ઃఆ (ࢹधٻ) • Migrate DB (ࢹधٻ) Ҏ Sentry 2 ҝྫɿhttps://cartalyst.com/manual/sentry#installation
  21. Laravel ׭ํจ݅ • http://laravel.com/docs - ༝׭ํਪग़తจ݅ɼڞ෼ Guide ٴ API ၷछܕࣜɼґधٻ࢖༻

    - ਪન࢖༻ Dash ҃ devdocs.io ၏཭ઢ查ਘ ༻޻۩ɼํศ։ᚙ࢖༻
  22. Laravel ჩߟॻ੶ • Laravel: Code Bright - ༝ࣾ܈஌໊࡞ऀ Dayle Rees

    ॴḤሜత Laravel ڭላॻɼਪનೖ໳࢖༻ • Laravel: From Apprentice To Artisan - ༝ᐽՍ࡞ऀ Taylor ਌ࣗૢ౛ɼ㘸໌ Laravel ֩৺ݪཧٴᎷॆٕ޼ɼֱద߹ਐ ֊త։ᚙऀ㕕ᩇ ߋଟਗ਼ᄸՄჩߟɿhttp://www.laravel-dojo.com/books
  23. Laravel ి୆ • Podcast (http://www.buzzsprout.com/11908) - ༝ࣾ܈ॴ੒ཱత Laravel Podcastɼෆఆ ظᚙߦɼ໨લڞ༗

    15 ू - 㑌Ұूᬐ੥ࣾ܈㚎େਆڃਓ෺ઢ্ᡅ৽ ฉɺ։ᚙ৺ಘҎٴ…֤ࣜീ܋ɼᓣܴగ 㕕࿅ᡒྗʂ ߋଟਗ਼ᄸՄჩߟɿhttp://www.laravel-dojo.com/worth-to-subscribe
  24. Laravel Өยڭላ • laracasts.com - ༝ Jeffrey Way ॴ૑ཱత Laravel

    ઢ্ڭላ ඼ṛɼ࠾గ㕕ࣜ෇අ෰຿ • tutsplus.com - ஌໊ઢ্ڭላ໢᜾ɼ෦㟨㚎༰໔අʀ෦ 㟨ਐ֊㚎༰࠾ᄸങ҃గ㕕ࣜ෇අ ߋଟਗ਼ᄸՄჩߟɿhttp://www.laravel-dojo.com/screencast
  25. Laravel ୆ᖯ • தจԽ׭໢ (http://bit.ly/twlaravel) - ໨લఏڙ׭ํจ݅຋ᩄ - ᓣܴ༗ࢤ೭࢜ fork

    ճڈڠॿ຋ᩄ޻࡞ʂ • FB ࣾᅶ (http://bit.ly/laraveltwfb) - ෆఆظ෼ڗ Laravel ৽ฉɺڭላɺ౼࿦ - ᓣܴՃೖࣾᅶ౼࿦ʂ
  26. Laravel Dojo (ಓ৔) • @LaravelDojo (http://bit.ly/laravel-dojo) - ఏڙ Laravel ላशࢿݯҝओ୊తڭላ໢

    ᜾ɼෆఆظߋ৽ Laravel ૬᮫㚎༰ - ະိ༬ఆ݁߹ᩇॻ။׆ಈɼޑჄࣾ܈㚎 ੒һ൴ࠑަྲྀɺ੾᛭መፌٕज़ - ᓣܴՃ౸ఆظ௥᪦ਗ਼ᄸʂ
  27. ؐੋ㘸෰ෆྃ㟬… • ߟྀଖଞత framework 䆩ʁṜཫؐ༗ɿ - Symfony (@Ricky Su) -

    yii (@KeaNy) - Phalcon (@Rack Lin) - ࣗݐ framework (@c9s) • ᓣܴଟ౸ PHP ୆ᖯɺPHP ໵༗ Day ౼࿦