laravel에 대한 생소한 지식
php 매개변수의 기본값
<code><span><span><?php</span><span><span>function</span><span>makecoffee</span><span>(<span>$type</span> = <span>"cappuccino"</span>)</span> {</span><span>return</span><span>"Making a cup of $type.\n"</span>; } <span>echo</span> makecoffee(); <span>echo</span> makecoffee(<span>null</span>); <span>echo</span> makecoffee(<span>"espresso"</span>); <span>?></span></span></code>
출력
<code>Making <span>a</span> cup <span>of</span> cappuccino. Making <span>a</span> cup <span>of</span> . Making <span>a</span> cup <span>of</span> espresso.</code>
모델 바인딩
RouteServiceProvider에서 부팅 메소드에 모델 바인딩을 구현합니다
<code><span>public</span> function boot(Router <span>$router</span>) { <span>parent</span><span>::boot</span>(<span>$router</span>); <span>$router</span><span>-></span>model(<span>'users'</span>, <span>'App\User'</span>); <span>$router</span><span>-></span>model(<span>'goods'</span>, <span>'App\Good'</span>); <span>$router</span><span>-></span>model(<span>'categories'</span>, <span>'App\Category'</span>); <span>$router</span><span>-></span>model(<span>'tryClothes'</span>, <span>'App\TryRecord'</span>); <span>$router</span><span>-></span>model(<span>'carts'</span>, <span>'App\Cart'</span>); <span>$router</span><span>-></span>model(<span>'orders'</span>, <span>'App\Order'</span>); <span>$router</span><span>-></span>model(<span>'orderItems'</span>, <span>'App\OrderItem'</span>); <span>//</span> }</code>
양식 요청
<code><span>php</span><span>artisan</span><span>make</span><span>:request</span><span>CreateArticleRequest</span></code>
<code><span>public</span><span><span>function</span><span>authorize</span><span>()</span> {</span><span>return</span><span>true</span>; }</code>
<code><span>public</span><span><span>function</span><span>rules</span><span>()</span> {</span><span>return</span> [ <span>'title'</span> => <span>'required|min:3'</span>, <span>'body'</span> => <span>'required'</span>, <span>'published_at'</span> => <span>'required|date'</span>, <span>// 也可以使用数组</span><span>//'published_at' => ['required', 'date'],</span> ]; }</code>
<code><span>public</span><span><span>function</span><span>store</span><span>(Request <span>$request</span>)</span>{</span><span>$this</span>->validate(<span>$request</span>, [<span>'title'</span> => <span>'required|min:3'</span>, <span>'body'</span> =><span>'required'</span>, <span>'published_at'</span> => <span>'required|date'</span>]); Article::create(<span>$request</span>->all()); <span>return</span> redirect(<span>'articles'</span>); }</code>
<code>Article<span>::create</span>(<span>$request</span><span>-></span><span>all</span>());</code>
https://gist.githubusercontent.com/barryvdh/5227822/raw/811f21a14875887635bbbb3733aef32da51fa0501e/_ide_helper.php 특정 폴더에 컨트롤러 생성
<code>php artisan <span>make</span>:controller Console/ConsoleController</code>
<code><span>[</span>ReflectionException<span>]</span> Class App<span>\Http</span><span>\Controllers</span><span>\console</span> does not exist</code>
laracast