Laravel Basics Errors & Logging - fantasy0107/notes GitHub Wiki
η’η exception
php artisan make:exception CardCreatedException
θη exception
//controller
use App\Exceptions\CardCreateException;
try {
//...create card sql
} catch(\Exception $exception) {
throw new CardCreatedException('ζ°ε’ε‘ηε€±ζ');
}
// handler
use App\Exceptions\CardCreateException;
use Illuminate\Validation\ValidationException;
use Illuminate\Database\Eloquent\ModelNotFoundException;
public function report(Exception $exception)
{
if ($exception instanceof CardCreateException) {
// log
} elseif ($exception instanceof ValidationException) {
// log validation ηΈι
} elseif ($exception instanceof ModelNotFoundException) {
// log validation ηΈι
}
parent::report($exception);
}