PHP code example of vdauchy / laravel-model-injector

1. Go to this page and download the library: Download vdauchy/laravel-model-injector 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/ */

    

vdauchy / laravel-model-injector example snippets


// In: config/permission.php
return [
    'models' => [
        'permission' => Permission::class,
        'role' => Role::class,
    ],
    ...
];

// In: src/PermissionRegistrar.php
public function __construct(CacheManager $cacheManager)
{
    $this->permissionClass = config('permission.models.permission');
    $this->roleClass = config('permission.models.role');
    ...
}

// In: src/PermissionRegistrar.php

use HasModelInjection;

public function __construct(CacheManager $cacheManager)
{
    $this->permissionClass = $this->mClass(Permission::class);
    $this->roleClass = $this->mClass(Role::class);
    ...
}

$this->app->bind(Permission::class, MyCustomPermission::class);