ΨΠυΛಡΉɿଓɾ ʰRequest Lifecycleʱ from ʮArchitecture Conceptsʯ ΨΠυ͔ΒಘΒΕΔͷ The goal of this document is to give you a good, high-level overview of how the Laravel framework works. Ͳ͏ Function ͢Δ͔ɺશମΛ௫Ήʂ ʢݡ͘ɺϋΠϨϕϧʹ ཧղ͕ਐΊͲ͏ͳΔ͔ By getting to know the overall framework better, everything feels less magical and you will be more confident building your applications. ΑΓ ࣗ৴Λ࣋ͬͨ ΞϓϦ ։ൃ ͕ՄೳͱͳΔʢϚδͰ ࡔຊ߶ @sakamoto03 (Sodick Co., Ltd.) Laravel ૬ஊձ PHP ΧϯϑΝϨϯεԬ 32 / 54
Laravel Validation @ https ://laravel.com/docs/5.6/validation /∗∗ ∗ Store a new blog post . ∗ ∗ @param Request $request ∗ @return Response ∗/ public function store ( Request $request ) { $validateData = $request −>va l i d a t e ( [ ’ t i t l e ’ => ’ required | unique : posts |max:255 ’ , ’ body ’ => ’ required ’ , ] ) ; / / The blog post i s valid , store in datebase } ࡔຊ߶ @sakamoto03 (Sodick Co., Ltd.) Laravel ૬ஊձ PHP ΧϯϑΝϨϯεԬ 41 / 54
Laravel Validation @ https ://laravel.com/docs/5.6/validation # Introduction ΑΓ Now we are ready to fill in our store method with the logic to validate the new blog post. To do this, we will use the validate method provided by the Illuminate\Http\Request object. If the validation rules pass, your code will keep executing normally; however, if validation fails, an exception will be thrown and the proper error response will automatically be sent back to the user. public function store ( Request $request ) { $request −>v a l i d a t e ( $request , [ ’ t i t l e ’ => ’ required | unique : posts |max:255 ’ , ’ body ’ => ’ required ’ , ] ) ; / / The blog post i s valid , store in database } ࡔຊ߶ @sakamoto03 (Sodick Co., Ltd.) Laravel ૬ஊձ PHP ΧϯϑΝϨϯεԬ 42 / 54
Service Providers @ https ://laravel.com/docs/5.6/providers # Introduction ΑΓ Service providers are the central place of all Laravel application bootstrapping. Your own application, as well as all of Laravel’s core services are bootstrapped via service providers. But, what do we mean by bootstrapped? In general, we mean registering things, including registering service container bindings, event listeners, middleware, and even routes. ʰbootstrapʱͷҙຯ ʲIT ༻ޠʳࣗಈ࣮ߦ͢Δ ΨΠυΛಡ·ͳ͍ͱɺ͔Βͳ͍ײ֮ɻΘ͟ͱʰbootstrapʱͱ͍͏ पΓ͘Ͳ͍දݱΛ͍ʰregistʱॏཁͳΩʔϫʔυͩͱΘ͢ Service Providers ͷηΫγϣϯʹʰregistʱͱ͍͏ݴ༿͕ߴසͰ ΘΕ͍ͯΔ ࡔຊ߶ @sakamoto03 (Sodick Co., Ltd.) Laravel ૬ஊձ PHP ΧϯϑΝϨϯεԬ 43 / 54
Service Providers @ https ://laravel.com/docs/5.6/providers # The Register Method ΑΓ As mentioned previously, within the register method, you should only bind things into the service container. You should never attempt to register any event listeners, routes, or any other piece of functionality within the register method. Otherwise, you may accidentally use a service that is provided by a service provider which has not loaded yet. class RiakServiceProvider extends ServiceProvider { public function r e g i s t e r ( ) { $this −>app−>singleton ( Connection : : class , function ( $app ) { return new Connection ( config ( ’ riak ’ ) ) ; } ) ; } } ࡔຊ߶ @sakamoto03 (Sodick Co., Ltd.) Laravel ૬ஊձ PHP ΧϯϑΝϨϯεԬ 44 / 54