I have this 3 table:
stations (id,station_name)
products (id,product_name)
pivot table
product_station (station_id,product_id, tank_volum)
Station Model
public function products(){
return $this->belongsToMany(Product::class)
->withTimestamps()
->withPivot('tank_volume');
}
Product Model
public function stations(){
return $this->belongsToMany(Station::class);
}
I'm trying to create a station with many products and every product have it's tank volume but i can't save the tank volume value to database:
product_station table
this is my controller:
public function store(StationsRequest $request)
{
// dd($request);
$input = $request->all();
if($file = $request->file('photo_id')) {
$name = time() . $file->getClientOriginalName();
$file->move('images', $name);
$photo = Photo::create(['file'=>$name]);
$input['photo_id'] = $photo->id;
}
$station = Station::create($input);
$station->products()->sync($request->products , false);
return redirect('/admin/stations');
}
Q: How can i Save Tank volume inside product_station table "pivot table" ?
tank_volume
variable in your code. – Tpojkatank_volume
instore
method. How do you get value oftank_volume
? Is it from request, where do you find it? – Tpojka