I need to create seeds
in Laravel
. i have two tables as setting_categories
and settings
. Table schema as below.
I have added seeds in setting_categories
successfully.
I am trying to seed
for settings table as below
<?php
use Illuminate\Database\Seeder;
class Settings_v_1_0_Seeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::statement("TRUNCATE TABLE settings");
//$site_setting_id = SettingCategory::select("id")->whereSlug("site_settings")->firstOrFail();
$site_setting_id = App\SettingCategory::where('id', 1)->get()->first();
$settings = array(['created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s"), 'setting_category_id' => $site_setting_id, 'code' => 'site_name', 'value' => 'test', ' sort_order' => 1],
['created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s"), 'setting_category_id' => $site_setting_id, 'code' => 'header_caption', 'value' => 'test', ' sort_order' => 2],
['created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s"), 'setting_category_id' => $site_setting_id, 'code' => 'site_msg', 'value' => 'test. Copyright 2018 - 2018 ©', ' sort_order' => 3]
);
DB::table('settings')->insert($settings);
}
}
But it is throwing error as
Symfony\Component\Debug\Exception\FatalThrowableError : Class 'App\SettingCategory' not found
In the commented line I used $site_setting_id = SettingCategory::select("id")->whereSlug("site_settings")->firstOrFail();
as well. But no luck.
Could someone please suggest.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire