Laravel?? ??? ?? ????? ???? ??
??:
Laravel? ??? ??? ??? ???? ???? ??? ? ??????? ??? ??? ? ??? ????. ?? ??? ?? ? ??? ???????. ????? ??? ??? ???? ? ??? ? ??? ?????? ??? ?? ?? ??? ?? ??? ??? ? ????. ?? ???? Laravel?? ??? ?? ????? ???? ??? ???? ???? ?? ??? ???????.
1??: ???? ??? ??
?? ??? ??? ???? ???? ???? ???. Laravel??? php artisan make:middleware CacheMiddleware
??? ?? ??? ???? ???? ??? ? ????. ?? ?? CacheMiddleware
??? ??? ?? handle
???? ?? ??? ??? ? ????. php artisan make:middleware CacheMiddleware
來創(chuàng)建一個新的中間件類。然后,我們可以打開CacheMiddleware
類文件,將以下代碼添加到handle
方法中:
public function handle($request, Closure $next) { $key = 'cache_' . md5($request->fullUrl()); if(Cache::has($key)) { return response(Cache::get($key)); } $response = $next($request); Cache::put($key, $response->getContent(), 60); return $response; }
上述代碼邏輯很簡單,首先我們生成了一個緩存的鍵值,這里使用了請求的完整URL作為鍵名。然后我們判斷緩存中是否存在該鍵值,如果存在則直接返回緩存內(nèi)容,否則繼續(xù)執(zhí)行后續(xù)邏輯。在執(zhí)行完后續(xù)邏輯之后,我們將請求的響應內(nèi)容存入緩存中,并設(shè)置了有效期為60秒。
步驟2:注冊中間件
接下來,我們需要將上述創(chuàng)建的中間件類注冊到應用程序中。在Laravel中,可以通過編輯app/Http/Kernel.php
文件來完成中間件的注冊。在$routeMiddleware
數(shù)組中,添加以下代碼:
'cache' => AppHttpMiddlewareCacheMiddleware::class,
此處使用了cache
作為中間件的名稱,你可以根據(jù)自己的需求進行修改。
步驟3:使用中間件
現(xiàn)在我們已經(jīng)創(chuàng)建了中間件并將其注冊到應用程序中,接下來就是如何使用中間件了。在Laravel中,可以通過路由或者控制器中間件來使用中間件。這里我們以路由中間件為例進行說明。
先在routes/web.php
文件中添加一個路由示例:
Route::get('/example', function () { return 'This is an example.'; })->middleware('cache');
在上述代碼中,我們通過middleware
方法指定了使用cache
中間件。這樣當訪問/example
rrreee
2??: ???? ??
app/Http/Kernel.php
??? ???? ???? ??? ??? ? ????. $routeMiddleware
??? ?? ??? ?????. rrreeecache
? ??? ???? ???? ???? ??? ?? ??? ? ????.
routes/web.php
??? ??? ??? ?????: ??rrreee??? ????? ????
? ?? cache ???/??>????. ??? <code>/example
??? ???? ????? ???? ??, ?? ?? ??? ?? ??? ???? ??? ????, ?? ??? ???? ???? ???. ?????? ??: ???? ?? ??? ??? ?? ???? ?? ?????. ?? ??????? ? ??? ?? ?? ??? ??? ? ????. ??????? ? ?? ?? ??, ?? ???? ?? ?? ??? ? ????. ??, Laravel?? ???? ?? ??? ??? ???? ?? ??? ?? ???? ? ????. ??????: ????? ????? ???? Laravel ??????? ??? ???? ???? ? ????. ?? Laravel?? ??? ?? ????? ???? ??? ?? ?? ? ?? ?????. ? ?? ??? ???? ?????. ??? ?? ??? ???? ?????. ??? ??? 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)

PHP?? ?? ??? ???? ? ?? ?? ??? ????. 1. php.ini? ?? ??? ??; 2. ? ?? (? : Apache? Setenv ?? nginx? FastCGI_Param)? ??????. 3. PHP ?????? putenv () ??? ??????. ? ??? Php.ini? ????? ??? ???? ??? ???? ? ?? ??? ?? ???? ????? ???? Putenv ()? ?? ??? ?????. ?? ???? ?? ?? (? : php.ini ?? ? ?? ??)? ???? ????. ?? ?? ??? ??? ?? ??? ????? ???? ?? ????.

