Это видео недоступно.
Сожалеем об этом.
Laravel - Seed Database from JSON File
HTML-код
- Опубликовано: 14 авг 2024
- In this video, we're going to have a look, in just a few steps, at how to seed the database with data that come from a JSON file within our application.
Article: neutrondev.com...
JSON file: gist.github.co...
================
Connect with me:
================
Twitter: / pelu_carol
Facebook: / neutrondevcom
Instagram: / neutrondevcom
GitHub: github.com/Tynael
Site: neutrondev.com/
Newsletter: neutrondev.com...
⏲️ Timestamps ⏲️
00:00 - Intro
00:28 - Create the JSON file
00:40 - Create the corresponding Model
01:40 - Create the migration
02:47 - Create the Seeder Class
05:40 - Call the Seeder
06:21 - The result
================
#laravel #database #seed
Article: neutrondev.com/seed-database-from-json-file-laravel/
⏲️ Timestamps ⏲️
00:00 - Intro
00:28 - Create the JSON file
00:40 - Create the corresponding Model
01:40 - Create the migration
02:47 - Create the Seeder Class
05:40 - Call the Seeder
06:21 - The result
php artisan make:model Movie -ms
Indeed, the '-ms' option comes in handy as it creates the migration and the seeder for the Model.
if it is implemented on the web with the case of importing JSON data from another web to the SQL database, does it need a routing on web.php?
Hi! Yes, you'll need an API endpoint for that. I'll suggest you using the api.php instead of web.php. web.php is for internal routes and api.php is dedicated to external routes (API endpoints). Also, make sure you take the proper security measures when implementing such an API because it can damage your database if you allow malicious users to insert data into your app.
how u can import a loot files json , like 10-20 json files
$json = Storage::disk('local')->get('/json/*.json');
You want to import multiple JSON files in bulk?
@@NeutronDev yea mate
@@zoomescrow4037 How big are those JSON files?
@@NeutronDev a per files like 1MB but its a loot like around 30 files json
@@zoomescrow4037 You can bulk 5 JSON files into 1 and then call the API. Repeat this until you process all the files.
Nice video, but I have a problem, my json is a bit different since it has an element with an array and object inside another array and object. Basically something like this (what would be the way to access the person name and schedule information to save them individually?):
[
{
"id": 173937,
"term": "202200",
"term_desc": "DECEMBER",
"nrc": "6754",
"campus": "CAMPUS II",
"subject_name": "Calculus",
"subject_course": "MAT522",
"person": [{ "name": "James" }],
"schedule": [
{
"begin_time": "18:01",
"end_time": "21:00",
"building": "B-4",
"campus": "CAMPUS II",
"start_date": "08/01/2022",
"end_date": "07/18/2022",
credits: 3,
"type": "TEO",
"room": "12",
"is_monday": false,
"is_tuesday": false,
"is_wednesday": false,
"is_thursday": true,
"is_friday": false,
"is_saturday": false,
"is_sunday": false
}
]
}];
Hey! Thank you 🙏
You have to parse the additional array of objects - person and schedule in your case.
I guess the simplest is to iterate over them within a foreach loop.
Cannot provide a snippet 'cause I don't know exactly how your code looks like.