NativePHP alphaãã¼ã¸ã§ã³ãwindows10ç°å¢ã§åããã¦ã¿ã
NativePHP | Baking Delicious Native Apps
ãªãã¨Laravelã§ãã¹ã¯ãããã¢ããªã®éçºãåºæ¥ãã¨ããå¤æ ã¢ããªãã§ã¦ããã®ã§ç¨¼å確èªã¾ã§ããã£ã¦ã¿ã¾ããããã¹ã¯ãããã¢ããªã¯ä½ã£ã¦ã¿ããæ°æã¡ããã£ãã®ã§ãããWebç³»ã°ããã®ç§ã«ã¯ãã¼ãã«ãé«ãã¦å°»è¾¼ã¿ãã¦ã¾ããããLaravelã§ããããªãï¼ã¨æã£ã¦ã²ã¨ã¾ãããã£ã¦ã¿ã¾ããã
ç°å¢
- windows10 64bit
- PHP version 8.1.8
- composer version 2.3.9
- nodejs 18.17.1
以ä¸ã®æé ã«å¾ãã¤ã³ã¹ãã¼ã« Installation - NativePHP
ã¾ãLaravelãã¤ã³ã¹ãã¼ã«ãã
$ composer create-project laravel/laravel example-app
ä½æããLaravelã®ããã¸ã§ã¯ããã©ã«ãã«ç§»å
$ cd example-app
ãã㦠nativephpã®ããã±ã¼ã¸ãLaravelã«composerã§è¿½å ãã
$ composer require nativephp/electron
php artisanã³ãã³ããå©ã㦠native PHPé¢é£ã®ã³ãã³ãã追å ããã¦ããã°OKï¼
$ php artisan Laravel Framework 10.20.0 ...çç¥... native native:build native:install Install all of the NativePHP resources native:migrate Run the database migrations in the NativePHP development environment native:minify native:publish native:queue native:serve ...çç¥...
ãµã¼ãã¼ã®èµ·åãè¡ã
$ php artisan native:serve Starting NativePHP dev server⦠Fetching latest dependencies⦠Installing NPM dependencies (This may take a while)... Installing NPM dependencies using the npm package manager... Fetching latest dependencies⦠Starting NativePHP app Running the dev script with npm... Fetching latest dependenciesâ¦
ãããã¨ã©ã¼ã¨ãªã
[Window Title] Error [Main Instruction] A JavaScript error occurred in the main process [Content] Uncaught Exception: Error: spawn C:\Users\sakam\study\nativePHP-demo2\vendor\nativephp\electron\resources\js\resources\php\php ENOENT at ChildProcess._handle.onexit (node:internal/child_process:283:19) at onErrorNT (node:internal/child_process:476:16) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) [OK]
ï¼ã¨ãåæã«ã¢ããªã®ã¢ã¯ã»ã¹ã許å¯ããæ¨ã®ãã¤ã¢ãã°çªãã§ãã®ã§ããã¯è¨±å¯ãã¦ããï¼
ã¨ã©ã¼ãã¤ã¢ãã°ã§æ¤ç´¢ããï¼ãã¤ã¢ãã°é¸æã§Ctrl + Cã§ã¡ãã»âã¸ãã³ãã¼ã§ããï¼ã¨ã以ä¸ã®ãã¼ã¸ãããããã©ãããã°ãããããã
[Bug]: A Javascript Error Occured In The Main Process. · Issue #105 · NativePHP/laravel · GitHub
ãããã®ã³ã¡ã³ãã«å¾ããªã³ã¯å ã®ãã¡ã¤ã«ã®å 容ãæ¸ãæããã [Bug]: A Javascript Error Occured In The Main Process. · Issue #105 · NativePHP/laravel · GitHub
To fix this visit => vendor\nativephp\electron\resources\js\electron-builder.js
https://paste.laravel.io/6c7100ed-fc2f-4d27-ad06-060d70e793fd
Replace this file
now run below command in sequence :-
=> php artisan native:install => php artisan native:build win (you will get >error a popup click ok and let complete process). => php artisan native:serve
vendorã®ä¸ã®ä»¥ä¸ã®ãã¡ã¤ã«ã
vendor\nativephp\electron\resources\js\electron-builder.js
以ä¸ã®ãªã³ã¯å ã®ã½ã¼ã¹ã«æ¸ãæãã Pastebin | Laravel.io
以ä¸ã®ã³ãã³ããå度å®è¡
php artisan native:install # ã¡ãã»ã¼ã¸ãåºã¦ãããGitbashã ã¨è¡¨ç¤ºãããªãã£ããenterãã¼ã2åç¨æ¼ãã¦å ã«é²ãã php artisan native:build win # å®äºæã«æ§æã¨ã©ã¼ã®ãã¤ã¢ãã°ãåºããã²ã¨ã¾ãç¡è¦ãã # ãµã¼ãã¼èµ·å php artisan native:serve
ããã§éçºç¨ã®ã¦ã£ã³ãã¦ãç«ã¡ä¸ãã
ã¾ã å ·ä½çããã£ã¦ã¯ãã¾ããããalphaçããªããç«ã¡ä¸ãããªããªã¼ã¨ããæ¹ã®ãåèã«ãªãã°å¹¸ãã
è¿æ³
大å¤ä¹ ãã¶ãã§ããæ´æ°ãã¾ãã
è¿æ³
ãããæ§ã§æ¥åå§è¨ã®ããã°ã©ãã¼ãç¶ãããã¦ãã¾ãã ã³ããç¦ã®ç¶æ³ã§ã¯éããã»ã¼å®å ¨ãªã¢ã¼ãã§åãäºãåºæ¥ã¾ããã
ã§ããããããã°ããã¯ä¼é¤ãã¦ãããæ°ããæè¡ãå¦ãã ããã¦ããã®ã§ããã®è¾ºã®ç¥è¦ãã»ãã®ã¡ããã£ã¨ã§ãæ´æ°ãããããªã¨æã£ã¦ä¹ ã ã«ããã°ã®ç®¡çç»é¢ãéãã次第ã§ãã
æ¥æãã復帰ãå¥ã®æã§åãäºå®ã§ãã
ãã£ã¦ãããã¨
ã¡ãã£ã¨ç¹æ®ãªSNSã®éç¨ãæ©è½è¿½å ãã³ã³ã·ã¥ã¼ãã¦ã¼ã¶ã¼ç¨ã®ãµãã¼ããµã¤ãã®è¿½å æ¹ä¿®çãè¡ã£ã¦ã¾ããã éä¸ããå¤é¨èªè¨¼å¨ãã®ä»äºã主ã«è¡ãããã«ãªããOAuth2ãã¼ã¹ã§ã®èªè¨¼å¨ãã®å®è£ çã主ã«è¡ã£ã¦ã¾ããããµã¼ãã¼å´ã«id/passwordãä¿åãã¦ãããµã¼ãã¹ãããæ°ããªã¢ã«ã¦ã³ããçºè¡ãã¦æ°ããèªè¨¼æ¹å¼ã«å¤ãã£ã¦ãããçºã®è«¸ã ããè±èªã®ãªãã¡ã¬ã³ã¹ãæ¥æ¬èªç¿»è¨³ãã¦APIã¨ãã使ã£ã¦ãã«ããã«ããããã¨ãä»æ§ãåã£ããå®è£ ãããè²ã ãã£ã¦ã¾ããã
ã¹ã¯ã©ã éçºãçµé¨ãããããªã¢ã¼ãã ãã§ããä¼è©±ãã¦ãªãã¡ã³ãã¼ã§ãçµæãå¼·ããªã£ã¦ãã¼ã ã§éçºãããã¨æ§ã ãªçµé¨ãããã¦ãããã¾ããã
éçºå¾æã§ã¯èªåã®ä½ã£ããµã¼ãã¹ãå®ã¯ãã¬ãã®CMã§ã°ãã°ãæµãã¦ãææããã£ãããã¦ãã§ãã¾ã å®è£ çµãã£ã¦ãªãæããã®ã«â¦ãã¨ãè¤éãªå¿å¢ã«ãªã£ãããã¾ããã
ãã£ãããã£ããç®ã§ããã²ã¨ã¾ããããªã¨ããã§ãã ãããããæ°ããæè¡ã身ã«ä»ãã¦ãããã°è¯ããªã¨æã£ã¦ã¾ãã
éé£çããã°ã©ãã³ã°å¦ç¿æ¹æ³10ç®æ¡
- ç¿ããã¯ããã
- éãæãããª
- æå¾ã¾ã§èªããª
- ã¡ã¢ãæ®ã
- errorã®åºåå 容ã翻訳ãã¦ç解ãããããã¦ã°ã°ã
- é§ç®ãªã次ãã¡ãã£ã¢ãå¤ãã
- 俺ã®é ãæªãããããªããã¾ã 追ãä»ãã¦ãªãã ã
- éè¤é¨åãã²ã¨ã¾ãç®ãéã
- ä¸æããããªãè¦å´ãå¾ããå¹ãã¦ãã
- åºæ¥ããæãããããããã¦æãããããª
å®ã¯7æããã¾ã¨ã¾ã£ãæéãåºæ¥ã¦ããã®1é±éç¨ãæ°ããªæè¡ã®åå¼·ãå§ãã¦ãä»ãã£ã¨æåã®ç®æ¨ã®ç°å¢æ§ç¯ãã§ããæ§ã«ãªãã¾ãããï¼docker-compose㧠nginx, MySQL,Laravelã®éçºç°å¢ãä½ãã¾ããï¼ ãã®éãç解ããã¾ã§ããªãç´ä½æ²æããã£ã¦ãããããããªãæ°ããæè¡ã®åå¼·ã®ä»æ¹ã¿ãããªãã®ã«æ°ä»ããã®ã§ãã¾ã¨ãã¦ããã¾ãã
Dockerã§ã®ç°å¢æ§ç¯æ¹æ³ã£ã¦ããã°ã©ãã³ã°ã¨ããããã¤ã³ãã©ã§ãããã¾ããå¦ã³æ¹ã¯åãã ã¨æãã®ã§ãå¤ãã«è¦ã¦ãã ããã
ç¿ããã¯ããã
æ°ããäºãè¦ãããã¨æã£ãããä¸çªã«è¨ãããã®ã¯ãã¨ã«ããä¸çªç°¡åã§å 容ã®èãã¡ãã£ã¢ããå§ããã®ããããããã¾ãã ä»åç§ã失æããã®ã¯ãã¡ãã£ã¨ä¸ç´è åãã®æ¬ãè²·ã£ã¦å¦ç¿ãåãã¦ãã¾ã£ãäºã§ããããããã¡ãã£ã¢ã¯ãå¤ãã®æé»ã®ç¥èãåæã«ç©äºãæ¸ãã¦ããã®ã§ãå¾ã ã«çç¥ãããäºæãæ ¡æ£ãã¹çã§ããã®éãã«ãã£ã¦ãä¸æãè¡ããªãäºãå¤ã ããã¾ãããããããã®ã«ä¸åº¦ãããã¨ãªã«ããªã¼ãã¨ã¦ãé£ãããªãã¾ãã解決ã§ããªãã§ä¸æéãæ©ãã¨ç²¾ç¥çã«ãåã£ã¦ãã¦ããæ°ãç¡ããå¯è½æ§ãããã®ã§ããªãã¹ãæåä¸å¯§ã§ãå¤ãããããã®ããå§ããã®ãè¯ãã§ãããã
éãæãããª
ãããã«ã¯ç¡æã®ã³ã³ãã³ããå±±ã®æ§ã«ããã¾ããã¨ã¦ãåèã«ãªããã®ãããã¾ãããæ¬å½ã®åå¿è åãã³ã³ãã³ãã¨ããã®ã¯ãå®ã¯ã¨ã¦ãæéæããããã³ã¹ãããããã®ã§ãã ããã¯ãã¾ã£ããã®ãã½ã³ã³åå¿è ã«ãè¬å¸«ã¨ãã¦Excel,html,cssçãæãã¦ããçµé¨ä¸ã確信ãæã£ã¦è¨ãã¾ãã æè¿ããã°ã©ãã³ã°ã¹ã¯ã¼ã«ã§ã®å¦ç¿ããªã«ãã¨è©±é¡ã«ãªãã¾ãããææ¥æããããªãã«ãããã®ã¯ãææã®ä½æããç´æ¥æããã³ã¹ãã馬鹿ã«ãªããªããããã¨ããé¢ãå¤åã«ããã¨æãã¾ãã
èªåèªèº«ã®åã§èª¿ã¹ã¦å¦ã¶ã¹ãã«ã«èªèº«ããªãã®ã§ããã°ãéãæãã¾ããã¹ã¯ã¼ã«ãªããé«ä¾¡ãªæ¬ãªããææã³ã³ãã³ãçã§å¦ã¶ã¹ãã§ããããããã¦ãç¥èã ãã§ã¯ãªãããå¦ã³æ¹ããå¦ã¶äºãæèããã¨ããã§ããã ã¯ããå çä»å¤§äºãªãã¨ãè¨ãã¾ãããã¼ã
æå¾ã¾ã§èªããª
æ¬ãåç»ã®è©±ã§ãããããåºæ¬çãªäºæ以å¤ã¯ãç¡çã«å ¨é¨ãèªãã ãè¦ããããå¿ è¦ã¯ç¡ãã¨èãã¦ãã¾ããç¹ã«ãèªåãç®çæèãæã£ã¦å¦ç¿ãã¦ããæã¯ãªãããã§ãã ä»ã®ç®æ¨ã¨ç°ãªãå 容ã§ããã°ãè¦åºãã«ç®ãéãã¦è¨æ¶ã«ã¨ã©ãã¦ããã ãã§å¤§ä¸å¤«ã ã¨æãã¾ããããããåºæ¬çãªäºæã°ããã®ãã®ã§ããã°ãç解ã¯åºæ¥ãªãã£ãã¨ãã¦ãã軽ã¼ãç®ãéãä½ã¯ãã¦ãããæ¹ãè¯ãã§ãããããããªãã®ããããã ãã¨ããæ å ±ã®è¦åºããä¿æãã¦ãããã¨ãå¾ã å½¹ã«ç«ã¤ãã¨ãããã§ãããã
ã¡ã¢ãæ®ã
ããã°ã©ãã³ã°ãè¦ããã®ã§ããã°ãã¡ã¢ã¯çµ¶å¯¾å¿ è¦ã§ããã¨ãããããã®èªåã ãã®èç©ãèªåèªèº«ã®éè¦ãªè²¡ç£ã«ãªãçã§ãã ç§ã¯ Evernoteã Boostnoteã使ã£ã¦ãæ°ããç¥èã«é¢ãã¦ã¯ãã¨ã«ããããã¹ããã¼ã¹ã¡ã¢ãæ®ãæ§ã«ãã¦ã¾ãã
ããã¦ãã°ã°ã£ã¦ã¿ãã®ã¨ä¸¦è¡ãã¦ããã®ã¡ã¢ã§ãæ¤ç´¢ããã¾ãããã使ãã³ãã³ãã¨ããåºåãããã¨ã©ã¼ã¨ãurlã®ã¯ãªããã¨ããQiitaè¨äºã®ã³ãã¼ã¨ããã¨ã«ããèç©ããã¦ããã¾ãããã¼ã«ã«ãã£ã¦ã¯ã«ãã´ãªã¼ãã¿ã°ãä»ããããã®ã§ãç§ã¯çµæ§ä¸å¯§ã«åé¡ããã¦ãã¾ãã ç¹ã«ãµã¼ãã¼ã®ç°å¢æ§ç¯ã«é¢ãã¦ã¯ãQiitaã®è¨äºããã¼ã¹ã«ãèªåã®ã¡ã¢ã追å ãã¦ããã®ã¡ã¢ãè¦ãã°å ¨é¨åãã«ä½ãããã£ã¦ä½ä¸å¯§ã«ã³ãã³ããã注æç¹ãæ¸ãã¦ãç¬èªã®ãã¼ãã«ãã¦ã¾ãï¼ãªã®ã§å ¬éã¯åºæ¥ãªãï¼
errorã®åºåå 容ã翻訳ãã¦ç解ãããããã¦ã°ã°ã
ããã¯ãã®ã¾ã¾ã§ããã¨ã©ã¼ã¡ãã»ã¼ã¸ã®è±èªãããããªãå ´åã¯Google翻訳ã«ããã¦ä½ã¦æããã¦ãã®ãç解ãã¾ããããããã«ãã®è±èªæããã®ã¾ã¾æ¤ç´¢ãã¦ãæµ·å¤ã®stackoverflowã®è¨äºãããããããªãã¦ããã¡ããã¨è¦ã«è¡ãã¾ããããè±èªã®ãµã¤ãã§ããã©ã¦ã¶ã®ç¿»è¨³æ©è½ã§æ¥æ¬èªåãã¦èªãã°ãçµæ§ç解ã§ããã解決ã§ãããããã«ãã®ã¨ã©ã¼è§£æ±ºæ¹æ³ããæ¥æ¬èªè¨äºã«ãªã£ã¦ãªããã°ãèªåãè¨äºãæ¸ãã¦Webã«æ®ãã¦ããã°å¾ã«æ¥ã人ãå©ããäºã«ãªãã
é§ç®ãªã次ãã¡ãã£ã¢ãå¤ãã
ããã§ããªãã ãè¦ããããªãããã³ã¨ããªããããæ°ãåºãªããææãåºãªããã¨ãã£ãäºã§ããã°ãããã§ä¸æãã¦æ¬¡ã«è¡ãã¾ããããä»ã®èªåã«åã£ãç¥èã¨æ å ±ã絶対ã©ããã«ããçã§ãç§ã¯ãã®ä¸é±éã§ã300ãã¼ã¸è¶ãã®æ¸ç±ã2åè²·ã£ã¦å®è·µãã¦ã¾ããããå®éã«èªãã§å®è·µãããã¼ã¸ã¯100ãã¼ã¸ç¨ã§ããã ã§ãããããé§ç®ã ã¨æã£ã¦ã次ã«åç»ãæ¢ãã¦2æéã»ã©ã®å®è·µåç»ãè¦ãªããå®è·µãã¦ã¿ã¾ããããããããããæå¾ã¾ã§ã¯å®èµ°ã§ãããä»åº¦ã¯å¥ã®åºç¤çãªèª¬æããã¦ãããã¦ã§ããµã¤ããããã¤ãèªã¿ãå®è·µãã¦ããã£ã¨èªåã®ç®æ¨ã ã£ããã®ãæ§ç¯ã§ããããã«ãªãã¾ããã
ããããããã§è¦ã¦æ¥ãæ¬ããµã¤ããåç»ã§ã®ç¥èã¯ãã¡ã¢ãæ®ãã¦ããã®ã§ãæéãçµéãã¦æè¡çè³å³æéãåããªãéãããã¤ã§ã調ã¹ãããæ å ±ã®è¦åºãã«ãªã£ã¦ãã¾ãã
俺ã®é ãæªãããããªããã¾ã 追ãä»ãã¦ãªãã ã
ä»åè³¼å ¥ãã2åã®æ¬ã¯ãä»ã®èªåã«ã¯ãã¼ãã«ãé«ãã£ãã§ããç¹ã«ãè¨å®ãä¸æããããæ£ã è©°ã¾ã£ã¦ãåé¡ã解æ¶ãããã«ããå¦ã³ããDockerã¨ã¯ç°ãªãé¨åã§ã®ãã©ãã«ã ã£ãã®ã§ãã¾ã£ããã¢ããã¼ã·ã§ã³ããããã¾ããã§ãããï¼jenkinsã®ã¹ã¬ã¤ãã®sshæ¥ç¶ã®è¨å®ãä¸æããããªãã¨ããä»ã®èªåã«ã¯ãã¾ãå¿ è¦ã®ãªãäºæã§æ©ãã§è«¦ããï¼ ã¾ããèªåã®ç®æãæ¹æ³ã¨ã¯ç°ãªãæ¹æ³è«ã§è¨è¿°ãããæ¬ã®è¨å®æ¹æ³ãèªåã«åããããããä¸æããããªãã£ãã®ã§ããããæ©ã ã«è«¦ãã¾ãããã©ã¡ããä»ã®èªåã®ã¬ãã«ã§ã¯ç解ã追ãä»ããªããéè¦ãªäºæã ã£ãã®ããããã¾ãããããããåºæ¥ãªããç解ã§ããªãäºã§æ°ã«ç ãäºã¯ãªãã¨æã£ã¦ã¾ãã
éè¤é¨åãã²ã¨ã¾ãç®ãéã
è¤æ°ã®ã¡ãã£ã¢ã§ã¤ã¾ã¿é£ãå¦ç¿ããã¦ããã¨ãæåã®æ¹ã¯ãã©ããåããã¨è¨ã£ã¦ããªã¼ãã¨æã£ã¦ãã±ãã±ãã¨é£ã°ãã¦ãã¾ã£ãããã¾ãããå®ã¯ããæããäºã£ã¦ãããäºã§ããã ã£ã¦ããã¾ã§ç解ãé²ãã§ã説æãã¦ããããªãã§ããããæ§ã«ãªã£ã¦ãã訳ã§ããããããããã®éè¤é¨åãæµãç¨åº¦ã§è¯ãã®ã§ãã²ã¨ã¾ãç®ãéããã¨ããããããã¾ããèªåã®ç解ãããã¾ãã ã£ãäºæãåºæ¬æ¦å¿µããéã人ã®è¨èã§ç¶´ããã¦ããã®ãè¦ãäºã§ãããç©äºã®ç解ãé²ãã¨æãã¾ãã
ä¸æããããªãè¦å´ãå¾ããå¹ãã¦ãã
ã§ããã®è¾ºã¾ã§æ¥ã¦è²ã ã¤ã¾ã¿é£ããã¦ããä»ã®èªåã«ä¸åº¦è¯ãææã«åºä¼ããã¨ã以åä¸æãè¡ããªãã£ãéã«ãè¦å´ãã¦èª¿ã¹ãäºã¨ãã試ãã¦ãããã¨ããå¹ãã¦ããæãæ¥ã¾ãï¼æè¨ï¼å¦ç¿æ²ç·ãä¸æ°ã«ä¸æ¹åã«ä¼¸ã³ãç¬éã¨ã§ãè¨ãã¾ãããããããããã®ã¨ã©ã¼ã¯åã«ããã£ãããããã¦ããªãããã ãªãã¨ãããããã®ç¶æ ãªãã次ã«â¡â¡ãããã¦ããã®ã³ãã³ãã¯åã«ã¡ã¢ãããããã«â¦ãã¿ããã«ãªã£ã¦æ¥ãç¬éãæ¥ãããã£ã¡ã®ãã®ã§ãã
åºæ¥ããæãããããããã¦æãããããª
ããã¦åºæ¥ããæãã£ããåã³ã¾ããããé¨å±ã§è¸ã£ããã人ã«èªæ ¢ãã¦ãè¯ãã¨æãã¾ãã
docker-compose 㧠nginx,mysql,volumes ã®çµã¿åããã§ãã¹ãos å´ã§laravelã¢ããªã®ã³ã¼ããå ±æããã¦ããç°å¢ãæ§ç¯ãããã¨ãåºæ¥ãï¼è²ã è¿·ã£ãåãerrorãåºã¦ãæä½éãªãã¨ãã§ããæ§ã«ãªã£ãï¼
— sakamata (@sakamata) 2020å¹´7æ8æ¥
èªåèªèº«ã®å¦ç¿åã®ææã¨ãå¤ãã®å 人ãæ®ããã¡ãã£ã¢ã®åãåãã¦åºæ¥ãææã§ãã人ç®ãæããæãã£ããåãã§ãã ãããããã¦ã俺ã£ã¦ãããï¼ã¨èªåãè¤ãã¦ãã£ã¦ãã ããã
ããã¦å¦ç¿ã®çºã«ã¡ãã£ã¢ã¨ãã¦æ®ãã¦ãããå 人ã«æ大éã®æè¬ããã¾ããããããªãããããç解ã§ããã®ã¯ãå 人ãã¡ãã£ã¢ãéãã¦ãããªãã«ãããæãã¦ãããããã§ããæãããã£ãå¾ã¯ãè¬èã«ãªã£ã¦ããã¤ããã®ãã¦ãã¦ã次ã«æ¥ã誰ãã«ãä¼ãã¦ãããããããã«ãªãã¨è¯ãã¨æãã¾ãã
ä»åã®å¦ç¿ã§ãä¸è©±ã«ãªã£ãæ¸ç±ããµã¤ããåç»ç
Docker/Kubernetes å®è·µã³ã³ããéçºå ¥é
- ä½è :å±±ç° ææ²
- çºå£²æ¥: 2018/08/25
- ã¡ãã£ã¢: åè¡æ¬ï¼ã½ããã«ãã¼ï¼
試ãã¦å¦ã¶ Dockerã³ã³ããéçº
- ä½è :æ«»äº æ´ä¸é,æå´ å¤§è¼
- çºå£²æ¥: 2019/07/25
- ã¡ãã£ã¢: åè¡æ¬ï¼ã½ããã«ãã¼ï¼
æçµçã«ãã¡ãã®ãµã¤ãã®éãã«æ§ç¯ãããã§ããæ§ã«ãªãã¾ããã ãããã¨ããããã¾ãã
ãã¾ã
ãã¾ãã¾é ç®ã10ã«ã¾ã¨ã¾ã£ãã®ã§ãç§ã®å¤§å¥½ããªã¢ããè¨ç»ã®ãã©ã¤ããã£ã¬ã¯ã¿ã¼ã®ãã¸ã¼ã³ã¯ã©ã³ãã®10ç®æ¡ããç´¹ä»ãã¾ãã
- Be proactiveï¼ç©æ¥µçã«è¡åããï¼
- Take responsibilityï¼èªã責任ãæã¦ï¼
- Play flat-outï¼ç®æ¨ã«åãã£ã¦èç®ãæ¯ãããéããã«éè¡ããï¼
- Ask questionsï¼åãããªããã¨ã¯è³ªåããï¼
- Test and validate all assumptionï¼èãããããã¨ã¯ãã¹ã¦è©¦ãã確èªããï¼
- Write it downï¼ã¡ã¢ãã¨ãï¼
- Don't hide mistakesï¼ãã¹ãé ããªï¼
- Know your system thoroughlyï¼èªåã®ä»äºãçç¥ããï¼
- Think aheadï¼å¸¸ã«å ã®ãã¨ãèããï¼
- Respect your teammatesï¼ä»²éãå°éããä¿¡é ¼ããï¼
ããã§ã¢ãã13å·ã¯ã«ã¼ãç¡äºå¸°éãããã¨æãã¨è¸ç±ã
é¢é£è¨äºï¼ sakamata.hateblo.jp
Laravel unit test dataProvider ã§å¤æ°ãconfig 使ãå ´å
ã³ã¼ãã¨ã³ã¡ã³ãã§å ¨é¨è¡¨ãã¦ã¾ãããããªæãã
unitãã¹ãã«ããFeatureãã¹ãã«ããããã¼ã¿ãããã¤ãã使ã£ã¦ãtestç¨ã®é åãã¼ã¿ãä½ãã¨ããã®ã¯è¯ããããã¨æãã¾ããã unitãã¹ã㧠ãã¼ã¿ãããã¤ã使ãéã«ã¯ã
$this->createApplication();
ã¨ããã®ãæåã«æ¸ãã¦ãããªãã¨é§ç®ãããã§ãã(laravel6ç³»ã§ç¢ºèª)
/** * ãã¼ã¿ãããã¤ã * @return array */ public function hogeParams() { // unitTestã§ã¯ DataProviderã«ãããå¿ è¦ $this->createApplication(); // ä¸ã®ãå ¥ããªãã¨dataProviderå ã§ãããªã®ã使ããªããªã $otherId = config('const.hoge-id'); // ãã®è¾ºã«Testã§ä½¿ãé åãè¨è¿° return [ // é åå®£è¨ ]; }
$this->createApplication();
ãæ¸ããªãã¨ãããªé¢¨ã«æããã
There was 1 warning: 1) Warning The data provider specified for Tests\Feature\HogeTest::postValidateRequiredIfTest is invalid. Target class [config] does not exist. WARNINGS! Tests: 1, Assertions: 0, Warnings: 1.
追è¨ï¼
ãã¦ãã¦ã¨ãã¦ã$this->createApplication();
ã¨ã ãæ¸ãã°è¯ããã¨ããç解ã§ãããã®ã ãã©ããããå®ã¯
Laravelã®testsãã£ã¬ã¯ããªã«ãã以ä¸ã®ã¡ã½ãããå¼ãã§ããã£ã¦ãã¨ã§ããã
\tests\CreatesApplication.php
<?php namespace Tests; use Illuminate\Contracts\Console\Kernel; trait CreatesApplication { /** * Creates the application. * * @return \Illuminate\Foundation\Application */ public function createApplication() { $app = require __DIR__.'/../bootstrap/app.php'; $app->make(Kernel::class)->bootstrap(); return $app; } }
ããã確ãLaravelèªä½ãã¢ããªã±ã¼ã·ã§ã³ã¨ã¾ãåãã奴㧠index.php ã¨ããã追ããå¦çã§æ¸ãã¦ããäºã¨åºæ¬ã¯åãã§ãããã¤ã¾ã unit teståä½ã¨ãã¦å®çµãã ãã¥ã¢ãªphpunit ç°å¢ã§testãããããããªãã¦ãlaravelã¨ãã¦åããã¦åä½æ¤è¨¼ããã¨ãããããããªæãã 詳ãã追ã£ã¦ãªããã© DataProvider ã¨ããæ©è½èªä½ãLaravelåºæã®ãã®ãªã®ããªï¼ãããªæ°ãããã
10ä¸å給ä»éãç¡éã«ä½¿ãä»çµã¿
ã³ããã¦ã¤ã«ã¹ã§å¤§å¤ãªäºã«ãªã£ã¦ããå°çã®çããããã«ã¡ã¯ãç§ã大å¤ã§ãã
æ¥æ¬æ¿åºãå½æ°ä¸äººããã10ä¸åã給ä»ããã¨ããããªãã¨ãã足ããªããã°ããã¿ãããªè©±ã«ãªã£ã¦ã¾ãããããã¯ä»ãã®åé¡ã解決ããæ¹æ³ã§ã¯ãªããå ã ã®äºãèãã¦ã®ææ¡ã¨ãããå¦æ³ã§ãã
ååãã¿ã¿ãããªè©±ã§ãããå®ã¯çµæ§åããè²ã èãã¦ãããã¨ã®ä¸ã¤ã®çãã¿ãããªãã®ããããæ°ã±æã§çºé µãã¦ããã®ã§ãã¢ã¦ããããããã¦ãããã¨æãã¾ããã¾ãã³ããã¦ã¤ã«ã¹ã«ææãã¦æ»ããããå¯è½æ§ã0ãããªãã®ã§ã
ã§ã¯å ã«çµè«ã
ä½å¦ã®å½ã§ãè¯ãã§ãããã®å½ã®æ¿åºã¯å½æ°ä¸äººãããæ¥æ¬åã§ããã10ä¸åãæ°ãæé ãç¶ããäºç®ã使ã£ã¦ï¼å¾æãã§ãOKï¼ååé ãå¯è½ãªã¹ããã¢ããªã®é»åé貨ã·ã¹ãã ãçºæ³¨ãããªãä½ããªããã¦æ¬²ããã§ããããããã°çµæ§å¤ãã®äººããã³ããè±ãããã幸ãã«ãªã£ãããããããããªãããã¨ãã話ã
ã¯ï¼ãåä½è¨ã£ã¦ãã®ï¼ã¨ããããã³ããç¡è¦ãã¦è©±ãç¶ãã¾ãã
æ¿åºã確ç´ãããã¨ã¯
- ãã®ã·ã¹ãã ã®å©ç¨è ã¯ãã®å½ã®ãã®äººã§ééããªãäºã証æãã
- ãã®ã·ã¹ãã ãç¶æéå¶ããäºç®ãæ¯å¹´åºã
- ããã¯ç¢ºãã«ã¦ãã®å½ã®ãéã§ãããã¨ç¢ºç´ãããã¨
ã§ãã
誰ã ãå
ãããããéã¨ã¯ä½ãï¼ã¨ãããããã話ã10年以ä¸å»¶ã 調ã¹ããèãã¦ãæ°ããçµæ¸ã·ã¹ãã ãä½ãããã¦ããã°ã©ã è¦ãã¦ãããã¿ã¤ããä½ã£ãããã¦ç¾å¨ã¯è·æ¥ããã°ã©ãã¼ã®ãã£ããã§ãã
ã§ãã¾ãä»çµãèãã¦ãã·ã§ããã¦ãèªåã§ä½ãã¦ããçãããã«ä¾¡å¤ãæãã¦ä½¿ã£ã¦ããããªãã¨ããã¯ããéã¨ããä»çµã¿ãã«ã¯ãªããªã訳ã§ãã
ã§ããããã³ã¤ã³ã ã£ã¦æåã¯åè«ååã§ãã¶ã¨äº¤æãããã®ã«ãä»ãæ®éã«åå¼ããã¦ãã¾ãã羨ã¾ããããµãã·ãã«ã¢ãã
ãé大äºããªã®ã«ç¨¼ããªã
ãã¦ããã®ãéã§ãããæ¥æ¬ã®ãæã«ã¯æ¥æ¬éè¡å¸ãã£ã¦æ¸ãã¦ããã¾ãããæè¿æµè¡ãã®ã¹ããã®ããªãã¡ãããã¤ãã«ãããã¤ã³ãã¨ãæ¥æ¬éè¡å¸ã£ã¦åããéã§ãããï¼ã²ã¼ã ã«åºã¦æ¥ããã´ã¼ã«ãã»ã«ãã¼ããªãã¦ãããã²ã¼ã ã®ããã¼ãã¨è¦ãæã大ãã¦éãã¯ãªãã®ã«ãã¬ã¸ã¦ããã£ã¦ããã°ã¡ããã¨ä½¿ããã便å©ã ããã¦ã足ããªããªã£ãããã¯ã¬ã¸ããã«ã¼ãã¨ãéè¡ã®ãéã§ãã£ã¼ã¸ããã°ãããããã¼ä¾¿å©ã ã§ãéè¡ã«æ¯ãè¾¼ã¾ããããããã®ãéã¯ãåããªãã¨æ¯æ¸ããããã£ã¼ã¸ãã§ããªããªããä½ãè²·ããªããªããããã§ãåãã«åããªãç¶æ ããã¾ã ç¶ãããã§ããã¼ä¸å®ã
ã ããæ¿åºãå½æ°ã®çæ´»ãå®ãçºã«ãæ¯æ´éãé ãã¹ãã ã¨ããã®ã¯ãã£ã¨ãã ã¨æãã¾ãã
è¦ã¯å½æ°å ¨å¡ã®éè¡å£åº§ã«ããã£ã¦ãã£ã¼ã¸ãã¦æ¬²ããããã§ããã§ãå½é¢ã¯æ¯æ¥çããã®ã«å¿ è¦ãªé£ã¹ç©ãé»æ°ã®æ¯æããçæ´»å¿ éåãè²·ãã¦ããªãã¨ãçãã¦ãããæ§ã«ãã¦æ¬²ããã
ã§ããæ¬å½ã«å ¨å¡ãªã®ï¼ã¨ããæ©ãããããã¨ãããã£ã¨çµ¦ä»ãããªãã¨å ¨ç¶ã¤ãã¤ãã¨ãå§ã 諤ã ãã£ã¦ãããã ã«ããä»äºã¯åºæ¥ããæ®é«ã¯ã²ã£è¿«ããæ°æã¡ã«ä½è£ãç¡ããªãã
ããããã®æ¬å½ã«è¾ãã¨æãã¾ããã¾ããééãã°ç æ°ããéã§çµ¶æãã¦æ»ã¬ãããããªããªãã¦æ¬å½ã«ããã©ãã
ã§ãããããªæã«ç§å人ãã§ãããã¨ã£ã¦ä»äºä»¥å¤ã§ããã¾ããªãããªã®ã§ãã¡ãã£ã¨éç¾å®çã ãã©ãããã§ãããè¯ããªãã¿ãããªè©±ã¨ãã¦èªãã§ãã ããã
ç§ã¯ãéã®æ´å²ã«å¦ãã§ãæ°ããã¿ã¤ãã®é»åããã¼ã®ãããªãã®ãä½ããããã¨èãã¦ãã¾ãã
ã©ãããä»çµã¿ãï¼
æ¿åºä¸»å°ã®ã¹ããã¢ããª
çæ´»ã«å¿ è¦ãªæä½éã®é¡ï¼ä»¥éããã¤ã³ããã¨å¼ç§°ï¼ããæ¯æã§ããé±ã«1度ã§ããæ¯æ¥ãã§ãè¯ãã§ãããã¡ãã¨ãã£ã¼ã¸ãããæ§ã«ãªãä»çµã¿ã§ãã
ã²ã¨ã¾ããä¸æãããã§ä¸äºº10ä¸ãã¤ã³ã
ã§ããã®ã¢ããªãã¹ããå士ã§ãã¤ã³ããããåãã§ãã¾ããã¬ã¸ã®æ©æ¢°ã§ããã£ã¦ããã®ãé£ãããªããç§ã§ãä½ããQRã³ã¼ãã¨ãã§éãåãããã®ã§ãè¯ãã§ããã¤ã¾ãå人ã®ã¹ããå士ã§ãã¤ã³ããããåãã§ãããQRã³ã¼ãã ãããé ãã®äººã¨ãããåãã§ãã¾ãã
ãã¹ããæã£ã¦ãªããã¨ããããã¾ã使ããªããã£ã¦äººã¯æåã®æã«çµ¦ä»ããã10ä¸åã®æ¿ããã«ã¢ããªã®å ¥ã£ãã¹ãããé å¸ãã¦ããããªããè³¼å ¥ãããªããã¦éä¿¡ä¼ç¤¾ã¨å¥ç´ãã¦ãããã¾ãããã¸ã¿ã«ããã¤ãã®åé¡ã¯ããããããã®çµ¦ä»éã§ããç¨åº¦ãªãã¨ãã§ããã¨æã£ã¦ã¾ãã
ããã¦æ¿åºããããããéã¨ãã¦ä½¿ãã¾ããã£ã¦è¨ãã°è¯ãã ã
ãããããã®ããªãã¡ãããã¤ã§æãã¾ããã£ã¦è¨ã£ãã®ã«ããåºã¨ã売ãå´ããããããªå¤ãªããã¼ããé§ç®ã ãç¦æ²¢è«åãããï¼ãã¿ããã«åãåãæå¦ãããã¨ããããç½°éã«ããã¨ããç½°åè¨ãã¦ãè¯ãä½ã§ããã ã£ã¦ãéãªãã ããã
ã§ãããããªãã°ãç§ãã¡ã¯ããã§æ¯æã®æä½éã®çæ´»ãã¾ããªããã¨ãã§ãã訳ã§ããããã§ã¹ã¼ãã¼ãã³ã³ããã§é£æè²·ã£ã¦ãè¯ãããé»æ°ä»£ãæã£ã¦ãè¯ãã家è³ãæã£ã¦ãè¯ãããã§ããããã¦å½ç¶ããã¯å½ãããéã¨ãã¦ä½¿ãã¾ããã£ã¦è¨ã£ã¦ããã®ã§ã給æã¨ãã¦ç¤¾é·ãå¾æ¥å¡ã«é ã£ã¦ãè¯ã訳ã§ããã
ã¹ã¼ãã¼ãã³ã³ããã¯ã¬ã¸ã«èªåã®åºã®ã¹ããã®å£åº§ã®QRã³ã¼ããç´ã«å°å·ãã¦ããã°OKï¼æ³äººç«¯æ«ãã¼ï¼ã¨ãåé¡ããããªãããã®éåºé·ããå人ã®ç«¯æ«ã¨ãã§ãè¯ãã§ãï¼ä¼è¨ã®æã«ãæ示ãããéé¡ã確ãã«èªåã®ã¹ããã«æ¯ãè¾¼ã¾ããäºã ãã確èªã§ããã°è¯ãããã§ãã
é»æ°ã家è³ãåæ§ã§ããã¦ã§ããµã¤ãã«æ³äººå£åº§ã«ç¸å½ããã¹ããã®QRã³ã¼ãå¼µã£ã¦ããã°æ¯æããã§ãã訳ã§ãã
ã ããæã£ãã®ãï¼ã¹ããã¢ããªãªã管çã証æãå¯è½ã§ã
è¦ã¯éè¡ã®å£åº§ãã¢ããªã«ãªã£ã¦ããæ§ãªãã®ãªã®ã§ã誰ãããã¤ã³ããéããã¦ã誰ã«éã£ããï¼ããæåããé帳ã¨ã確å®ç³åã®æã®è³æã®æ§ã«ç®¡çåºæ¥ã¦ãããã§ãã
ã§ããã誰ã¨ããåãããããããã¨ãå«ãã¨ãããã¨ãããªæ¬ã®è³¼å ¥å±¥æ´ã¨ããã¸åå¼ãã¨ãªãã®ã§ãé»è©±çªå·ã¨ãååãããªãã¦ããããã«ç´ã¥ããæå·åãããIDã§ãããã®ã¢ããªã®å©ç¨è ã®ä¸æã®æ å ±ãå©ç¨è å ¨å¡ããäºãã«ããã£ã¦ããã°ãã¾ãåé¡ãªããã¨ã
ãããªãã¨è¨ã£ã¦æ10ä¸ã¨ã財æºã©ãããã ï¼
ã¨æãããããã¾ããã確ãã«æåã®è£½ä½è²»ã¨æã ã®ç¶æ管çè²»ã¯ãããªãã«ãããã¨æãã¾ãããããã§ããããããè¶ æåãªã¦ã§ããµã¼ãã¹ã®éå¶è²»ä½ãããã以ä¸ã§ãªãã¨ããªãã¨æãã¾ããä¸æãããã°ãéè¡ã®ATMãã¯ããã¨ããå£åº§ã·ã¹ãã éçºè²»ãç¶æè²»ãããå®ä¾¡ã«ãªãã¨è¸ãã§ã¾ããããã¦â¦
æ10ä¸ã®è²¡æºã¯ãçãããæ¯æããåããããæ10ä¸ãã¤ã³ãããå¾´åãã¾ã
ãªã«ãè¨ã£ã¦ããã®ãã¨ããã¨ããã®ã·ã¹ãã ã3ãæä½ä¸å使ããªãã§æ¾ç½®ãã¦ãããã©ããªããï¼
åè¨30ä¸ãæ¯ãè¾¼ã¾ãã¦ããã¨ãæããããªãã§ããï¼
ã¨ãããã©ã£ãããæ®é«ã¯10ä¸ã§ãã
ã¤ã¾ã使ã£ã¦ç¡ãã¨ããã®åã¯ä»ã®äººã®è²¡æºã«åããã¾ãã æ¯æ10ä¸ããã£ã¡ã使ã£ã¦æ®é«ãï¼ã«ããã°æ¬¡ã®æã¯ã¾ã10ä¸å ¥ãã¾ãã
éã«è¨ãã¨ãææ«ã«30ä¸ä½æºã¾ã£ã¦ãã¦ããæé«ã§æ®é«10ä¸ä½ã¾ã§æ¸ãããã¾ããã§ããå ¨é¨ã¯åããã¾ããããå¿ ãå ¨å¡ãä¸å®éã®ãã¤ã³ããå½ããä¿éããã訳ã§ãã
ãã®çä¸å°½ãªç¾è±¡ã«ååãä»ããã¨ããã°ãæå¾ç¨ãã¨ã§ãããã¾ãããããã§ãããã®ã·ã¹ãã ã使ã£ã¦ããã°æ¯æ10ä¸ã¯å¿ ããããããã¤ã¾ãããã¼ã·ãã¯ã¤ã³ã«ã åãååé æ©è½å å ã®é貨ã·ã¹ãã ãã¨ãã訳ã§ãã
ãã¦ãããã§ã¯æ¯æãããããå´ããã¾ãã«ãæããã¾ãããæãããªãã¿ã¤ãã®èª¬æãããåã«ãã²ã¨ã¾ãç¾ç¶ã®æ°åã®æµãã®å ¨ä½åãå ·ä½çã«èª¬æãã¾ãã
ä»®ã«ããã®ãªãã¡ãããã¤ã³ãã®åå è ã10åã ã¨ãã¾ããããæåã®æã«å ¨å¡ã«10ä¸ãã¤ã渡ããæ¿åºã®æ¯æãã¯100ä¸ã«ãªãã¾ãã
10人ã¯çæ´»ã®çºã«ãäºãã®ã¢ãããµã¼ãã¹ã¨ãã¤ã³ãã交æãã¾ããç¾å¨ä»äºãåºæ¥ãã»ã¨ãã©ãç活費ã§æ¶ãã人ã®ãã¤ã³ãæ®é«ã¯ãã»ã¼ï¼ã«è¿ããªããéã«ä»ãéããä»äºããã£ãããã¢ãããµã¼ãã¹ãå¤ãæä¾ããå´ã«ã¯ã20ä¸ã®å²ããåºãã¨ãã¾ãããã
ä»®ã«å©ç¨éå§ããä¸ãæãçµã¤é ã«ã10人ä¸3人ã30ä¸æºã¾ã£ãã¨ããã¨ã10ä¸(æåãã)+20ä¸ï¼å²ãï¼ï¼äººã®åè¨ã¯90ä¸ãããã¦æ®ã7人ã®ããããªé¡ãåè¨ãããã¨ã¡ããã©10ä¸ã¨ãªãã¾ããããã¦å ¨ä½ã§è¦ãã¨ã90ä¸ + 10ä¸ ã§åè¨100ä¸ãåè¨é¡ã¯å½ç¶å¤ããã¾ããã
ããã¦ææ«ã«ãªãã¨ã30ä¸ã®å£åº§ã®äººã¯20ä¸ãå¼ãããæ®é«10ä¸ã 3Ã20=60ä¸ãæ®ãã®7人ã«åãã¦å ¨å¡ã10ä¸ã«æ»ããã¨ãã訳ã§ãã
ãã£ã¨ããããã¯ããã¶ã極端ãªä¾ã§ããé å¼µã£ã¦åããã®ã«20ä¸ãåããããªãã¦ãµããã¦ãï¼ãã¨æã£ãããããã¾ããããå½ç¶ã§ãããªã®ã§ã«ã¼ã«ãå°ãå¤ãã¾ã¾ãããã
30ä¸ãã©ããããã¹ã¿ã¼ãããã¨ãã£ã¨å¬ãã
ä»åº¦ã¯3ãæç®ã¾ã§ã¯ãæ°è¦ã§10ä¸ãã¤ãå¿ ãæ¯ãè¾¼ã¾ããã¨ãããã©ãã§ãããï¼ã¤ã¾ã3ãææ¾ç½®ããã¨30ä¸è¿ãã¡ãã¨æºã¾ãã¾ãããã®æç¹ã§ã®10äººå ¨å¡ã§ã®åè¨ã¯300ä¸ã§ãããã¼ã¹ã©ã¤ã³ããããä¸ã§ãæ¯æ10ä¸ãå¿ ãå ¨å¡ã«é ãåã ããå ¨ä½ã®ä½å°ããéãã¾ãã
ä»åº¦ããã£ãã¨åæ§ã«3人ã®ä¸æã®å²ãã+20ä¸ã ã£ãã¨ãã¾ãããã å ã å ¨å¡ã30ä¸æºã¾ã£ãæããã¹ã¿ã¼ãããã®ã§ãå²ãã3人ãæã£ã¦ããã®ã¯ 30+20= 50ä¸ã§ãããããã3人ã§åè¨150ä¸ã æ®ãã®7人ãæã£ã¦ããåè¨é¡ã¯ãå ¨ä½ã®300ä¸ãã150ä¸ãå¼ãã¦ã150ä¸ã§ããï¼ãã£ãã¯10ä¸ã ã£ãã®ã«ï¼ï¼
ãããªãæ®é«10ä¸æªæºã®äººã«è² æ ããé¡ã¯ãåãããå°ãªãã¦æ¸ãäºãããããã¨æãã¾ããéãè¯ããã°ååé ãããªãã¦æ¸ãããï¼
â¦ã¨ããã®ãå®ã¯æ¥µç«¯ãªè©±ã§ãå®ã¯ç·é¡ãå¢ããåãã¤ã³ãã¬ãèµ·ããã®ã¨ãæµåæ§ãä¸ãã£ã¦äºã ãã¨ãªãã®ã§ãå®ã¯ãããªã«ä¸æãã¯è¡ãã¾ããããå ¨ä½ã¨ãã¦ä½è£ãçã¾ããã®ã¯ããããã¨æãã¾ãã
ããã«èãã極端ã«ãã¦ã¿ã¾ãã ãã£ã¨è²¡æºãè±å¯ã«ãã¾ããããããã¦ããç¨åº¦æ®é«ãæºã¾ã£ã¦ããåãããã«ã¼ã«ããã£ã¨çããã¾ãããã100ä¸ãã1ä¸ã ãå¼ãããæ§ã«ããï¼ããã¨ã400ä¸ä½ãã50ä¸ä½ã«ããï¼1000ä¸ãªã300ä¸ä½ï¼ããæºã¾ã£ã人ããã¯ããå¤ãåã£ãæ¹ãè¯ãï¼ â¦ãªãã¨ãªãå¾æ¥ã®ãéã®ä»çµã¨ãæå¾ç¨ãã«ä¼¼ã¦ãã¾ããããã¤ã¾ãããããäºã§ãã
ãããããã®ãã©ã³ã¹ãã©ã®ã¸ãã§ä¿ã¤ã®ãï¼ã¨ããã®ã大ããªåé¡ã§ããã«ã¯ã¡ãããªãã§ããããã¶ãç¦ç¥å½å®¶ãç®æããªãããã®ã²ã¼ã ã®åå è å ¨å¡ããå¥åº·ã§æåçãªæä½é度ã®çæ´»ããåºæ¥ãä½ãæ¯æé åãããä½ãã¡ããã©è¯ãã®ã§ã¯ãªãã§ããããï¼
ããã¦ãã®ã²ã¼ã ã10人ã§ã¯ãªãä½å人ã¨ããåä½ã§ãã訳ã§ãã
ã¤ã¾ãããã®ã·ã¹ãã ã§å¾´åãããéé¡ã¯ç¢ºå®ã«ä»ã®åå è ã®çºã«ä½¿ãããæ°è¦ã®ãã¤ã³ãçºè¡ãä¸ã®ä¾ã ã¨ã3ãæç®ä»¥éã¯ãªããªããæ¯æå¿ ãå ¨å¡ã«10ä¸ä½ãæã«æ¸¡ãã¾ããããããã®åè¨ã¯å¸¸ã«ä¸å®ã§ãä¸ã§æ°åã循ç°ããã ããã¨ããä»çµã¿ã§ãã ãªã®ã§ãã¶ã£ã¡ãããã¨å½å®¶ãéå¶ããããéããç¨éãã社ä¼ç¦ç¥ãããååé ãã¨ããä»çµã¿ãããã¸ã¿ã«ããã¼ã®ä»çµã§ãã¹ã¦ãã£ã¦ãã¾ãããã¨ãããã¨ã§ããã§ããã®ç¨éã¯æ¢ã«ãã®ä»çµã¿ã®ä¸èªä½ã§åã£ã¦ååé ããã¦ããã®ã§ããã以ä¸ç¨éãåãããå¿ è¦æ§ãæå³ãç¡ã訳ã§ãã
ãªããé¨ããã¦ãæ°ãããªãã§ããªãã§ãããç§ã«è¨ãããã°ãå®ã¯å¾æ¥ã®ãéã®ä»çµèªä½ã絶å¦ã«äººã欺ããä»çµã ã¨æã£ã¦ã¾ãã
ãã¦ãã§ã¯ãã®ãªãã¡ãããã¤ã·ã¹ãã ã§ãæå¾ç¨ããã©ããªé åã«ãªã£ãã¨ãã¦ãã絶対ã«æãããªãæ¹æ³ããããããè¨ã£ã¦ããã¾ããç¾å¨ã®çµæ¸ç¶æ³ãã©ããªã«è±ããªäººãã大ãã³ãã®äººãããã®æ¦ç¥ã¯ã»ã¼ä¸ç·ã§ãã
ã次ã®ååé ã®æ¥ã¾ã§ã«æ®ã£ã¦ããã¤ã³ããå ¨é¨ä½¿ããããã¨ã
ãã£ãããã ãã§ãã
宵è¶ãã®éãæããªããã°ãèªåã®æã¡éã¯çµ¶å¯¾æ¸ããªãã®ã§ããããã«å¿ è¦æä½éã®é¡ã¯å度æ¯çµ¦ãããã®ã§ãã
ãã¼ã·ãã¯ã¤ã³ã«ã å対ã®æè¦ã§ããåºãã®ããç¨æºãã©ããããã ãã¨ããå ¨å¡ã«ãéãæ¯çµ¦ããããã誰ãåããªããªããã¨ãã話ãããã¾ããããã®ä»çµã¿ã®ä¸ã§è²¡æºã¯ãæè³ããé¡ã ããä¸ã§å¾ªç°ããã®ã¿ã§ãããååé ãããã®ã¯ãå¥åº·ã§æåçãªçæ´»ãããçºã®æä½éã®é¡ã ãã§ããããã§ã足ããªãåã¯å¾æ¥éããããç¨åº¦åããªãå¾æ¥ã®ç¤¾ä¼ç¦ç¥ãå©ç¨ãããªããå¨å²ã®äººãã¡ã¨æ¯ãåãå¿ è¦ãããã¾ãããããä»ã¯ãã³ããã¦ã¤ã«ã¹ã®çºã«åãã«åããªãç¶æ³ã®äººãæ ¼æ®µã«å¢ãã¦ãã¾ãããããªä¸ã§ãã®ãããªä»çµã¿ãããå®ç¾ã§ããã°ã誰ã«ã¨ã£ã¦ãçããã®ã«å¿ è¦ãªæä½éãã·ã³ãã«ã«ä¿éãããã¨ããç¹ã§ãããªãã®å¹æãæå¾ ã§ããã®ã§ã¯ãªãã§ããããã
ããããããä¸åº¦ã
ãã®ä»çµã¿ã§æ¿åºã確ç´ãããã¨ã¯
- ãã®ã·ã¹ãã ã®å©ç¨è ã¯ãã®å½ã®ãã®äººã§ééããªãäºã証æãã
- ãã®ã·ã¹ãã ãç¶æéå¶ããäºç®ãæ¯å¹´åºã
- ããã¯ç¢ºãã«ã¦ãã®å½ã®ãéã§ãããã¨ç¢ºç´ãããã¨
ã¨ããã®ãæ¯éãã£ã¦ãããã¨ãçµæ§ãã¾ãããã¨æããã§ãããã©ããªãã§ãããã夢ç©èªã¿ãããªãã®ã ãããªããªãé£ããããããã¾ããã 財æºã¯ä¸ã®ä¾ãªãå½æ°1人ããã30ä¸ã½ã£ããã§ããã£ããå ã¯å é¨ã®ãã¤ã³ãã循ç°ããã¾ãã®ã§ããã以ä¸ã«ãéããããå¿é ããªããç¶æè²»ã®æ¯æãããå é¨ã®ãã¤ã³ãã§ãã£ã¦ãè¯ãããããªããã£ã¦ä½ã§ãã
ãããããããªé çãæ¬æ°ã«ãã¦ãããæ¿åºãç¾ããªãå ´åã®ãã©ã³ãå½ç¶èãã¦ãã¦ãã©ã£ã¡ãã¨ããã¨ãã£ã¡ãçæ³ã§æ¬å½ã§ãã
è¦ã¯ä¸ã®ã«ã¼ã«ããããªæãã§å°ãå¤ããã°è¯ãã¨æã£ã¦ã¾ãã
- ãã®ã·ã¹ãã ã®å©ç¨è ã¯ãã®äººã§ééããªãäºãä»ã®å©ç¨è ã第ä¸è ã«è¨¼æãã¦ããã
- ãã®ã·ã¹ãã ãç¶æéå¶ããäºç®ã¯å©ç¨è åå¿ãåºã
- ãã®ã¹ããã¢ããªã®ãã¤ã³ãã¯ç¢ºãã«ãéã§ãããã¨å©ç¨è åå¿ãåæã確ç´ãã
ã§ãã
ãã®ã·ã¹ãã ã®å©ç¨è ã¯ãã®äººã§ééããªãäºãä»ã®å©ç¨è ã第ä¸è ã«è¨¼æãã¦ããã
ä¸çªç®ãå¿ è¦ãªçç±ã¯ãè¤æ°ã®ã¹ãããæã£ã¦ããã追å ã§ããã«10ä¸è²°ãããã¨ããäºéåå¾ãé¿ããããã§ããä¸äºº1ã¢ã«ã¦ã³ããåæã®ä»çµãªã®ã§ãã®è¾ºãå¿ é ã«ãªãã¾ãã
ãã®ã·ã¹ãã ãç¶æéå¶ããäºç®ã¯å©ç¨è åå¿ãåºã
äºçªç®ã¯éå¶ããæã貨幣ã¨ãã£ãã¢ãã¨ãã¦ã®ãéã§ã¯ãªãçºãäºéä¼è¨ãä¸æ£çã®æªããè¨ç®ãããããã¨ãªããå¥å ¨ãªéå¶ç¶æãç¶ããã¨ãä¿¡é ¼ã®æ ¹æ ã«ãªãã¾ããããã¦èª°ããããä¿è¨¼ãç¶ããã®ãï¼ãåé¡ã«ãªãã¾ãããããã³ã¤ã³ãªã©ã¯ç¬ç«ããã¢ããªã±ã¼ã·ã§ã³ã¨ããããã¯ãã§ã¼ã³ã¨ãããåã ã®ç«¯æ«ã«å ±éã®æå·åãããå ¨å¡ã®é帳ãæã¤çãªäººã®ä»å¨ããªãä»çµèªä½ãããããç¶æãã¦ã¾ãã
ãã®ã¹ããã¢ããªã®ãã¤ã³ãã¯ç¢ºãã«ãéã§ãããã¨å©ç¨è åå¿ãåæã確ç´ãã
ä¸çªç®ãç¹ã«é£ããæ°ããã¾ããããã®ä»çµã¿ãã¨ã¦ãå®å¿ãã¦ä¿¡é ¼ã§ããããã«ãªãããäºãããã®ä»çµã¿ã«é¨ããã¦ãè¯ããã¨èãã人ãå¢ããã°ä¸æãããã¯ãã§ãããã§ã«ãããã³ã¤ã³ãããæå³ã§ãããªã£ã¦ãã¾ãããæ¢åã®ããéãã¨ããä»çµãã®ãã®ãæ¢ã«ãããªã£ã¦ã¾ãã®ã§ã
ã¨ãããã¨ã§ããã®ã·ã¹ãã ãä½ã£ã¦ãããã§ãã¶ã売ã£ããè²·ã£ãããã¦ããã人ãåããããã¨ããã®ãç§ã®å½é¢ã®ç®çã§ãã誰ãããã£ããä¸ç·ã«ããã¾ãããã
ã¡ãªã¿ã«ããã®ä»çµã¿ã®å ãã¿ãç¥ããã人ã¯ãã²ã¼ã«ãã¨ããèªç±è²¨å¹£ãã¨ãã¨ãã§ã°ã°ã£ã¦ã¿ã¦ãã ããã
ä¸è¨ã®èª¬æã¯ç°¡ç¥åãããã®ã§ãå®ã¯èããªãããããªãã«ã¼ã«ãä»çµãèµ·ããããåé¡ç¹ã¯å¤ã ããã¾ããä¾ãã°ååé ã®æéã決ã¾ã£ã¦ããå ´åãå¿ ãæããã人ãåºã¦æ¥ãåé¡ããæ¢åã®é貨ã¨ã®ä¸¡æ¿ã交æããã®ä»çµã¿ã使ã£ã¦ã®æè³ãåéã¯ã©ããªãã®ï¼ã¨ãã£ãåé¡ãããã¾ãããããã¯ããããã®æ©ä¼ã«èª¬æãããã¨æã£ã¦ã¾ãã
ã¾ãéå»ã«ç§ãä½ã£ããããã¿ã¤ãã¨ãï¼ä»ã¡ããã¨åãã¾ããï¼ãã¾ã¾ã§èããäºã®è»è·¡ã¯ããã«ããã®ã§ãèå³ãããã°è¦ã¦ãã£ã¦ãã ããã
Happy Project æ°ããé貨æ¦å¿µããã¶ã¤ã³ããã
ãããã«ããã°ã©ãã¼æ¥çãæ¯æ°ãæªããªã£ã¦ããã®ã§ãç§ãæãã§ãã¦ãã¾ãããããã¾ããããªã®ã§æéãä½ã£ããæ°ããæè¡ãå¦ã³ãªãããã·ã§ããã¦è¯ãã®ã§ãã¾ãã¯ãããä½ãã¾ããã¾ããç¾ç¶ã§ã®å©ç¨ãã¦ããããä¿¡é ¼åº¦ã¯ï¼ã§ããã課é¡ãå±±ç©ã¿ã§ããããã¤ã0ãã大ãããããã¨æã£ã¦ã¾ãã
Laravelæ¬çªç°å¢ã local è¨å®ã§åãã¦ãã¦ç¦ã£ã話
æ¬çªç°å¢ã§ã® composer ã³ãã³ãã«æ³¨æ
10åç¨æ¬çªç°å¢ãæ¢ãã¦ãã¾ã£ããã¨ã¯ããæ®æ®µã¯Slackã®éç¥ã°ããã§ãµã¤ãæ¬ä½ã¯äººãã»ã¨ãã©è¦ã¦ãªãã®ã§ãã¶ãã»ã¼ãã ãï¼æ¬å½ãï¼ï¼
ã¾ãçµè«
æ¬çªç°å¢ã® composer install ã§ã¯ 以ä¸ã®ãªãã·ã§ã³ãä»ããªãã¨ã devç°å¢ã® dusk çãæ¬çªã«ã¤ã³ã¹ãã¼ã«ããã¦ãã¾ãã±ã¼ã¹ããããããããªããææªåä½ããªããªãã®ã§æ³¨æãï¼envã®è¨å®ã«ãã£ã¦ã¯ä¸è¦ãããããªããæªæ¤è¨¼ï¼
Exception: It is unsafe to run Dusk in production. · Issue #289 · laravel/dusk · GitHub
composer install --no-dev
ããããè«
ããã¾ã§æ¬çªç°å¢ã® .env
ã® APP_ENV ã®è¨å®å¤ã local
ã®ã¾ã¾ã ã£ããããã®ãã㧠composer install
ã§localç°å¢ã§ã® phpunitã諸ã
ãæ¬çªç°å¢ã«ãå
¥ã£ã¦ãã¾ã£ã¦ããããã ã
å¾ã£ã¦ã¾ã .env
ã® å¤ã以ä¸ã®æ§ã«æ¸ãæãã
æ¬çªbefore
APP_ENV=local
æ¬çªafter
APP_ENV=production
ãããæåãã production
ã«è¨å®ãã¦ããã°ãããããä»åã®åé¡ã¯èµ·ãã£ã¦ããªããããããªãã
.env
ãæ¸ãæããå¾ã«config:clear
ã®éã«åºãerror
$ php artisan config:clear In DuskServiceProvider.php line 43: It is unsafe to run Dusk in production.
ãããããããã¼ã«ã«ç°å¢ã§ãæ£ã æ©ãã DuskãLaravel5.6 ã§ã¯ã«ã£ã¡ããã£ã¡ãè¡ããªããªã£ãéã®errorã§ãvendor ã® duskå ã®ã¡ã½ããã§è¿ãå¤ã®å宣è¨ããªãã¨errorã«ãªãé¢ä¿ã®å¥´ã ã£ãã¨æãã
ã§ããã®å¾composer update
ããã£ãã以ä¸ã®æ§ãª error ãåºã
#è²ã ãã£ã¦æå¾ã®æ¹ - Installing composer/semver (1.5.1): Downloading (100%) - Installing composer/ca-bundle (1.2.6): Downloading (100%) - Installing composer/composer (1.10.1): Downloading (100%) - Installing barryvdh/reflection-docblock (v2.0.6): Downloading (100%) - Installing barryvdh/laravel-ide-helper (v2.6.7): Downloading (100%) symfony/event-dispatcher-contracts suggests installing psr/event-dispatcher symfony/service-contracts suggests installing symfony/service-implementation barryvdh/reflection-docblock suggests installing dflydev/markdown (~1.0) Package facebook/webdriver is abandoned, you should avoid using it. Use php-webdriver/webdriver instead. Writing lock file Generating optimized autoload files Carbon 1 is deprecated, see how to migrate to Carbon 2. https://carbon.nesbot.com/docs/#api-carbon-2 You can run './vendor/bin/upgrade-carbon' to get help in updating carbon and other frameworks and libraries that depend on it. > Illuminate\Foundation\ComposerScripts::postAutoloadDump > @php artisan package:discover In DuskServiceProvider.php line 43: It is unsafe to run Dusk in production. Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1
dump-autoload ã§ãåããã¨è¨ããããããã§ãæ¬çªã¯åããªãï¼5åä½çµã£ã¦ç¦ã£ã¦ããï¼
$ composer dump-autoload Generating optimized autoload files Carbon 1 is deprecated, see how to migrate to Carbon 2. https://carbon.nesbot.com/docs/#api-carbon-2 You can run './vendor/bin/upgrade-carbon' to get help in updating carbon and other frameworks and libraries that depend on it. > Illuminate\Foundation\ComposerScripts::postAutoloadDump > @php artisan package:discover In DuskServiceProvider.php line 43: It is unsafe to run Dusk in production. Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1
ããã§erroræè¨ã§ã°ã°ãåé ã«ãå¼µã£ã以ä¸ã®ãã¼ã¸ã«è¾¿ãçã
Exception: It is unsafe to run Dusk in production. · Issue #289 · laravel/dusk · GitHub
è¨è¼ãããã³ãã³ãæã£ã¦æ¬çªç°å¢ã«ä¸è¦ãª Duskå«ãä½è¨ãªãã®ãã¢ã³ã¤ã³ã¹ãã¼ã«ã§ããã
$ composer install --no-dev Loading composer repositories with package information Installing dependencies from lock file Package operations: 0 installs, 0 updates, 34 removals # è²ã åé¤ãããï¼å²æï¼ - Removing webmozart/assert (1.7.0) - Removing phpunit/phpunit (7.5.20) - Removing laravel/dusk (v4.0.5) Generating optimized autoload files Carbon 1 is deprecated, see how to migrate to Carbon 2. https://carbon.nesbot.com/docs/#api-carbon-2 You can run './vendor/bin/upgrade-carbon' to get help in updating carbon and other frameworks and libraries that depend on it. > Illuminate\Foundation\ComposerScripts::postAutoloadDump > @php artisan package:discover Discovered Package: barryvdh/laravel-cors Discovered Package: barryvdh/laravel-debugbar Discovered Package: barryvdh/laravel-ide-helper Discovered Package: fideloper/proxy Discovered Package: laravel/tinker Package manifest generated successfully.
ãããä»ã¾ã§localç°å¢ã®è¨å®ã®ã¾ã¾ã§è¯ãåãã¦ãããªãã¨æãã ä¸ä¸ééã£ã¦testã³ãã³ãæã£ã¦ãããDBãæ»ãã§ããã ã¡ãªã¿ã«ä¸ã«åºã¦ã Carbon ã®æ°ãã奴ãã©ããããã¨ããã奴ã¯ãåã«å¤ããã¼ã¸ã§ã³ãããªãã¨é§ç®ãªä¾åããã±ã¼ã¸ããã£ãããã§ããã®ã¾ã¾ã«ãã¦ããã
â
Laravel Eloquentã§åå¾ãããã¼ã¿ã®ç¶æ ãæèãã¦ãªãã£ã件
ä»ã¾ã§DBãã¡ãµã¼ãã§ãã¼ã¿ã®åå¾ããã¦ã¾ããããæè¿ã¯ãã£ããEloquentã§ãã¼ã¿ãåã£ããå ¥ãããããããã«ãªãã¾ããããããã§ã¼ã³ã¡ã½ãããããããæ¸ãéã«ä¸æããã¼ã¿ãåããªãæããã£ã¦ããªãã§ï¼ã£ã¦ãªãäºããã°ãã°ã§ãããããã¼ã¿ã®ç¶æ ãã¡ããã¨æèããªãã§æè¦ã¨çµé¨åã¨å®è£ æã®Try&Error ã§ãªãã¨ããã¡ãã£ã¦ã¾ããã ã§ãããã®è¾ºãã¡ããã¨æèãã¹ãã ãªã¨ã
çµé¨ã®ãã人ããè¦ãã¨ãä»ããï¼ãã¿ãããªè©±ããããã¾ããããã¤ã¾ãããã§ãã
ã¾ãã馴æã¿ã®Modelããã£ãã¨ãã¾ãã
<?php namespace App; use Illuminate\Database\Eloquent\Model; class User extends Model { protected $table = 'users'; // ãªã¬ã¼ã·ã§ã³ã¨ã scope ã¨ãã®ã¡ã½ãããç¶ã }
ããã use App\User; ãã¦ä½¿ã£ã¦ä»ã®ã¯ã©ã¹å ã§ä½¿ããæ§ã«ãã訳ã§ããã ããåç´ã«ä½¿ããªãã¾ãããã§ãããã
$user = User::find(1);
DBãªããuser tableã®ä¸»ãã¼ã¨ãªã id=1 ã®ã¬ã³ã¼ã1件ãæ½åºãã¾ãã ãã¨ãããªé¢¨ã«ã使ãã¾ãã
$user = User::find(1)->get();
ã¨ã«ãã欲ãããããã§ãã¼ã¿åå¾ãã¿ãããªæã§ããã
ã¾ããã¡ãã£ã¨éã£ãæ¡ä»¶ã§å¼ã³åºãããéã¯ãããªé¢¨ã«å¼ãã ãããã¾ãã
User::where('community_id', 1);
DBã§èãã㨠users table ã®ãcommunity_id ã«ã©ã ã®å¤ã 1ã®å¥´ã ãã ã¤ã¾ãã³ãã¥ããã£ï¼ã«å±ããã¦ã¼ã¶ã¼ã ããè¤æ°ããã°åå¾ãã¿ãããªæãã§ããã
å½ç¶ããã¤ãgetãã¦ä½¿ã訳ã§ãã
User::where('community_id', 1)->get();
ã§ãå人çã«ãã使ãã®ããã®ãã¿ã¼ã³ã§ãè¤éãªé層ä¸ã®tableãªãããå¼ã¶éã¯ãå¤é¨ãã¼ããã¼ã¹ã«å¤ãå¼ã³åºãã¦ä½¿ãããªãã¦ããã®ããã訳ã§ãã
User::where('community_id', 1) ->LeftJoin('comments', 'comments.user_id', '=', 'users.id') ->where('comments.active', 1) ->get();
ãããªé¢¨ã«ã¢ã¯ãã£ããªè©²å½ã¦ã¼ã¶ã¼ã®ã³ã¡ã³ãã®ã¿ãåºããã¿ãããªãã¥ã¢ã³ã¹ã§ã¯ã¨ãªãã«ãã´ãªã´ãªæ¸ãã¦ä½¿ãæãã§ããã(ãªã¬ã¼ã·ã§ã³ã¡ã½ãã使ãã£ã¦è©±ãããã¾ãã)
ã§ããããªæãã§ããããªå½¢å¼ã§ãã¼ã¿ãåå¾ããããã§ããããªããä¸æããããªããªã¼ãã£ã¦å ´åããã£ã¦ããã®åå ããããã¾ããã
$user = User::find(1); dd(get_class($user));
ã£ã¦ã¯ã©ã¹åãåºåããããæåã«ç´¹ä»ãã奴ãããããéããã§ããã
$user = User::find(1); dd(get_class($user));
ãã㯠App\User class ã¨åºåããã¾ãã
ã¤ã¾ããããã¯ã¾ã åªã®Modelã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ã«ããã¾ããã
次ã«ãããä¸ä»¶ãã£ã¦ããäºã¯ä¸ã¨åãã§ãããã¤ã³ã¹ã¿ã³ã¹ãããã¯ã©ã¹ãç°ãªããã§ããã
$user = User::where('id', 1); dd(get_class($user));
Illuminate\Database\Eloquent\Builder classããåºåããã¾ã
dd($user)
ã£ã¦åºåããã¨éãå¤ãã¦ã¤ãã¤å¥´ã§ãã
Laravelãã£ã¦ã人ã¯çµé¨ããã¨æãã¾ããdd() ã®éãã£ãããããéã®ãªãã¸ã§ã¯ããåºåããã¦ãã·ã³ãããªã£ã¦ãªããªãç»é¢è¡¨ç¤ºãããªããã£ã¦å¥´ã§ããã
ãããããããã« ->get()
ãä»ä¸ããã¨ããã«ã¯ã©ã¹ãå¤ããã¾ãã
$usr = User::find(1)->get(); dd(get_class($user));
Illuminate\Database\Eloquent\Collection class ã¨åºå
ã¤ã¾ãã³ã¬ã¯ã·ã§ã³ã¯ã©ã¹ï¼é åã£ã½ã便å©ã«ä½¿ããã¢ã¬ï¼ã®ã¤ã³ã¹ã¿ã³ã¹ã¨ãã¦åºåããã¾ãã
$usr = User::where('id', 1)->get(); dd(get_class($user));
ãããåæ§ã Illuminate\Database\Eloquent\Collection class ã¨åºå
ã³ã¬ã¯ã·ã§ã³ã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ã¨ãã¦åºåããã¾ãã
ã¤ã¾ãã->get() ãä»ãããå®ä½åãã¦ã³ã¬ã¯ã·ã§ã³ã¨ãã¦å å·¥ãåºåã«ä¾¿å©ã«ä½¿ããç¶æ ã«å¤æããã訳ã§ããã
ã¨ããããããããã®ã¯ããã ->first()
ã§ã
ã²ã¨ã¾ããã®æ¡ä»¶ã§çµãè¾¼ãã§ãæåã®1件ã ããåå¾ããããªãã¦ããã¨ãã«ä½¿ãã¾ããç§ã¯ææ§ãªãã¼ã¿ã®åãæ¹ãããã®ãå«ã§ãã¾ã使ããªãã§ããã
$user = User::where('created_at', '>', Carbon::toDay())->first(); dd(get_class($user));
ãã App\User class ã¨åºåããã¾ãã
ã³ã¬ã¯ã·ã§ã³ã§ããªãã¾ã ãã¥ã¢ãªã¢ãã«ãªã®ããï¼ã£ã¦æãã§ãã
ã§ãããèãããã find(1)
ã¨åãæ±ãã§ããã
ã§ããããã¯ã¨ã¦ããæ··ä¹±ããã¡ã§ééããã¡ãªãã§ãããã
first() ãããããã¯ã¨ãªãã«ãæ¸ããæå¾ã«ä»ãããã¨ãè¯ãå¤ãã¦ãåãããã¼ã¿ã¨ãã¦ç¢ºå®ãããã¥ã¢ã³ã¹ãªã®ã§ã ->get()
ã¨åãèªèã§ãã¾ããããã¤ã³ã¹ã¿ã³ã¹ãç°ãªãçºãæ¬è³ªãç°ãªããã§ããã
ãªã®ã§ãä½è«ã§ãã first() ã®å¾ã«ã¯ã->get() ãä»ãããã¦ãã³ã¬ã¯ã·ã§ã³ã¤ã³ã¹ã¿ã³ã¹ã«å¤æãåºæ¥ã¾ãã使ãéãä»ä¸ã¤ãããã¾ãããã
$user = User::where('created_at', '>', Carbon::toDay())->first()->get(); dd(get_class($user));
Illuminate\Database\Eloquent\Collection ã¨åºå
ãã¨ãããå½ããåã§ããæå¾ã«ã->toArray()
ãä»ããã¨ããããå®å
¨ãªé
åã¨ãªãã¾ãã
User::find(1)->toArray(); User::find(1)->get()->toArray();
æ®éã®é åãã¼ã¿ã«ãªã
ç§ã¯ããã§å¿
è¦ãªIDã®é
åãåå¾ãã¦ãå¥ã®Modelãå¼ã¶éã®whereIn
ã®æ¡ä»¶ã«ãã¦ä½¿ããã¨ãå¤ãã§ããTOPé層ãã5é層é
ä¸(鬼ã®ãããªDBæ§é ...)ã®tableã®ãªã¬ã¼ã·ã§ã³ã§ã®å¤ãåºãå¿
è¦ããã£ãããã¦ããããªå ´åã«ä½¿ãã¾ãã
ã¾ããå®éã®ã¢ããªã±ã¼ã·ã§ã³ã§è¤éãªæ¤ç´¢æ¡ä»¶ã«å¯¾å¿ããéã®æ¹æ³ã¨ãã¦ãä¸åº¦ãåç´ãªã¯ã¨ãª find() ã where() ã§ãã¼ã¿ãå¼ã³åºãã¦ãget() ãç¹ããªãã¦$query
ã¿ãããªå¤æ°ã«å
¥ãããããããã«æ§ã
ãªå¦çãçµç±ãã¦æ¡ä»¶è¿½å ããã§ã¼ã³ã¡ã½ããã§ç¹ãã¦ãæå¾ã« ->get()
ã¿ãããªä½¿ãæ¹ããã¾ãã
以ä¸ã®ãããªæãã
// ãã使ãä¾ public function getUser(Request $request) $query = User::find($request->id); if (!is_null($request->date)) { $query->where('date', $request->date); } if (!is_null($request->name)) { $query->where('name', 'like', "%{$request->name}%"); } return $query; }
ã§ããã®é¢æ°ã®å¼ã³åºãå ã§
public function index(Request $request) // ä¸ã®é¢æ°ãå¼ã¶ $query = this->getUser($request); // ãã®è¾ºã« $query->ã使ã£ã¦ããã«è²ã å¦çãç¹ãããå å·¥ããã // ã§ãæå¾ã«ããããããããªãã£ããã㦠$user = query->get(); // åºå return view('index', [ 'user' => $user ]); }
ã¿ãããªæãã
ã§ããããã®éã«ãã®è¾ºã®ãã¼ã¿ãæã¡æ¹ã®éãããã¡ãã¨æèãã¦ãªãã¨ããªã«ããªãã ãããããªããªããã¨ããäºãããã¾ãã®ã§ãç¾å¨ã®ãã¼ã¿ã®ç¶æ ãæèãã¤ã¤ãã¯ã¨ãªãã«ããç¹ããå¿ è¦ããããªãã¨æãã次第ã
ã§ãããã®è¾ºãæå¿ã®ãªãã¡ã¬ã³ã¹ãµã¤ãEloquentï¼å©ç¨ã®éå§ 5.8 Laravelè¦ãã¨ã¡ããã¨æ¸ãã¦ãããã§ãããã
ãã¼ã¿ã®åå¾ã®æ¹æ³è«ã°ããæèãã¦ãã¦ãããã¾ã§ã¯ã©ã®ã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ã®ç¶æ ã§ãããï¼ã¨ããã®ãæèãã¦ãªãã£ããããããã°dd()ã§åºãéã«ãªããéããªâãä½ã®èªèãããã¦ãªãã¨ããâ¦ã
ä½è«ã§ãããããã«æèãåãã£ããã£ããã§ãããæè¿ãã¼ã ã§å®è£ ãããããã«ãªããå¾ããç§ã®ã³ã¼ããèªã人ã®çºã«ãããããããã³ã¼ããæèããããã«ãªããã¡ã½ããã«ãã¡ãã¨ã¢ããã¼ã·ã§ã³ãæ¸ããã¨ãå§ãã¾ãããï¼æè¿ããï¼ï¼
ã¨ã¯ããããã£ãã俺æµã§æ¸ãã¦ãã¾ã£ã¦ããã®ã§ããããããæ¸ããã¨ã§èµ·ãã£ãè¯ãå¤åã¨ãã¦ãå¼æ°ã«ã¯ã©ããªåã®ãã¼ã¿ãå¿ è¦ã§ãè¿ãå¤ã®ãã¼ã¿ã®åã¯ä½ãªã®ãï¼ã¨ããã®ãæèçã«çµ±ä¸ãã¦æ¸ãããã«ãªãã¾ããã
ãã®éã®è¿ãå¤ã«ããããã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ã¨ãã¦ã¯ä½ãæ¸ãã¹ããªã®ï¼ã£ã¦æã«ãããï¼ã£ã¦ãªã£ã¦ãã®è¨äºã«è³ãã¾ãã
ããããè¿ãå¤ã«ã¤ãã¦ã¯ãããã¾ã§ã¯åç´ãªé åãæ°å¤çããã¨ãModelã§æ¸ããããå ¨é¨å 容åãã§ãããä½ã«ããèªèãã¦ãªãã£ãã®ã§ãä»å¾ã¯è¿ãå¤ãä½ã®Classã®ã¤ã³ã¹ã¿ã³ã¹ãªã®ãããã¡ãã¨æèãã¦å®è£ ã§ããããã«ãã¾ãã