I am trying to insert data but unfortunately i am getting error Array to string conversion please help me how can i resolve that thanks.
please check error https://flareapp.io/share/x5Mznjem
return request
{
"_token": "3qLsIoNwWiOuze8aurlSQGqU4FsgttXgY6sMFYnw",
"icon": "0AKj2DRZii6yhJsoWKLNUbmOWKrXzOqKoFJTF4LI.jpg",
"name": "fdgdfg",
"person_name": "dfg",
"contact_number": "43543543",
"city": [
"2",
"3",
"4",
"5"
],
"location": [
"1",
"3",
"4"
],
"address": "A-232 Gulshan-e-hadeed ph 2"
}
controller
public function store(Request $request)
{
// return $request->all();
$request->validate([
'name' => "required",
'icon' => 'nullable',
'person_name' => 'required',
'contact_number' => 'required',
]);
$agency = Agency::create($request->except('_token'));
foreach ($request->city as $key => $value) {
$agencyCityLocation = new AgencyCityLocation;
$agencyCityLocation->agency_id = $agency->id;
$agencyCityLocation->city_id = $value;
$agencyCityLocation->location_id = $request->location;
$agencyCityLocation->save();
}
return redirect()->route('agency');
}
$agencyCityLocation->location_id = $request->location;here you need to send id but your sending arraymultiple locationthen your database need to allow to insert array insted of single id