<?php
namespace Clevercherry\Backslash4\Controllers\Admin;

use Illuminate\Http\Request;
use Clevercherry\Backslash4\Controllers\Controller;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\View;
use App\Models\User;

class UserController extends BkAdminController
{
    //public $adminView = 'backslash4::users';  // uses generic
    public $adminRoute = 'admin.users';
    public $AppModel = User::class;

    public function checkBeforeSave($store): array
    {

        if(isset($store['id']) && ( empty($store['password']) || empty(trim($store['password'])) ) )
            unset($store['password']); //don't update existing user password with empty
        else if(!isset($store['id']) && empty($store['password']))
            $store['password']=User::randomString();
        
        return $store;
    }

}
