1. Go to this page and download the library: Download wfeller/parental 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/ */
wfeller / parental example snippets
// The "parent"
class User extends Model
{
//
}
// The "child"
class Admin extends User
{
use \WF\Parental\HasParent;
public function impersonate($user) {
...
}
}
// Returns "Admin" model, but reference "users" table:
$admin = Admin::first();
// Can now access behavior exclusive to "Admin"s
$admin->impersonate($user);
// First, we need to create a `type` column on the `users` table
Schema::table('users', function ($table) {
$table->string('type')->nullable();
});
// The "parent"
class User extends Model
{
use WF\Parental\HasChildren;
protected $fillable = ['type'];
}
// A "child"
class Admin extends User
{
use \WF\Parental\HasParent;
}
// Another "child"
class Guest extends User
{
use \WF\Parental\HasParent;
}
// Adds row to "users" table with "type" column set to: "App/Admin"
Admin::create(...);
// Adds row to "users" table with "type" column set to: "App/Guest"
Guest::create(...);
// Returns 2 model instances: Admin, and Guest
User::all();
class User extends Model
{
use \WF\Parental\HasChildren;
protected $fillable = ['type'];
protected $childTypes = [
'admin' => App\Admin::class,
'guest' => App\Guest::class,
];
}
class User extends Model
{
use \WF\Parental\HasChildren;
protected $fillable = ['parental_type'];
protected $childColumn = 'parental_type';
}
bash
php artisan parental:discover-children
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.