mercredi 27 mai 2020

Laravel debug the Model connection to check if the env function is parsing the credentials properly

Working on multi-database, multi-connection project in Laravel 5.8.x version.

I created a Model for fetching data from specific database using specific connection.

I have defined the connection variable in Model file as:

protected $connection = '[ConnName]';

And I have the said connection set in config/database.php as:

'connections' => [
    '[ConnName]' => [
        'username' => env('username'),
        ....
    ],
    ....
]

Still when I try to load the Model's data into Controller's Index action as:

$modelData = Model::orderBy('created_at', 'DESC');
exit(print_r(compact($modelData)));
return view('entity.index', compact('modelData'));

It prints null/no records, even though there is data in the database linked with model thro' said connection.

Can anyone suggest anyway to cross-check, if the connection credentials are properly parsed thro' env method or just how to print the utilized connection in controller ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire