'Error: Object of class Illuminate\Database\Eloquent\Builder could not be converted to string in file
so I'm trying to call this function with foreach array i'm pulling from supplier_id but i'm facing this problem
$request->validate([
'destination_id' => 'required|exists:table_destinations,id',
'supplier_id' => 'required|array',
'supplier_id.*' => 'required|exists:table_suppliers,id',
'account_id' => 'required|exists:table_accounts,id',
'test_type' => 'required|string'
]);
$destination_id = Destination::where('id', $request->destination_id)->first();
$suppliers = Suppliers::whereIn('id', $request->supplier_id)->get();
$account_manager = Account::where('account_id', $request->account_id)->first();
$type_of_test = $request->test_type;
foreach ($suppliers as $supplier) {
(new classUtilities())->saveData($destination_id, $supplier['id'],$account_manager, $type_of_test, $supplier['cost']);
}
and that my classUtilities where i'm using my function
function saveData(Destination $destination, $working_suppliers, Account $acccount_manager, string $test_type, $supplier_cost)
{
$working_supplier_id = Suppliers::where('id', $working_suppliers)->get();
$working_suppliers_cost_rate = Suppliers::where('cost_rate', $supplier_cost)->get();
$type_of_test = ItestTypeOfTest::where('test_name', $test_type);
AllData::insert([
'destination_id' => $destination->id,
'working_supplier_id' => $working_supplier_id,
'account_manager_id' => $acccount_manager->id,
'type_of_test' => $type_of_test,
'cost_rate' => $working_suppliers_cost_rate
]);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
