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

Login laravel lewat link Laravel
Mendapatkan ID dari data yang baru saja disisipkan di Laravel Controller
Mengenal Path yang ada di Laravel Laravel
Cara checked Old pada checkbox di Laravel Blade
Membuat migration dan seeder Laravel otomatis dari database Laravel
Contoh Controller Search multi tabel berelasi 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