Advertisement
linuxyamigos

Untitled

Dec 27th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. <?php
  2.  
  3. namespace simplerest\models;
  4.  
  5. use simplerest\core\Model;
  6. use simplerest\libs\Factory;
  7.  
  8. class UsersModel extends Model
  9.  {
  10.     protected $table_name = "users";
  11.     protected $id_name = 'id';
  12.     protected $not_fillable = ['confirmed_email'];
  13.     protected $nullable = ['firstname', 'lastname', 'confirmed_email'];
  14.     protected $hidden   = [ 'password' ];
  15.  
  16.     /*
  17.         Types are INT, STR and BOOL among others
  18.         see: https://secure.php.net/manual/en/pdo.constants.php
  19.     */
  20.     protected $schema = [
  21.         'id' => 'INT',
  22.         'username' => 'STR',
  23.         'email' => 'STR',
  24.         'confirmed_email' => 'INT',
  25.         'password' => 'STR',
  26.         'firstname' => 'STR',
  27.         'lastname'=> 'STR',
  28.         'deleted_at' => 'STR',
  29.         'belongs_to' => 'INT'
  30.     ];
  31.  
  32.     protected $rules = [
  33.         'username'  => ['min'=>2, 'max'=>15, 'type' => 'regex:/^[a-zA-Z0-9_]+$/'],
  34.         'email'     => ['type'=>'email'],
  35.     ];
  36.  
  37.     function __construct($db = NULL){      
  38.         $this->accesorRegister('password', function($pass){ return password_hash($pass, PASSWORD_DEFAULT); });
  39.         parent::__construct($db);
  40.     }
  41.    
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement