Try to implements a custom user class in Laravel JWT authentication
I'm trying to implement an application that use a custom table for the user's informations.
My table _user looks like that
'USR_NoRole',
'USR_CompleteName',
'USR_UserName',
'USR_Password',
'USR_BBlocked',
'USR_BAssociation',
'USR_NoPeriode',
'USR_NoEntite',
'USR_CreateUser',
'USR_CreateTimestamp',
'USR_UpdateUser',
'USR_UpdateTimestamp'
When i create a new user, everything works and i get back a token
public function register(Request $request)
{
$validator = Validator::make($request->all(), [
'noRole' => 'required',
'completeName' => 'required',
'name' => 'required|string|max:255',
'password' => 'required|string|min:6|confirmed',
'noPeriode' => 'required',
'noEntite' => 'required'
]);
if ($validator->fails()) {
return response()->json($validator->errors()->toJson(), 400);
}
$user = User::create([
'USR_NoRole' => $request->get('noRole'),
'USR_CompleteName' => $request->get('completeName'),
'USR_UserName' => $request->get('name'),
'USR_Password' => Hash::make($request->get('password')),
'USR_BBlocked' => $request->get('isBlocked'),
'USR_BAssociation' => $request->get('isAssociation'),
'USR_NoPeriode' => $request->get('noPeriode'),
'USR_NoEntite' => $request->get('noEntite'),
'USR_CreateUser' => "jschneider",
'USR_CreateTimestamp' => date("Y-m-d H:i:s"),
'USR_UpdateUser' => "jschneider",
'USR_UpdateTimestamp' => date("Y-m-d H:i:s"),
]);
$token = JWTAuth::fromUser($user);
return response()->json(compact('user', 'token'), 201);
}
Here the result
{
"user": {
"USR_NoRole": "1",
"USR_CompleteName": "Complete Name",
"USR_UserName": "test#test.com",
"USR_Password": "$2y$10$bli2OTQQfsq7h4/XryZT4Op4p5DCnEGANCR5MYagHbndNU/ULmE3G",
"USR_BBlocked": null,
"USR_BAssociation": null,
"USR_NoPeriode": "1",
"USR_NoEntite": "1",
"USR_CreateUser": "test",
"USR_CreateTimestamp": "2019-04-01 07:02:13",
"USR_UpdateUser": "test",
"USR_UpdateTimestamp": "2019-04-01 07:02:13",
"id": 3
},
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sb2NhbGhvc3RcL2xhcmF2ZWwtand0XC9wdWJsaWNcL2FwaVwvcmVnaXN0ZXIiLCJpYXQiOjE1NTQxMDIxMzQsImV4cCI6MTU1NDEwNTczNCwibmJmIjoxNTU0MTAyMTM0LCJqdGkiOiJ2UGFURmNVbFE2WHVSY251Iiwic3ViIjozLCJwcnYiOiI4N2UwYWYxZWY5ZmQxNTgxMmZkZWM5NzE1M2ExNGUwYjA0NzU0NmFhIn0.Vi75d8uVSpzR_VddgfhJVGcyaNd-MsvjazPuUy81RXg"
}
But after that, when i try to login with this new user, i can't get a token. The result is always :
{
"message": "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name' in 'where clause' (SQL: select * from `_user` where `name` = jschneider#patinfo.ch limit 1)",
}
How can i configure the credentials to say that the field name matches with USR_UserName and the field password matches with USR_Password ?
My custom user class
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Tymon\JWTAuth\Contracts\JWTSubject;
class User extends Authenticatable implements JWTSubject
{
use Notifiable;
protected $table = '_user';
public $timestamps = false;
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'USR_NoRole', 'USR_CompleteName', 'USR_UserName', 'USR_Password', 'USR_BBlocked', 'USR_BAssociation', 'USR_NoPeriode', 'USR_NoEntite', 'USR_CreateUser', 'USR_CreateTimestamp', 'USR_UpdateUser', 'USR_UpdateTimestamp'
];
/**
* The attributes that should be hidden for arrays.
*
* #var array
*/
protected $hidden = [
'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* #var array
*/
protected $casts = [
// 'email_verified_at' => 'datetime',
];
public function getJWTIdentifier()
{
return $this->getKey();
}
public function getJWTCustomClaims()
{
return [];
}
}
the config/auth.php file
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
'guard' => 'api',
'passwords' => 'users',
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "session", "token"
|
*/
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'jwt',
'provider' => 'users',
],
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| You may specify multiple password reset configurations if you have more
| than one user table or model in the application and you want to have
| separate password reset settings based on the specific user types.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
],
],
];
Can anyone explain me how to set the app and create a token based on this 2 fields ?
place it on your controller
Config::set('jwt.user', 'App\OtherMOdel'); Config::set('auth.providers.users.model', \App\OtherMOdel::class);
Related
I have a problem when adding a second third party Oracle database to the TYPO3 Configuration in a TYPO3 9.5. After adding the configuration I cannot install any extensions (including core extensions) in ExtensionManager anymore.
In LocalConfiguration.php I add a second database (it's the database of a patent management system - no "TYPO3 style"):
'DB' => [
'Connections' => [
'Default' => [
....
],
'MyDB' => [
'charset' => 'utf8',
'dbname' => 'xxx',
'driver' => 'oci8',
'host' => 'xxx',
'password' => 'xxx',
'port' => '1521',
'user' => 'xxx',
],
],
'TableMapping' => [
'SCHEMA.TABLE1' => 'MyDB'
],
'extTablesDefinitionScript' => 'extTables.php',
],
I use QueryBuilder in the action in my controller and I can query the table without any problems.
BUT installing any extension in ExtensionManager leads to the following error:
(1/1) TypeError
Argument 1 passed to TYPO3\CMS\Core\Database\Schema\EventListener\SchemaColumnDefinitionListener::getDatabaseType() must be of the type string, null given, called in C:\inetpub\typo3_src-9.5.7\typo3\sysext\core\Classes\Database\Schema\EventListener\SchemaColumnDefinitionListener.php on line 41
in C:\inetpub\typo3_src-9.5.7\typo3\sysext\core\Classes\Database\Schema\EventListener\SchemaColumnDefinitionListener.php line 93
*
* #param string $typeDefiniton
* #return string
*/
protected function getDatabaseType(string $typeDefiniton): string
{
$dbType = strtolower($typeDefiniton);
$dbType = strtok($dbType, '(), ');
at TYPO3\CMS\Core\Database\Schema\EventListener\SchemaColumnDefinitionListener->getDatabaseType(null)
in C:\inetpub\typo3_src-9.5.7\typo3\sysext\core\Classes\Database\Schema\EventListener\SchemaColumnDefinitionListener.php line 41
public function onSchemaColumnDefinition(SchemaColumnDefinitionEventArgs $event)
{
$tableColumn = $event->getTableColumn();
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
$dbType = $this->getDatabaseType($tableColumn['type']);
if ($dbType !== 'enum' && $dbType !== 'set') {
return;
}
at TYPO3\CMS\Core\Database\Schema\EventListener\SchemaColumnDefinitionListener->onSchemaColumnDefinition(object(Doctrine\DBAL\Event\SchemaColumnDefinitionEventArgs))
As soon as I remove the second database from LocalConfiguration.php the ExtensionManager is working again - but of course the QueryBuilder does not know the table any more :enttäuscht:
I am using JWT in lumen and am unable to get token without password only With Email and i am using this code form stack overflow --
$user=User::where('email','=','user2#gmail.com')->first();
if (!$userToken=JWTAuth::fromUser($user)) {
return response()->json(['error' => 'invalid_credentials'], 401);
}
return response()->json(compact('userToken'));
This code give me error like this ->
ErrorException in UserController.php line 44:
Non-static method Tymon\JWTAuth\JWT::fromUser() should not be called statically, assuming $this from incompatible context
My controller UserController.php -
namespace App\Http\Controllers\v1;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Exception;
use Cartalyst\Sentinel\Native\Facades\Sentinel;
use Cartalyst\Sentinel\Laravel\Facades\Activation;
use Tymon\JWTAuth\JWTAuth;
use Illuminate\Support\Facades\Mail;
use App\Model\User;
use Tymon\JWTAuth\Exceptions\JWTException;
use Tymon\JWTAuth\Exceptions\TokenExpiredException;
use Tymon\JWTAuth\Exceptions\TokenInvalidException;
My - Config/auth
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
'guard' => env('AUTH_GUARD', 'api'),
'passwords' => 'users',
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "session", "token"
|
*/
'guards' => [
'api' => [
'driver' => 'jwt',
'provider' => 'users',
'identifier' => 'email',
'password' => 'password',
],
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => \App\User::class,
],
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| Here you may set the options for resetting passwords including the view
| that is your password reset e-mail. You may also set the name of the
| table that maintains all of the reset tokens for your application.
|
| You may specify multiple password reset configurations if you have more
| than one user table or model in the application and you want to have
| separate password reset settings based on the specific user types.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'passwords' => [
//
],
];
My bootstrap/app
<?php
require_once __DIR__ . '/../vendor/autoload.php';
try {
(new Dotenv\Dotenv(__DIR__ . '/../'))->load();
} catch (Dotenv\Exception\InvalidPathException $e) {
//
}
/*
|--------------------------------------------------------------------------
| Create The Application
|--------------------------------------------------------------------------
|
| Here we will load the environment and create the application instance
| that serves as the central piece of this framework. We'll use this
| application as an "IoC" container and router for this framework.
|
*/
$app = new Laravel\Lumen\Application(
realpath(__DIR__ . '/../')
);
$app->withFacades();
$app->configure('jwt');
$app->configure('auth');
class_alias(Tymon\JWTAuth\Facades\JWTAuth::class, 'JWTAuth');
class_alias(Tymon\JWTAuth\Facades\JWTFactory::class, 'JWTFactory');
$app->withEloquent();
/*
|--------------------------------------------------------------------------
| Register Container Bindings
|--------------------------------------------------------------------------
|
| Now we will register a few bindings in the service container. We will
| register the exception handler and the console kernel. You may add
| your own bindings here if you like or you can make another file.
|
*/
$app->singleton(
Illuminate\Contracts\Debug\ExceptionHandler::class,
App\Exceptions\Handler::class
);
$app->singleton(
Illuminate\Contracts\Console\Kernel::class,
App\Console\Kernel::class
);
$app->singleton(
Illuminate\Contracts\Routing\ResponseFactory::class,
Illuminate\Routing\ResponseFactory::class
);
/*
|--------------------------------------------------------------------------
| Register Middleware
|--------------------------------------------------------------------------
|
| Next, we will register the middleware with the application. These can
| be global middleware that run before and after each request into a
| route or middleware that'll be assigned to some specific routes.
|
*/
// $app->middleware([
// App\Http\Middleware\ExampleMiddleware::class
// ]);
$app->routeMiddleware([
'auth' => App\Http\Middleware\Authenticate::class,
'jwt.auth' => Tymon\JWTAuth\Middleware\GetUserFromToken::class,
'jwt.refresh' => Tymon\JWTAuth\Middleware\RefreshToken::class,
]);
/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
|
| Here we will register all of the application's service providers which
| are used to bind services into the container. Service providers are
| totally optional, so you are not required to uncomment this line.
|
*/
$app->register(App\Providers\AppServiceProvider::class);
$app->register(App\Providers\AuthServiceProvider::class);
$app->register(App\Providers\EventServiceProvider::class);
$app->register(Tymon\JWTAuth\Providers\LumenServiceProvider::class);
/*
|--------------------------------------------------------------------------
| Load The Application Routes
|--------------------------------------------------------------------------
|
| Next we will include the routes file so that they can all be added to
| the application. This will provide all of the URLs the application
| can respond to, as well as the controllers that may handle them.
|
*/
$app->group(['namespace' => 'App\Http\Controllers'], function ($app) {
require __DIR__ . '/../app/Http/routes.php';
});
return $app;
My Model User -
<?php
namespace App;
use Illuminate\Auth\Authenticatable;
use Laravel\Lumen\Auth\Authorizable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Tymon\JWTAuth\Contracts\JWTSubject;
class User extends Model implements JWTSubject, AuthenticatableContract, AuthorizableContract {
use Authenticatable,
Authorizable;
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'name', 'email',
];
/**
* The attributes excluded from the model's JSON form.
*
* #var array
*/
protected $hidden = [
'password',
];
public function getJWTIdentifier() {
return $this->getKey();
}
public function getJWTCustomClaims() {
return [];
}
}
My - JwtSubject -
<?php
/*
* This file is part of jwt-auth.
*
* (c) Sean Tymon <tymon148#gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Tymon\JWTAuth\Contracts;
interface JWTSubject
{
/**
* Get the identifier that will be stored in the subject claim of the JWT.
*
* #return mixed
*/
public function getJWTIdentifier();
/**
* Return a key value array, containing any custom claims to be added to the JWT.
*
* #return array
*/
public function getJWTCustomClaims();
}
My function __construct
class UserController extends Controller {
public $request;
protected $jwt;
public function __construct(Request $request, JWTAuth $jwt) {
try {
$this->request = $request;
$this->jwt = $jwt;
} catch (Exception $ex) {
\Log::error("Error : " . $ex);
$output = array('success' => false, 'result' => null, 'error' => $ex, 'error_key' => 'unhandled_exception');
return new Response($output);
}
}
Please help me how can i get token using only Email.
The issue is caused by this use statement in your UsersController.
use Tymon\JWTAuth\JWTAuth;
When you call JWTAuth::fromUser($user) you are not referencing the Facade (that contains an instance of JWTAuth already) but the actual function of the class, which you can't because it's not called statically.
This is what builds the Facade:
class_alias(Tymon\JWTAuth\Facades\JWTAuth::class, 'JWTAuth');
Remove that use statement and you should be fine.
Or modify it to use JWTAuth; so that you're referencing properly the Facade that is globally accessible.
Currently working with the Yii2 framework and using the includable \yiisoft\yii2-authclient OAuth abstraction class. I am able to connect and authenticate via Facebook but can not figure out how to access secondary data available through the OAuth2 scope configuration option.
Related but vague (as it does not explain how scope applies to the situation nor how to use the authClient to retrieve the data: Login with Facebook API
Config
'authClientCollection' => [
'class' => 'yii\authclient\Collection',
'clients' => [
'facebook' => [
'authUrl' => 'https://www.facebook.com/dialog/oauth',
'class' => 'yii\authclient\clients\Facebook',
'clientId' => '*****',
'clientSecret' => '*****',
'scope' => [
'email',
'public_profile',
'user_about_me',
'user_location',
'user_work_history',
]
],
],
],
Controller setup:
public function actions()
{
return [
'auth' => [
'class' => 'yii\authclient\AuthAction',
'successCallback' => [$this, 'onAuthSuccess'],
],
];
}
...
/**
* [onAuthSuccess description]
*
* #param [type] $client [description]
* #return [type] [description]
*/
public function onAuthSuccess($client)
{
$attributes = $client->getUserAttributes();
echo '<pre>';
print_r( $attributes );
echo '</pre>';
exit;
...
The returned object is as follows:
yii\authclient\clients\Facebook Object
(
[authUrl] => https://www.facebook.com/dialog/oauth
[tokenUrl] => https://graph.facebook.com/oauth/access_token
[apiBaseUrl] => https://graph.facebook.com
[scope] => Array
(
[0] => email
[1] => public_profile
[2] => user_about_me
[3] => user_location
[4] => user_work_history
)
[attributeNames] => Array
(
[0] => name
[1] => email
)
[version] => 2.0
...
)
How would I access the user's user_about_me data?
*Edited to add controller logic that provides the data dump.
You can get following info by setting this values in attributeNames
id
name
first_name
last_name
age_range
link
gender
locale
picture
timezone
updated_time
verified
In your config file
...
'components' => [
...
'authClientCollection' => [
'class' => 'yii\authclient\Collection',
'clients' => [
'facebook' => [
'class' => 'yii\authclient\clients\Facebook',
'authUrl' => 'https://www.facebook.com/dialog/oauth',
'clientId' => 'YOUR APP CLIENT ID',
'clientSecret' => 'YOUR APP CLIENT SECRET',
'attributeNames' => [
'id',
'name',
'first_name',
'last_name',
'link',
'about',
'work',
'education',
'gender',
'email',
'timezone',
'locale',
'verified',
'updated_time',
],
],
],
],
...
],
...
Important Links and references
https://developers.facebook.com/docs/facebook-login/permissions/v2.2
Login with Facebook API
What data can be obtained about a user who logs in with Facebook Oauth?
https://developers.facebook.com/tools/explorer/?method=GET&path=me%3Ffields%3Did%2Cname%2Cemail&version=v2.7
https://developers.facebook.com/docs/graph-api/using-graph-api/#fieldexpansion
You should use getUserAttributes method:
public function actions()
{
return [
[
'class' => 'yii\authclient\AuthAction',
'successCallback' => [$this, 'successCallback']
]
];
}
/**
* #param OAuth2 $client
*/
public function successCallback($client)
{
$attributes = $client->getUserAttributes();
...
}
Environment:
CakePHP 3
Postgres
I'm trying to do a migration to add a new field, then update some data for that field in our Postgres database. The entity seems to indicate that it's updated, but when I view the database, it is not saved.
Code
<?php
use Cake\Cache\Cache;
use Cake\ORM\TableRegistry;
use Migrations\AbstractMigration;
class AddDisplayRouteNumberToAgencies extends AbstractMigration
{
/**
* Up Method.
*/
public function up()
{
$table = $this->table('agencies');
$table->addColumn('display_route_number', 'boolean', [
'default' => true,
'null' => false,
]);
$table->update();
// Try to clear the Model cache
Cache::clear(null, '_cake_model_');
$patchData = [
'display_route_number' => false
];
$agencies = TableRegistry::get('Agencies');
$agency = $agencies->get(25);
// And save it back to the DB
$agencies->patchEntity($agency, $patchData);
debug($agency);
// Added after comment from ndm
$agencies->save($agency);
}
/**
* Down method
*/
public function down()
{
$table = $this->table('agencies');
$table->removeColumn('display_route_number');
$table->update();
// Clear the CakePHP Model cache
Cache::clear(null, '_cake_model_');
}
}
Results from debug()
object(App\Model\Entity\Agency) {
'id' => (int) 25,
'full_name' => 'Agency',
'legacy_agency_slug' => null,
'created' => object(Cake\I18n\Time) {
'time' => '2015-11-19T10:58:51+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'modified' => object(Cake\I18n\Time) {
'time' => '2015-11-19T10:58:51+0000',
'timezone' => 'UTC',
'fixedNowTime' => false
},
'display_route_number' => false,
'[new]' => false,
'[accessible]' => [
'*' => true
],
'[dirty]' => [
'display_route_number' => true
],
'[original]' => [],
'[virtual]' => [],
'[errors]' => [],
'[repository]' => 'Agencies'
}
Postgres query and results
SELECT id, display_route_number
FROM agencies
WHERE id = 25;
id | display_route_number
----+----------------------
25 | t
(1 row)
Other attempts
I also tried just using save() rather than patchEntities(), which returned the same results, except [dirty] is empty.
$agencies = TableRegistry::get('Agencies');
$agency = $agencies->get(25);
// Items to update
$agency->display_route_number = false;
// And save it back to the DB
$agencies->save($agency);
Thanks to #ndm for figuring this out for me. I ended up having to update the table schema. I believe this is because the Migration table part updates the SQL, but doesn't update the Schema.
Here's the final code:
// Clear the CakePHP Model cache
Cache::clear(null, '_cake_model_');
$table = $this->table('agencies');
$table->addColumn('display_route_number', 'boolean', [
'default' => true,
'null' => false,
]);
$table->update();
$agencies = TableRegistry::get('Agencies');
// REQUIRED!! Add the field to the Table schema
$agencies->schema()->addColumn('display_route_number', [
'type' => 'boolean',
'default' => true,
'null' => false
]);
$agency = $agencies->find()
->where(['short_name' => 'bart'])
->first();
// Items to update
$agency->display_route_number = false;
// And save it back to the DB
$agencies->save($agency);
I'm working on a Laravel Project which using a Postgre database, I run
php artisan migrate
Then I get error
[PDPException] could not find driver
But all my drivers is properly installled and enabled in my php.ini . I have a Yii Application that uses Postgre and works fine. php_pdo_pgsql is already installed and enabled.
Here's my config on Laravel
<?php
return [
/*
|--------------------------------------------------------------------------
| PDO Fetch Style
|--------------------------------------------------------------------------
|
| By default, database results will be returned as instances of the PHP
| stdClass object; however, you may desire to retrieve records in an
| array format for simplicity. Here you can tweak the fetch style.
|
*/
'fetch' => PDO::FETCH_CLASS,
/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/
'default' => 'pgsql',
/*
|--------------------------------------------------------------------------
| Database Connections
|--------------------------------------------------------------------------
|
| Here are each of the database connections setup for your application.
| Of course, examples of configuring each database platform that is
| supported by Laravel is shown below to make development simple.
|
|
| All database work in Laravel is done through the PHP PDO facilities
| so make sure you have the driver for your particular database of
| choice installed on your machine before you begin development.
|
*/
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => storage_path('database.sqlite'),
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
'pgsql' => [
'driver' => 'pgsql',
'host' => '192.168.3.9',
'database' => 'qms',
'username' => 'postgres',
'password' => 'postgres',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
],
],
/*
|--------------------------------------------------------------------------
| Migration Repository Table
|--------------------------------------------------------------------------
|
| This table keeps track of all the migrations that have already run for
| your application. Using this information, we can determine which of
| the migrations on disk haven't actually been run in the database.
|
*/
'migrations' => 'migrations',
/*
|--------------------------------------------------------------------------
| Redis Databases
|--------------------------------------------------------------------------
|
| Redis is an open source, fast, and advanced key-value store that also
| provides a richer set of commands than a typical key-value systems
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
*/
'redis' => [
'cluster' => false,
'default' => [
'host' => '127.0.0.1',
'port' => 6379,
'database' => 0,
],
],
];
You will need the doctrine/dbal package to use postgres. https://packagist.org/packages/doctrine/dbal
Add this to your application by requiring the package:
composer require doctrine/dbal