PHP code example of devanoxltd / core

1. Go to this page and download the library: Download devanoxltd/core 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/ */

    

devanoxltd / core example snippets


use Devanox\Core\Http\Middleware\PreventAccessFromCentralDomains;
use Illuminate\Support\Facades\Route;

// ...

->withRouting(
    web: __DIR__.'/../routes/web.php',
    commands: __DIR__.'/../routes/console.php',
    health: '/up',
    then: function () {
        if (file_exists(base_path('routes/tenant.php'))) {
            Route::middleware([
                'web',
                PreventAccessFromCentralDomains::class,
            ])
                ->name('tenant.')
                ->group(base_path('routes/tenant.php'));
        }
    }
)

namespace App\Models;

use Devanox\Core\Models\Tenant as BaseTenant;

class Tenant extends BaseTenant
{
    // Add custom relationships or logic here
    public function users()
    {
        return $this->hasMany(User::class);
    }
}

    'models' => [
        'tenant' => App\Models\Tenant::class,
        'domain' => Devanox\Core\Models\Domain::class,
    ],

use App\Models\Tenant;

$tenant = Tenant::find(1);

tenancy()->run($tenant, function ($tenant) {
    // This code will run within the context of the tenant
    // e.g., using the tenant's database connection
});
bash
php artisan vendor:publish --tag="core"
bash
php artisan vendor:publish --tag="core-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="tenancy-config"
php artisan vendor:publish --tag="tenancy-migrations"
php artisan tenancy:install
php artisan migrate