2016-09-29 22:20:49 -07:00
|
|
|
<?php
|
|
|
|
|
2021-06-10 13:18:00 -07:00
|
|
|
namespace Database\Seeders;
|
|
|
|
|
2016-09-29 22:20:49 -07:00
|
|
|
use App\Models\User;
|
|
|
|
use Illuminate\Database\Seeder;
|
2021-09-23 22:05:42 -07:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
2016-09-29 22:20:49 -07:00
|
|
|
|
|
|
|
class UserSeeder extends Seeder
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Run the database seeds.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function run()
|
|
|
|
{
|
2017-10-07 03:41:46 -07:00
|
|
|
User::truncate();
|
2021-06-10 13:17:44 -07:00
|
|
|
User::factory()->count(1)->firstAdmin()->create();
|
|
|
|
User::factory()->count(1)->snipeAdmin()->create();
|
|
|
|
User::factory()->count(3)->superuser()->create();
|
|
|
|
User::factory()->count(3)->admin()->create();
|
|
|
|
User::factory()->count(50)->viewAssets()->create();
|
2021-09-23 22:05:42 -07:00
|
|
|
|
|
|
|
$src = public_path('/img/demo/avatars/');
|
|
|
|
$dst = 'avatars'.'/';
|
|
|
|
$del_files = Storage::files($dst);
|
|
|
|
|
|
|
|
foreach ($del_files as $del_file) { // iterate files
|
|
|
|
$file_to_delete = str_replace($src, '', $del_file);
|
|
|
|
Log::debug('Deleting: '.$file_to_delete);
|
|
|
|
try {
|
|
|
|
Storage::disk('public')->delete($dst.$del_file);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
Log::debug($e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$add_files = glob($src.'/*.*');
|
|
|
|
foreach ($add_files as $add_file) {
|
|
|
|
$file_to_copy = str_replace($src, '', $add_file);
|
|
|
|
Log::debug('Copying: '.$file_to_copy);
|
|
|
|
try {
|
|
|
|
Storage::disk('public')->put($dst.$file_to_copy, file_get_contents($src.$file_to_copy));
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
Log::debug($e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-23 22:16:19 -07:00
|
|
|
$users = User::orderBy('id', 'asc')->take(20)->get();
|
2021-09-23 22:05:42 -07:00
|
|
|
$file_number = 1;
|
|
|
|
|
|
|
|
foreach ($users as $user) {
|
|
|
|
|
|
|
|
$user->avatar = $file_number.'.jpg';
|
|
|
|
$user->save();
|
|
|
|
$file_number++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-09-29 22:20:49 -07:00
|
|
|
}
|
|
|
|
}
|