PHP code example of saritasa / eloquent-custom
1. Go to this page and download the library: Download saritasa/eloquent-custom library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
saritasa / eloquent-custom example snippets
'providers' => array(
// ...
Saritasa\Database\Eloquent\PredefinedMigrationsServiceProvider::class,
)
class User extends Entity
{
protected $defaults = [
'role' => 'user'
]
}
$user = new User(['name' => 'John Doe']);
$this->assertEquals('user', $user->role); // true
$admin = new User['name' => 'Mary', 'role' => 'admin');
$this->assertEquals('admin', $admin->role); // true
class SomeModel extends Model {
...
protected static function boot()
{
parent::boot();
static::addGlobalScope(new \Saritasa\Database\Eloquent\Scopes\SortByName());
}
...
}
use Saritasa\Database\Eloquent\Models\CamelCaseModel;
class SomeModel extends CamelCaseModel
{
//your code
}
use Saritasa\Database\Eloquent\Models\CamelCaseForeignKeys;
class MyModel extends SomeModelClass
{
use CamelCaseForeignKeys;
}
bash
php artisan vendor:publish --provider=Saritasa\Database\Eloquent\PredefinedMigrationsServiceProvider --tag=migrations