Laravel ?? ??: ?? ? ?? ??? ???? ??
Nov 23, 2023 am 10:08 AMLaravel ???? ?? ?? ? ??? ?? ??? ????, ??? ??? ?? ??? ???? ? ??? ???. ? ???? ???? Laravel? ? ? ??? ? ??? ?? ? ?? ??? ???? ??? ?????.
- ?? ??
?? ??? ?????? ??? ??? ?? ??? ???? ? ??? ??? ?? ?? ???? ?? ?????. Laravel? ??? ?? ?? ????? ?????. ?? ??? ???? ??? ???????.
1.1 ?? ??
Laravel?? ??? ??? ??? ??? ? ???? ??? ??? ?? ??? ????. ??? ? ?? ???? ?? ?????.
- HTTP ??: ??? ??? ???? ??? ??? HTTP ?? ??? ???? HTTP ??? ?????.
- ??? ?? ? ?? ??: Eloquent ??? ??? ? ?????? ?? ? ???? ???? ?? ? ??? ??? ?? ? ?? ??? ?????.
- ?? ??: ?? ??? ???? ??? ??? ?? ??? ??? ?? ??? ?????.
- ?????? ??: Laravel? ?? ?? ?? Eloquent? ???? ??????? ??? ? ??? ???? ?????? ??? ?????.
- ?? ??: ?? ?? ??? Laravel?? ??? ??, ??? ?? ?? ?? ?? ??? ??? ?? ????.
1.2 ?? ?? ????
??? ???? Laravel? ?? ??? ?? ?? ??? ?????. ???? ??? ?? ?????? ???? ?? ???? ????? ???? ?? ??? ?? JSON ??? ?????. ?? ??? ??? ?? ?????? ?? ???? ??? ????? ?? ???? ??? ?? ?? ?????. ??? ?? ??? ???? ???????.
1.2.1 ?? ??? ???
Laravel??? ??? ? ? ???? ?? ?? ???? ??? ??? ? ????. ??? ?? ?? ???? Exception ???? ???? ???. ??? ??? ?? ?? ???? ????.
namespace AppExceptions; use Exception; class CustomException extends Exception { public function __construct($message = "", $code = 0, Exception $previous = null) { parent::__construct($message, $code, $previous); } public function render($request) { return response()->view('errors.custom', [], 500); } }
? ????? CustomException??? ?? ???? ???? ??? ???? ????? ?? ??? ??? ??????.
1.2.2 ?? ??? ??
Laravel??? AppServiceProvider ?? ExceptionHandler? ?? ?? ???? ??? ? ????. ?? ???? ???? ?? ??? ??? ??? ? ????. ??? ?? ???? ???? ????.
namespace AppProviders; use IlluminateSupportServiceProvider; use IlluminateContractsDebugExceptionHandler as ExceptionHandlerContract; use AppExceptionsCustomExceptionHandler; class AppServiceProvider extends ServiceProvider { public function boot() { // } public function register() { $this->app->bind( ExceptionHandlerContract::class, CustomExceptionHandler::class ); } }
? ????? ??? ?? ?? ?? ????? ???? ?? ??? ???? ?? ExceptionHandleContract ?????? CustomExceptionHandler ???? ???????.
1.2.3 ?? ??
?? ?????? ?? ??? ?? ?? ??? ??? ? ????. ????? ?? ??? ?? ??? ???? ?? ??? ????? ???? ???. ??? ??? ???? JSON ??? ???? ????.
namespace AppExceptions; use Exception; use IlluminateHttpJsonResponse; class CustomExceptionHandler implements ExceptionHandlerContract { public function report(Exception $exception) { // 記錄異常到日志中 Log::error($exception->getMessage()); } public function render($request, Exception $exception) { // 返回JSON響應(yīng) return new JsonResponse([ 'message' => '操作失敗,請稍后再試。', 'error' => $exception->getMessage(), ], 500); } }
? ????? Report ???? ???? ??? ??? ???? render ???? ???? JSON ??? ?????.
- ??
???? ?? ?? ? ??? ?? ??? ?? ?? ??? ??? ???? ?? ????. Laravel??? ??????? ???? Log ???? ???? ?? ??? ??? ? ????. ??? ???? ??? ???????.
2.1 ?? ????
Laravel? ?? ?? ????, ?? ?? ????, syslog ????, ?????? ???? ?? ?? ??? ?? ????? ?????. config/logging.php ??? ???? ?? ????? ??? ? ????. ??? ?? ??? ????.
return [ 'default' => env('LOG_CHANNEL', 'stack'), 'channels' => [ 'stack' => [ 'driver' => 'stack', 'channels' => ['single'], ], 'single' => [ 'driver' => 'single', 'path' => storage_path('logs/laravel.log'), 'level' => 'debug', ], ], ];
? ????? ?? ?? ????? ???? ??? Storage/logs/laravel? ?????. ??? ??????.
2.2 ?? ??
Laravel? ???? ??, ??, ??, ??, ??, ??, ??, ??? ?? ?? ??? ??? ?????. config/logging.php ???? ?? ??? ??? ? ??? ???? ??? ?????. ??? ?? ??? ???? ????.
return [ 'default' => env('LOG_CHANNEL', 'stack'), 'channels' => [ 'stack' => [ 'driver' => 'stack', 'channels' => ['single'], ], 'single' => [ 'driver' => 'single', 'path' => storage_path('logs/laravel.log'), 'level' => env('APP_LOG_LEVEL', 'debug'), ], ], ];
? ????? env ??? ???? APP_LOG_LEVEL ?? ??? ?? ?? ?? ??? ??????.
2.3 Logging
Laravel??? Log ???? ???? ??? ??? ? ????. ??? ??? ????.
use IlluminateSupportFacadesLog; Log::info('This is an information log.');
? ????? info ???? ???? ?? ??? ??? ?????.
??
? ?? ??? ???? ?? ??? ??? ??? ??? ???? ?? ??? ?????? ??? ??? ????. ?? ?? ????? ???? ???? ??? ??? ??? ???? ?? ???? ??? ???? ???? ???? ???? ???.
? ??? Laravel ?? ??: ?? ? ?? ??? ???? ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

C++ Lambda ???? ?? ???? ?? ??? ??? ????? ??? ???? ????. ??? ????? Lambda ??? ?? ??? ???? ???. ? ??? ???? Lambda ???? ?? ?? ??? ??? ???? try-catch ???? ??? ??? ? ????.

C++ ?? ??? ???? ??? ????? try-catch ??? ???? ?? ?? ??? ??? ???? ??? ?? ?? ?? ??? ?? ? ????. 1. ?? ????? ??? ??? ?? ?? ???? ???? what() ???? ??????. 2. ??? ?????? throw ???? ?????. 3. ??? ???? ??? ?? ??? ?????. ??.

PHP??? ??, ??, ????? ???? ?? ?? ??? ??????. 1) ?? ??? ??? ?? ??? ??? ???? ????. 2) ?? ??? ??? ?????. 3) ????? ??? ??? ?? ????????. 4) ???? ???? ??? ???? ? ?????. ??? ????? ??? ???? ?? ??? ????? ? ??????.

