1. Go to this page and download the library: Download envor/laravel-datastore 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/ */
/**
* Create a newly registered user.
*
* @param array<string, string> $input
*/
public function create(array $input): User
{
$create = function () use ($input) {
Validator::make($input, [
'name' => ['();
return DB::transaction(function () use ($input) {
return tap(User::create([
'name' => $input['name'],
'email' => $input['email'],
'password' => Hash::make($input['password']),
]), function (User $user) {
$this->createTeam($user);
});
});
};
SQLite::make(database_path('my_backup.sqlite'))
->create()
->migratePath('database/migrations/platform')
->migrate()
->run($create)
->disconnect();
MariaDB::make('backup')
->create()
->migratePath('database/migrations/platform')
->migrate()
->run($create)
->disconnect();
return MariaDB::make('datastore')
->create()
->migratePath('database/migrations/platform')
->migrate()
->run($create)
->return();
}
Route::get('/contexed', fn() => 'OK')->middleware('datastore.context');
// or
Route::get('/contexed', fn() => 'OK')->middleware(\Envor\Datastore\DatastoreContextMiddleware::class);
// will use the authenticated user to configure a database
...
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable implements \Envor\Datastore\Contracts\HasDatastoreContex
{
use \Envor\Datastore\Concerns\BelongsToDatastore
public function datastoreContext(): \Envor\Datastore\Contracts\ConfiguresDatastore;
{
return $this->datastore;
}
}
interface HasDatastoreContext
{
public function datastoreContext(): ?\Envor\Datastore\Contracts\ConfiguresDatastore;
}
interface ConfiguresDatastore
{
public function configure();
public function use();
public function database(): ?\Envor\Datastore\Datastore;
}
ini
DATASTORE_PUSH_CONTEXT_MIDDLEWARE=true
AUTOCONFIGURE_DEFAULT_CONTEXT=true