Code/PHP 22

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