C++ ??? ???? ?? ?? ? ???? ??? ?????. ?? ??: ?? ?? ? ??, ??? ?? ?? ???? ???? ?? ?? ?? ??. ?? ??: ?? ?? ???? ???? ?? ??? ???? ?? ??? ?????. ??: ?? ? ?? ??? ???? ???? ??? ??? ??????. C++ ????? ??: std::cerr ? std::clog? ??? ?? ??. ?? ?? ?????: ?? ??? ? ?? ?? ??? ?? ?? ??? ?? ?? ?????? ?????. ??? ?? ?? ???: ??? ?? ???? ???? ?? ????? ????? ??? ??? ??? ???? ?? ?? ?????? ?????.

PHP ?? ??: ?? ??? ?? ??? ?? ?? ??? PHP?? ??? ???? ? ???? ?????? ??? ?? ???? ?? ?????. ?? ??? Exception? ???? ??? ????, Throwable ???? ?? ??? ?????. throw ???? ???? ??? ????? try...catch ?? ???? ?? ???? ?????. ?? ????? ?? ??? ???? ??? ??? ? ?? ????? ????? ??? ? ??? ??() ???? ??? ? ?? DivisionByZeroError? ???? ?????.

Laravel? YII? ?? ???? ?? ??, ??? ?? ? ?? ???????. 1. Laravel? ??? ???? ???? ????? Eloquentorm ? Artisan ??? ?? ??? ??? ???? ?? ?? ? ????? ?????. 2.YII? ??? ???? ????, ? ?? ??????? ????, ???? Activerecord ? ?? ???? ????? ??? ?? ??? ????.

laravel ?? ?? ?? ? ?? ?? ?? Laravel? ?? ?? ??? ??? ? ?? ??? ?? ??? ????? : ??? : ?? ...

?? ??? ?? ??? ???? ?? ?? ? ??? ???? ? ???? C++? ?????. ?? ?? ??? ?? ??? ? ????. ?? ??: ?? ??? ?????? throw ?? ?????. ?? ??: try-catch ??? ???? ??? ???? catch ???? ???? ?? ?? ??? ?????. ?? ??: ?? ?? ?? ?? ??? ??? ?? ??? ???? ?? ?? ???? try-catch ??? ???? ??? ??? ? ????. ?? ??? ?? ?? ??, ?? ??? ??, ?? ?? ???, ?? ??? ? ?? ?? ?? ? ?? ??? ?????.
