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

Menambahkan Default Port Laravel di .env Laravel
Starter Project Laravel Laravel
Repository Blog Laravel Laravel
Solusi CURL ERROR 60: SSL Certificate Problem di LARAVEL atau di curl PHP Laravel
Laravel 403 Forbidden Upload to resfull API Laravel
Cara menghapus gambar/file di folder public 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