2016-09-01 16:23:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Illuminate\Database\Seeder;
|
|
|
|
|
|
|
|
class DatabaseSeeder extends Seeder
|
|
|
|
{
|
2017-02-16 17:32:01 +00:00
|
|
|
public static function createOrUpdate($tableName, array $values = [], $includeTimestamps = true)
|
|
|
|
{
|
|
|
|
$record = DB::table($tableName)->where($values)->first();
|
|
|
|
if (is_null($record))
|
|
|
|
{
|
|
|
|
// Add timestamps if we're creating a record
|
|
|
|
if ($includeTimestamps && !isset($values['created_at']))
|
|
|
|
{
|
|
|
|
$values['created_at'] = new \DateTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($includeTimestamps && !isset($values['updated_at']))
|
|
|
|
{
|
|
|
|
$values['updated_at'] = new \DateTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
DB::table($tableName)->insert($values);
|
|
|
|
$record = DB::table($tableName)->where($values)->first();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $record;
|
|
|
|
}
|
|
|
|
|
2016-09-01 16:23:39 +01:00
|
|
|
/**
|
|
|
|
* Run the database seeds.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function run()
|
|
|
|
{
|
2017-02-16 17:32:01 +00:00
|
|
|
$this->call(PermissionsSeeder::class);
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|
|
|
|
}
|