Laavel 8.50에 추가된 수수한 기능 Prining Models

4802 단어 Laravelprunetech
Ver.8.50에 추가된 기능 중 하나는 필요하지 않은 데이터를 삭제할 때 작용할 수 있다.(prune...수확)
이 기능이 나오기 전에 제 관련 프로젝트에서'로그인 후 3개월 후의 발언을 정기적으로 삭제'기능을 만들었습니다. 그때 조건에 맞는 데이터를 삭제하는 명령을 했고 그 명령을 정기적으로 호출했습니다. 만약에 이 Prouning Models의 기능을 사용한다면모델 파일로 TRAIT를 읽고 방법을 준비한 다음 모델:prune 명령을 정기적으로 호출하면 됩니다.
참조: [8.x] Adds the possibility of having "Prounable" models#37889
참조: 홈 문서, Prouning Models

실제로 어떤 느낌


두 개의 위탁 관리가 있는데, 그 중 하나를 사용한다.
Illuminate\Database\Eloquent\Prunable
Illuminate\Database\Eloquent\MassPrunable
MassPunable는 갑자기 삭제되기 때문에 모델 이벤트가 발생하지 않고 Punable는 삭제할 때 모델 개별 이벤트가 발생합니다.
그렇다면 사용법은 이렇다.(문서는 그대로 유지...)
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Prunable;

class Flight extends Model
{
    use Prunable;

    /**
     * Get the prunable model query.
     *
     * @return \Illuminate\Database\Eloquent\Builder
     */
    public function prunable()
    {
        return static::where('created_at', '<=', now()->subMonth());
    }
}
이후에 App\Connee\Keernel을 사용하십시오. 예를 들어 다음과 같이 정기적으로 호출하면 됩니다.
protected function schedule(Schedule $schedule)
{
    $schedule->command('model:prune')->daily();
}
기타 상세한 내용은 문서를 확인하세요.
겸사겸사 말씀드리겠습니다, Ver.8.48.0, "Added a queue:proune-failed command"의 기능도 그 안에 추가되었다. 같은 prone도 다른 것이다.
참조: [8.x] Adda queue: prune-failed command#37696

잡감


없어도 상관없는 기능이지만 있으면 있을 수도 있어요.

좋은 웹페이지 즐겨찾기