<?php

namespace App\Classes\General\Eloquent\Filters;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\DB;

class WithArrivalDate implements Filter
{

    /**
     * @param Builder $builder
     * @param $value
     * @return mixed
     */
    public static function apply(Builder $builder, $value)
    {
        return $builder->leftJoin('transport_arrangements', function ($join) {
            $join->on('packing_lists.id', '=', 'transport_arrangements.owner_id')->where('transport_arrangements.owner_type', 'App\Models\PackingList');
        })->addSelect(['packing_lists.*', DB::raw('transport_arrangements.drop_date as arrival_date')]);
    }
}