В модели User:
public function phones()
{
return $this->hasMany(Phone::class);
}
В модели Phone:
public function user()
{
return $this->belongsTo(User::class);
}
Создание пользователя:
$user = new User();
$user->name = "Test";
$user->age = "100";
$user->active = 1;
$user->phones()->save('79999999991');
$user->phones()->save('79999999992');
$user->phones()->save('79999999993');
$user->save();
$headers = [
'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0'
, 'Content-Encoding' => 'UTF-8'
, 'Content-type' => 'text/csv; charset=utf-8'
, 'Content-Disposition' => 'attachment; filename='.$filename.'.csv'
, 'Expires' => '0'
, 'Pragma' => 'public'
];
$callback = function() use ($list)
{
$FH = fopen('php://output', 'w');
fputs( $FH, "\xEF\xBB\xBF" ); //UTF-BOM
foreach ($list as $row) {
fputcsv($FH, $row,';');
}
fclose($FH);
};
$filename = 'data.csv';
$data = "Fio,DateTime,Count".PHP_EOL;
$data .= "ФИО,".time().",50";
$response = Http::attach(
'file',
$data,
$filename
)->post('http://example.com/attachments');