Skip to content

Commit

Permalink
Updated code indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tareq1988 authored Apr 2, 2020
1 parent 511a2b9 commit d34de75
Showing 1 changed file with 63 additions and 62 deletions.
125 changes: 63 additions & 62 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?php
namespace Whatever;

use WeDevs\ORM\Eloquent\Model;

class CustomTableModel extends 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();
}

}
```

### Retrieving All Rows From A Table
Expand Down

0 comments on commit d34de75

Please sign in to comment.