The Illuminate Database component is a full database toolkit for PHP, providing an expressive query builder, ActiveRecord style ORM, and schema builder.
- Query Builder / Schema Builder / Eloquent ORM
- Insert / Update / Delete
- Soft deleting
- Date Mutators / Carbon
- Query Scopes
- Event listener
- Eager loading
- Accessors / Mutators
- Array / JSON conversion
- Pagination
- and many more...
<?php
// put this into ADDONDIR/models/Testmodel.php
use Illuminate\Database\Eloquent\Model as Eloquent;
class Testmodel extends Eloquent {
use Sg\Paginator\PaginatorTrait;
protected $pageVariable = 'seite';
protected $table = 'rex_article';
const CREATED_AT = 'createdate';
const UPDATED_AT = 'updatedate';
protected $dates = ['createdate', 'updatedate'];
// needed if unix timestamp
protected function getDateFormat()
{
return 'U';
}
// model events
public static function boot()
{
parent::boot();
static::created(function($obj)
{
});
static::updated(function($obj)
{
});
static::saved(function($obj)
{
});
static::deleted(function($obj)
{
});
}
public function parent() {
return $this->belongsTo('Testmodel', 're_id');
}
public function children() {
return $this->hasMany('Testmodel', 're_id');
}
}
New classes need to be loaded by Composer
# open addon directory via console and enter:
php composer.phar dumpautoload
Or edit autoload_classmap.php with editor:
vendor/coposer/autoload_classmap.php
<?php
$item = Testmodel::first();
print $item->name;
print $item->createdate->format('d.m.Y');
// or
$items = Testmodel::where('status', 1)->orderBy('updatedate', 'desc')->take(5)->get();
foreach($items as $item) {
print $item->name;
print $item->updatedate->format('d.m.Y');
if($item->children!=null) {
foreach($item->children as $child) {
print $child->name;
print $child->updatedate->format('d.m.Y');
}
}
}
<?php
$items = Testmodel::where('status', 1)->orderBy('updatedate', 'desc')->paginate(5);
foreach($items as $item) {
print $item->name;
print $item->updatedate->format('d.m.Y');
}
// Pagination
print $items->links();
- paginator Standalone-Wrapper by Joseph Montanez
- illuminate/database Class by Taylor Otwel
- Babelfish AddOn by RexDude
- Parsedown Class by Emanuil Rusev