diff --git a/readme.md b/readme.md index 3f6f391..e6dffa8 100644 --- a/readme.md +++ b/readme.md @@ -42,68 +42,69 @@ var_dump( DB::table('users')->where('user_login', 'john')->first() ); ## Creating Models For Custom Tables You can use custom tables of the WordPress databases to create models: -``` - namespace whatever; - - - class CustomTableModel extends \WeDevs\ORM\Eloquent\Model { - - /** - * Name for table without prefix - * - * @var string - */ - protected $table = 'table_name'; - - - /** - * Columns that can be edited - IE not primary key or timestamps if being used - */ - protected $fillable = [ - 'city', - 'state', - 'country' - ]; - - /** - * Disable created_at and update_at columns, unless you have those. - */ - public $timestamps = false; - - /** Everything below this is best done in an abstract class that custom tables extend */ - - /** - * Set primary key as ID, because WordPress - * - * @var string - */ - protected $primaryKey = 'ID'; - - /** - * Make ID guarded -- without this ID doesn't save. - * - * @var string - */ - protected $guarded = [ 'ID' ]; - - /** - * Overide parent method to make sure prefixing is correct. - * - * @return string - */ - public function getTable() - { - //In this example, it's set, but this is better in an abstract class - if( isset( $this->table ) ){ - $prefix = $this->getConnection()->db->prefix; - return $prefix . $this->table; - - } - - return parent::getTable(); - } - - } +```php +table ) ){ + $prefix = $this->getConnection()->db->prefix; + + return $prefix . $this->table; + } + + return parent::getTable(); + } + +} ``` ### Retrieving All Rows From A Table