<?php


namespace App\Repositories;


use App\BoxOrderLine;
use App\Discount;

class BoxOrderLineRepository implements RepositoryInterface
{
    public static function all() {
        return BoxOrderLine::all();
    }

    public static function create(array $data){
        return BoxOrderLine::create($data);
    }

    public static function update(array $data, $id){
        BoxOrderLine::findOrFail($id)->update($data);
        return BoxOrderLine::findOrFail($id);
    }

    public static function delete($id){
        return BoxOrderLine::destroy($id);
    }

    public static function find($id){
        return BoxOrderLine::findOrFail($id);
    }

    public static function createAndAssociate($id_order,$lines){
        $ids = array();
        foreach ($lines as $l){
            $l['box_order_id'] = $id_order;
            $line = BoxOrderLine::create($l);
            array_push($ids,$line->id);
        }
        return $ids;
    }
}
