This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Http\Middleware; | |
| use Closure; | |
| use Illuminate\Support\Facades\Auth; | |
| class Tenant | |
| { | |
| /** |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * @param $class | |
| * @param array $attributes | |
| * @param int $times | |
| * @return mixed | |
| */ | |
| function create($class, $attributes = [], $times = 1) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| Route::get('/posts', function () { | |
| return \App\Models\Tenant\Post::all(); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use App\Models\Tenant\Post; | |
| use Faker\Generator as Faker; | |
| $factory->define(Post::class, function (Faker $faker) { | |
| return [ | |
| 'title' => $faker->sentence, | |
| 'body' => $faker->paragraph | |
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Models; | |
| use Illuminate\Database\Eloquent\Model; | |
| class TenantModel extends Model | |
| { | |
| protected $connection = 'tenant'; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Models; | |
| use Illuminate\Database\Eloquent\Model; | |
| class MainModel extends Model | |
| { | |
| protected $connection = 'main'; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use Illuminate\Support\Facades\Artisan; | |
| use Illuminate\Support\Facades\Config; | |
| use Illuminate\Support\Facades\DB; | |
| use Illuminate\Support\Facades\Schema; | |
| if (! function_exists('tenant_connect')) { | |
| /** | |
| * Establish a tenant database connection. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use App\Models\Main\Company; | |
| use Faker\Generator as Faker; | |
| $factory->define(Company::class, function (Faker $faker) { | |
| $hostname = '127.0.0.1'; | |
| $username = $faker->userName; | |
| $password = $faker->password; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use App\Models\Main\User; | |
| use App\Models\Main\Company; | |
| use Faker\Generator as Faker; | |
| $factory->define(User::class, function (Faker $faker) { | |
| static $password; | |
| return [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace Tests; | |
| use App\Models\Main\User; | |
| use Illuminate\Foundation\Testing\RefreshDatabase; | |
| abstract class TenantTestCase extends TestCase | |
| { | |
| use RefreshDatabase; |