PHP code example of michielkempen / laravel-morphable
1. Go to this page and download the library: Download michielkempen/laravel-morphable 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/ */
michielkempen / laravel-morphable example snippets
use Illuminate\Database\Eloquent\Model;
use MichielKempen\LaravelMorphable\Morphable;
use App\UserModelFactory;
class User extends Model
{
use Morphable;
public $factory = UserModelFactory::class;
public $typeField = 'role';
}
use Illuminate\Database\Eloquent\Model;
use \MichielKempen\LaravelMorphable\MorphableModelFactory;
class UserModelFactory implements MorphableModelFactory
{
public static function create(string $type): Model
{
if($type == 'admin') {
return app(Manager::class);
}
return app(Customer::class);
}
}
class Manager extends User
{
// manager specific methods
}
class Customer extends User
{
// customer specific methods
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.