In my laravel project I'm trying to add mulitple image for RFQ table...can anyone tell me what i did wrong.
My relationship like: rfq hasMany images AND images belongsTo rfqs
This is my livewire method
public function store()
{
$validatedData = $this->validate([
'product_name' => 'required',
'product_category_id' => 'required|not_in:0',
'sub_category_id' => 'required|not_in:0',
'product_quantity' => 'required',
'unit_id' => 'required|not_in:0',
'purchase_price' => 'nullable',
'city' => 'required|',
'isChecked' => 'required|accepted',
'details' => 'required|string|min:1|max:500',
'images.*' => 'image|max:1024',
]) + [
'user_id' => auth()->user()->id,
];
$rfqData = Rfq::create($validatedData);
// if ($this->images)
// {
foreach ($this->images as $photo) {
$path_url = $photo->storePublicly('rfqs', 'public');
$rfqData->images()->attach($photo,[
'file_name' => $photo->getClientOriginalName(),
'file_path' => $path_url,
]);
}
// }
session()->flash('message', 'RFQ submitted successfully.');
$this->reset();
}