Skip to content

Instantly share code, notes, and snippets.

View gamerwalt's full-sized avatar
🏠
Working from home

Olawale Adewoyin gamerwalt

🏠
Working from home
  • Saskatoon, Canada
View GitHub Profile
@gamerwalt
gamerwalt / homestead Connection issues?
Last active August 29, 2015 16:03
Homestead connection timeout warning solution (I believe)
After working with homestead/vagrant and using homestead up, i get connection timeout especially for windows.
My fix was halting the machine even though i couldn't do anything with it.
1. Open Virtual box
2. Start the VM with Virtualbox
3. Login using vagrant vagrant
4. Show status using homestead status/vagrant status in command line
5. Halt from command line.
6. When done, close virtual box
@gamerwalt
gamerwalt / migrations
Created October 2, 2015 19:19
Migrations for multitenant
Users
Schema::create('users', function (Blueprint $table) {
$table->increments('user_id');
$table->string('user_uid', 50)->unique();
$table->string('fullname', 600);
$table->string('email_address', 255)->unique();
$table->string('password', 60);
$table->string('verify_token', 60)->nullable();
$table->integer('status_code_id')->unsigned();
$table->foreign('status_code_id')
@gamerwalt
gamerwalt / env file sample for database connection
Created October 2, 2015 19:25
env file db connection sample
DB_HOST=localhost
DB_DATABASE=benta
DB_USERNAME=benta_app_user
DB_PASSWORD=
DB_ENCRYPTION_HOST=localhost
DB_ENCRYPTION_DATABASE=benta_enc
DB_ENCRYPTION_USERNAME=benta_enc_user
DB_ENCRYPTION_PASSWORD=
@gamerwalt
gamerwalt / database config
Created October 2, 2015 19:26
db_config_sample
'default' => env('DB_CONNECTION', 'benta'),
'connections' => [
'benta' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'latin1',
'collation' => 'latin1_swedish_ci',
@gamerwalt
gamerwalt / Event Service Provider Sample
Last active October 2, 2015 19:34
Event Service provider sample
protected $listen = [
'BentaNamin\Infrastructure\Events\RegistrationEvents\UserRegisteredEvent' => [
'BentaNamin\Infrastructure\EventListeners\RegistrationEventListeners\SendWelcomeEmail',
'BentaNamin\Infrastructure\EventListeners\RegistrationEventListeners\InformAdministrationOfNewRegistrant',
'BentaNamin\Infrastructure\EventListeners\RegistrationEventListeners\QueueEmailForNextSevenDaysIfNoActivity',
],
'BentaNamin\Infrastructure\Events\RegistrationEvents\TenantRegisteredEvent' => [
'BentaNamin\Infrastructure\EventListeners\RegistrationEventListeners\CreateTenantDatabaseRecords',
'BentaNamin\Infrastructure\EventListeners\RegistrationEventListeners\ProvisionTenantDatabases',
'BentaNamin\Infrastructure\EventListeners\RegistrationEventListeners\SendUserInfoToTenantDatabases',
@gamerwalt
gamerwalt / db_provisioner
Created October 2, 2015 19:40
db_provisioner
/**
* Handle the event.
*
* @param TenantRegisteredEvent $event
* @return void
*/
public function handle(TenantRegisteredEvent $event)
{
$migrate = '1';
@gamerwalt
gamerwalt / create_user_script
Created October 11, 2015 21:46
Create_User method
private function createUser($host, $databaseName, $username, $password)
{
$createUserQuery = "CREATE USER '$username'@'$host' IDENTIFIED BY '$password'";
$this->runStatement($createUserQuery);
$grantUserQuery = "GRANT SELECT, INSERT, UPDATE, EXECUTE, DELETE ON $databaseName.* TO '$username'@'$host' IDENTIFIED BY '$password'";
$this->runStatement($grantUserQuery);
}
@gamerwalt
gamerwalt / ConnectTenant
Created October 24, 2015 03:40
ConnectTenant Middleware
if ($this->auth->guest()) {
if ($request->ajax()) {
return response('Unauthorized.', 401);
} else {
return redirect()->guest('signin');
}
}
//get the current user
$this->user = $this->auth->user();
@gamerwalt
gamerwalt / TenantBaseController
Created October 24, 2015 03:42
TenantBaseController
abstract class TenantBaseController extends Controller
{
/**
* @var CommandBus
*/
public $commandBus;
/**
* @param \BentaCore\Infrastructure\Common\Commanding\CommandBus $commandBus
*/
@gamerwalt
gamerwalt / SampleModel
Created October 24, 2015 03:53
Sample Model
<?php
class StatusGroup extends BaseModel
{
protected $connection = 'benta_tenant';
protected $table = 'db_status_groups';
protected $primaryKey = 'status_group_id';