분류 전체보기 62

XorY methods

엘로퀀트는 2가지 기능응 합친 메소드가 있따. 이런 메서드는 X하고 안되면 Y해라. Example 1 – findOrFail(): Instead of: $user = User::find($id); if (!$user) { abort (404); } Do this: $user = User::findOrFail($id); eloquent has quite a few functions that combine two methods, like “please do X, otherwise do Y”. Example 2 – firstOrCreate(): Instead of: $user = User::where('email', $email)->first(); if (!$user) { User::create([ 'emai..

Code/PHP 2021.03.04

phpstorm의 Laravel모델에서도 인텔리전스를 하고 싶을 때.

Laravel모델에서 자동입력을 할려고 하면 잘 안된다. query()->를 붙이고 하면 되긴 된다. 그러나, 다른 유튜브를 보면 되는 것이다. 그래서 찾아봤다. github.com/barryvdh/laravel-ide-helper barryvdh/laravel-ide-helper Laravel IDE Helper. Contribute to barryvdh/laravel-ide-helper development by creating an account on GitHub. github.com 위쪽 깃에 들어가서 설치하면 된다. 해당 프로젝트디렉토리에서 터미널을 열고 composer require --dev barryvdh/laravel-ide-helper 치면 설치한 뒤 php artisan ide-hel..

Code/PHP 2021.02.26

Laravel Tips ) 레코드 존재 확인 용으로 find함수와 if함수의 조합 비추천

Laravel Daily Tips, tutorials, and demo-projects based on Laravel framework and technology around it. Host: Povilas Korop www.youtube.com 레코드 존재를 확인하기 위한 용도로 if문과 find함수의 조합를 쓰지 말라.findOrFail() 혹은 optional을 쓰자. yt3.ggpht.com/d7WPOrvEaFbXc2Y06b1y3RZhfEPOtnLfsTQkqttAY8YpPlr0ebVbF_I_P19B-c46xtFAu4pkL-YZ3g=s640-c-fcrop64=1,00200000ffdfffff-nd

Code/PHP 2021.02.23