1. Go to this page and download the library: Download fxcosta/landlord 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/ */
Landlord::removeTenant('tenant_id');
// Or you can again pass a Model instance:
$tenant = Tenant::find(1);
Landlord::removeTenant($tenant);
// As you would expect by now, $tenant can be either a string column name or a Model instance
Landlord::hasTenant($tenant);
// $tenants is a Laravel Collection object, in the format 'tenant_id' => 1
$tenants = Landlord::getTenants();
use Illuminate\Database\Eloquent\Model;
use HipsterJazzbo\Landlord\BelongsToTenants;
class ExampleModel extends Model
{
use BelongsToTenants;
}
use Illuminate\Database\Eloquent\Model;
use HipsterJazzbo\Landlord\BelongsToTenants;
class ExampleModel extends Model
{
use BelongsToTenants;
public $tenantColumns = ['tenant_id'];
}
// 'tenant_id' will automatically be set by Landlord
$model = ExampleModel::create(['name' => 'whatever']);
// This will only ();
// This will fail with a ModelNotFoundForTenantException if it belongs to the wrong tenant
ExampleModel::find(2);
// Will Model::allTenants()->get()
// Will not scope by 'tenant_id', but will continue to scope by any other tenants that have been set
ExampleModel::withoutGlobalScope('tenant_id')->get();