You can import information into Laravel using an array in the following ways:
$data = ['name' => 'John', 'email' => 'john@example.com'];
$user = User::create($data);
$data = [
['name' => 'John', 'email' => 'john@example.com'],
['name' => 'Jane', 'email' => 'jane@example.com'],
];
DB::table('users')->insert($data);
insert
method that allows you to insert multiple rows at once.$data = [
['name' => 'John', 'email' => 'john@example.com'],
['name' => 'Jane', 'email' => 'jane@example.com'],
];
User::insert($data);
It's important to note that you should ensure the array's keys match the database table's column names to ensure the data is imported correctly.
Asked: 2022-09-16 11:00:00 +0000
Seen: 16 times
Last updated: Oct 11 '21