- 目前開發中使用到套件
- facebook/google 登入: laravel/socialite
- 驗證:機器人: buzz/laravel-google-captcha
- 購物車: gloudemans/shoppingcart
- 開發實戰
- Routing:簡化/{controller}/{action}
- 所有的view共用變數:View::share
- phpunit
目前使用到套件
- facebook/google 登入:socialite
套件名稱:laravel/socialite
安裝方式: composer
說明:https://github.com/laravel/socialite
- 驗證:我不是機器人 captcha
套件名稱: buzz/laravel-google-captcha
說明: https://github.com/thinhbuzz/laravel-google-captcha
google recaptcha 說明: https://www.google.com/recaptcha/intro/invisible.html
- 購物車:Shopping cart
套件名稱:gloudemans/shoppingcart
說明: https://github.com/Crinsane/LaravelShoppingcart
- 開發實戰
- 簡化Routing
routes\web.php
非此規則的再另外定義//通用 Route::any('/{controller?}/{action?}/{arg?}', function ($controller='Index',$action='index',$arg=null,Request $request){ return \App::Make('App\\Http\\Controllers\\'.ucfirst($controller).'Controller')->callAction($action, array($arg?:$request,$request));} );
-
所有的view共用變數
e.g 購物車
原本CartController已經寫好了count
在view中inject 注入,後即可享用<!-- Stored in resources/views/include/navbar.blade.php --> @inject('cart', 'App\Http\Controllers\CartController') <span class="badge">{{$cart->count()}}</span></a>
-
測試
-
建立測試:名稱規則XXXXTest
php artisan make:test MemberServiceTest #Nameing Rule XXXXTest
測試常用指令
$this->assertEquals(預期值,實際值);
$this->assertTrue(實際值);
$this->assertFalse(實際值);
$this->assertNull(實際值);
$this->assertInstanceOf('class of interface name', 變數);
..
參考: phpunit Assertion
-
建議別名
alias phpunit ='php56 vendor/bin/phpunit' # avoid err=PDO driver not found -
執行測試
$phpunit -
執行結果
-
- 簡化Routing
- Fail
- Pass