Skip to content
logo

Kotak Kode Pemograman

Sharing tentang bahasa pemograman

  • WordPress
    • Plugin
  • Tutorial
    • PHP
  • Laravel
  • Tools Webbsite
  • Desain
  • Source Code
  • Web Developer
  • Toggle search form

Membuat Seeder Laravel dari File JSON

Posted on 19/06/2024 By kotakkode No Comments on Membuat Seeder Laravel dari File JSON
<?php
  
namespace Database\Seeders;
  
use Illuminate\Database\Seeder;
use App\Models\Country;
use File;
  
class CountrySeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Country::truncate();
  
        $json = File::get("database/data/country.json");
        $countries = json_decode($json);
  
        foreach ($countries as $key => $value) {
            Country::create([
                "name" => $value->name,
                "code" => $value->code
            ]);
        }
    }
}
Laravel, Seeder

Post navigation

Previous Post: html to image laravel
Next Post: Mendapatkan ID dari data yang baru saja disisipkan di Laravel

Related Posts

Contoh Project Laravel 10 Github Laravel
Cara install laravel Laravel
Contoh Membuat Factory di Laravel Laravel
Jersey Avenue is an interactive SPA project using TALL Stack (TailwindCSS, AlpineJS, Laravel 10, Livewire). Laravel
Cara membuat Value selected Dropdown di halaman edit blade laravel Blade
Mendapatkan ID dari data yang baru saja disisipkan di Laravel Controller

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2026 Kotak Kode Pemograman.

Powered by PressBook Grid Blogs theme