feat(bottle): menambahkan input outlet_ids
This commit is contained in:
parent
8d67c59f10
commit
8c411af7e5
@ -6,6 +6,7 @@
|
|||||||
use App\Rules\UnsignedInteger;
|
use App\Rules\UnsignedInteger;
|
||||||
use App\Traits\WithMediaHandler;
|
use App\Traits\WithMediaHandler;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
use Livewire\Form;
|
use Livewire\Form;
|
||||||
|
|
||||||
class BottleForm extends Form
|
class BottleForm extends Form
|
||||||
@ -24,6 +25,8 @@ class BottleForm extends Form
|
|||||||
|
|
||||||
public ?string $description = null;
|
public ?string $description = null;
|
||||||
|
|
||||||
|
public array $outlet_ids = [];
|
||||||
|
|
||||||
public array $image = [];
|
public array $image = [];
|
||||||
|
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
@ -34,6 +37,8 @@ public function rules(): array
|
|||||||
'cost_price' => ['required', 'numeric', new UnsignedInteger],
|
'cost_price' => ['required', 'numeric', new UnsignedInteger],
|
||||||
'sale_price' => ['required', 'numeric', new UnsignedInteger],
|
'sale_price' => ['required', 'numeric', new UnsignedInteger],
|
||||||
'description' => ['nullable', 'string'],
|
'description' => ['nullable', 'string'],
|
||||||
|
'outlet_ids' => ['required', 'array', 'min:1'],
|
||||||
|
'outlet_ids.*' => Rule::exists('outlets', 'id'),
|
||||||
'image' => ['nullable', 'array'],
|
'image' => ['nullable', 'array'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -46,6 +51,7 @@ public function validationAttributes(): array
|
|||||||
'cost_price' => 'harga beli',
|
'cost_price' => 'harga beli',
|
||||||
'sale_price' => 'harga jual',
|
'sale_price' => 'harga jual',
|
||||||
'description' => 'deskripsi',
|
'description' => 'deskripsi',
|
||||||
|
'outlet_ids' => 'outlet',
|
||||||
'image' => 'gambar',
|
'image' => 'gambar',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -59,7 +65,7 @@ public function setBottle(Bottle $bottle)
|
|||||||
$this->cost_price = $bottle->cost_price;
|
$this->cost_price = $bottle->cost_price;
|
||||||
$this->sale_price = $bottle->sale_price;
|
$this->sale_price = $bottle->sale_price;
|
||||||
$this->description = $bottle->description;
|
$this->description = $bottle->description;
|
||||||
|
$this->outlet_ids = $this->bottle->outlets->pluck('id')->toArray();
|
||||||
$this->image = $this->mapMediaCollection($bottle->getMedia('image'));
|
$this->image = $this->mapMediaCollection($bottle->getMedia('image'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,6 +82,8 @@ public function store()
|
|||||||
'description' => $this->description,
|
'description' => $this->description,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$bottle->outlets()->attach($this->outlet_ids);
|
||||||
|
|
||||||
$this->uploadMedia($this->image, $bottle, 'image');
|
$this->uploadMedia($this->image, $bottle, 'image');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -93,6 +101,8 @@ public function update()
|
|||||||
'description' => $this->description,
|
'description' => $this->description,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$this->bottle->outlets()->attach($this->outlet_ids);
|
||||||
|
|
||||||
$this->syncMedia($this->image, $this->bottle, 'image');
|
$this->syncMedia($this->image, $this->bottle, 'image');
|
||||||
$this->uploadMedia($this->image, $this->bottle, 'image');
|
$this->uploadMedia($this->image, $this->bottle, 'image');
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user