Skip to content

Commit

Permalink
Merge pull request #108 from andes2912/feature/command-admin-cli
Browse files Browse the repository at this point in the history
Command Admin CLI
  • Loading branch information
andes2912 authored Jun 13, 2023
2 parents 9e21ef2 + 4550ab2 commit ab25da5
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 69 deletions.
91 changes: 91 additions & 0 deletions app/Console/Commands/CreateAdminCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

namespace App\Console\Commands;

use App\Models\User;
use App\Models\LaundrySetting;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Spatie\Permission\Models\Role;
use App\Models\notifications_setting;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rules\Password;

class CreateAdminCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'create:admin';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Buat Pengguna Dengan Role Administrator';

/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$admin['name'] = $this->ask("Nama untuk Administrator");
$admin['email'] = $this->ask("Email untuk Administrator");
$admin['status'] = 'Active';
$admin['auth'] = 'Admin';
$admin['password'] = $this->secret("Password untuk Administrator");
$admin['password_confirmation'] = $this->secret("Konfirmasi Password untuk Administrator");

$cekUser = User::where('email', $admin['email'])->where('auth','Admin')->first();
if($cekUser) {
$this->error("User Administrator sudah dibuat!");
return -1;
}

$validator = Validator::make($admin,[
'name' => ['required','string','max:255'],
'email' => ['required','string','email','max:255','unique:'.User::class],
'password' => ['required','confirmed',Password::defaults()]
]);

if ($validator->fails()) {
foreach ($validator->errors()->all() as $error) {
$this->error($error);
}

return -1;
}
DB::transaction(function() use($admin, $cekUser){
$role = Role::firstOrNew(['name' => 'Admin']);
$role->name = 'Admin';
$role->save();

$admin['password'] = bcrypt($admin['password']);
$newAdmin = User::create($admin);
$newAdmin->assignRole('Admin');

$getIdAdmin = User::where('auth','Admin')->first();

$setting = new LaundrySetting;
$setting->user_id = $getIdAdmin->id;
$setting->target_day = 0;
$setting->target_month = 0;
$setting->target_year = 0;
$setting->save();

$notif = new notifications_setting;
$notif->user_id = $setting->user_id;
$notif->telegram_order_masuk = 0;
$notif->telegram_order_selesai = 0;
$notif->email = 0;
$notif->save();
});

$this->info("User " .$admin['email']. " Berhasil dibuat :)");
}
}
38 changes: 0 additions & 38 deletions database/seeders/AdminSeeder.php

This file was deleted.

2 changes: 0 additions & 2 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ class DatabaseSeeder extends Seeder
*/
public function run()
{
$this->call(AdminSeeder::class);
$this->call(SettingPageSeeder::class);
$this->call(LaundrySettingSeeder::class);
$this->call(RoleSeeder::class);
$this->call(IndoBankSeeder::class);
$this->call(addRoleSeeder::class);
Expand Down
25 changes: 0 additions & 25 deletions database/seeders/LaundrySettingSeeder.php

This file was deleted.

8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Version 3.1 use PHP 8.0 (Framework Laravel 9) [Versi 3.1](https://github.com/andes2912/laundry/tree/3.1)
* Database (eg: MySQL)
* Web Server (eg: Apache, Nginx, IIS)

## Framework

Laundry dibangun menggunakan [Laravel](http://laravel.com), the best existing PHP framework, as the foundation framework.
Expand All @@ -20,9 +20,9 @@ Laundry dibangun menggunakan [Laravel](http://laravel.com), the best existing PH
* Run `cp .env.example .env` for create .env file
* Run `php artisan migrate --seed` for migration database
* Run `php artisan storage:link` for create folder storage
* Detail login, Email : `admin@laundry.com` Password `123456`
* Run `php artisan create:admin` for create user Administrator
* Run `php artisan queue:listen` for run queue

Note : Aplikasi ini akan terus saya update.<br>
Kalau ada pertanyaan bisa kontak aku di email ini <b>andridesmana29@outlook.com</b>
</p>
Expand Down Expand Up @@ -58,7 +58,7 @@ Kalau ada pertanyaan bisa kontak aku di email ini <b>andridesmana29@outlook.com<
* Dashboard Customer
* Ubah thema (untuk saat ini hanya ada Dark & White)
* Notification List


## Sponsors

Expand Down

0 comments on commit ab25da5

Please sign in to comment.