Laravel? ?? ??? ?? ?? ??? ?? ?? ??? ???? ??? ??????. ?? ???? ?? ??? ????? ? ???? I/O ?? ? ?? ?? ??? ???? ???? ??? ?? ? ????. 1. ?? ????? ?? ? ? ???????? ??? ????? ?? ???? ??????. 2. ??? ? ??? ?? ? ? PhPartisAnconfig? ?? ???????. 3. ?? ??? ??? ??? ???? ?? ?? ?? ???? ???? ????. 4. ?? ?? ??? ???? ?? ??? ??? .env ??? ???? ?? ???????.

PHP ????? ?? ??? ??? ? ??? ??? CI (Continuous Integration) ????? ???? ? ????. 1. DockerFile? ???? ?? ???, ?? ??, ??? ?? ? ?? ??? ???? PHP ??? ?????. 2. Gitlabci? ?? CI/CD ??? ???? .gitlab-ci.yml ??? ?? ??, ??? ? ?? ??? ???? ?? ??, ??? ? ??? ?????. 3. PHPUNIT? ?? ??? ??? ??? ???? ?? ?? ? ???? ???? ????????. 4. Kubernetes? ?? ?? ?? ??? ???? ?? .yaml ??? ?? ?? ??? ?????. 5. Dockerfile ??? ? ??? ??? ??????

??? ?? ??? PHP ???? ?? ?? ??? ???? ?? ???????. RBAC (Role-Based Access Control) ??? ?? ???, ?? ? ??? ???? ??? ?? ?? ? ??? ?????. ?? ???? ??? ?????. 1. ???, ?? ? ??? ? ???? user_roles ? role_permissions? 3 ?? ?? ???; 2. $ user-> can ( 'edit_post')? ?? ???? ?? ?? ??? ?????. 3. ??? ???? ??? ??????. 4. ?? ??? ???? ?? ?? ?? ? ??? ? ???? ???? ?? ??? ? ?? ??? ?????. 5. ??? ??? ?? ?? ???? ?? ???? "??"? ??????.

Laravel? eloquentscopes? ?? ??? ??? ??? ?????? ?? ?? ??? ????? ?????. 1. ?? ??? ???? ???? ???? ???? Post :: published (); 2. ??? ??? ?? ??? ???? ???? ?? ??? ?? ?? ?? ??? ???? ???? ??? ?????? ??? ???? ???????. 3. ????? ?? ?? ?? ??? ??? ?? ?? ??? ?? ? ? ??? ?? ? ? ?? ?? ??? ?????. 4. ?? ??? ? ??? ?? ???? ? ??? ? ?? ??, ?? ??, ?? ???? ? ?? ?????????.

CreateAhelpers.phpfileInapp/helperswithCustOmFunctionsikeFormatPrice, isactiveroute, andisAdmin.2.addTheFileTothe "??"sectionOfcomposer.jsonUnderAutoLoad.3.runcomposerDump-AUTOLOADTOMAKETHINGTICTIONSGLOBELYAVAILABLE.4.USETHEHELPERFUNCUNTION

?? ?? ?? : ?? ????? PHP? ?? Error_Log ()? ??? ? ????. ????? ???? ??? ?? ??? ?????? ???? ?? ??? ? ?? ??? ???? ??? ?? ???, ??, ?? ? ?? ? ?? ?? ??? ???? ??? ??????. 2. ??? ?? ?? : ??? ??? ??? ??? ? ??? ?? ??? ??? ?? ??? ??? ??????? ??????. MySQL/PostgreSQL? ???? ??? ? ???? ??????. Elasticsearch Kibana? ? ???/? ???? ?????. ???, ??? ?? ? ??? ? ?? ??? ?? ??????. 3. ?? ? ?? ????? : ??, ???, ?? ? ??? ??? ??????. Kibana? ?? ????? PHP ??? ?? ?? ?????? ???? ???? ?????? ???? ??? ? ?? ??? ??? ? ????.

??, ??, ?? ?? ? ?? ??? ???? ?? ??? ?? ? ?? ???? ?????. 2. ?? ???? ???? ?? ??? ??? SONGSTOMONY ? HASMANY ?? ??; 3. ?? ? ? ?? ? ?? ??? ????? (?? ???? ?? ??? ? ??). 4. ?? ? ?? ??? ???? ?? ??? ???? ?? ? ?? ??? ???? ?? ??? ?????. 5. ?? ???? ??? ?? (?? ??)? ???? ?? ????? ??????. 6. ?? ??? ?? ??? ???? Laravel Signature URL? ???? ??? ??????. 7. ? ?? ?? ? ? ?? ??? ?? ?? ??? ?? ??? ?????. ?????? ??, ?? ?? ??? ??????????.
