Это видео недоступно.
Сожалеем об этом.

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

Комментарии • 13

  • @NeutronDev
    @NeutronDev  2 года назад

    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

  • @yacobee
    @yacobee Год назад +1

    php artisan make:model Movie -ms

    • @NeutronDev
      @NeutronDev  Год назад

      Indeed, the '-ms' option comes in handy as it creates the migration and the seeder for the Model.

  • @msyauqimubarak
    @msyauqimubarak 2 года назад

    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?

    • @NeutronDev
      @NeutronDev  2 года назад +1

      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.

  • @zoomescrow4037
    @zoomescrow4037 2 года назад

    how u can import a loot files json , like 10-20 json files
    $json = Storage::disk('local')->get('/json/*.json');

    • @NeutronDev
      @NeutronDev  2 года назад

      You want to import multiple JSON files in bulk?

    • @zoomescrow4037
      @zoomescrow4037 2 года назад

      @@NeutronDev yea mate

    • @NeutronDev
      @NeutronDev  2 года назад

      @@zoomescrow4037 How big are those JSON files?

    • @zoomescrow4037
      @zoomescrow4037 2 года назад

      @@NeutronDev a per files like 1MB but its a loot like around 30 files json

    • @NeutronDev
      @NeutronDev  2 года назад

      @@zoomescrow4037 You can bulk 5 JSON files into 1 and then call the API. Repeat this until you process all the files.

  • @conspilt5021
    @conspilt5021 Год назад +1

    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
    }
    ]
    }];

    • @NeutronDev
      @NeutronDev  Год назад

      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.