Hello!
Here's how I did it:
getFresh()
method of the Illuminate\Database\Query\Builder
class. So, I created the following class:<?php namespace App\Database; // Or use any namespace you think suits you better
use Illuminate\Database\Query\Builder as QueryBuilder;
class LdapQueryBuilder extends QueryBuilder {
public function getFresh($columns = array())
{
$users = parent::getFresh($columns);
foreach($users as &$user)
{
// Provide your logic here to fetch data from both sources (DB and LDAP) and add to $user.
$user->otherField = $otherValue;
}
return $users;
}
}
Illuminate\Database\Eloquent\Model::newBaseQueryBuilder()
in your model so we can use our custom query builder:<?php namespace App\Models;
use ...; // Your use statements.
use App\Database\LdapQueryBuilder;
class User extends ... implements ... { // Your extends and implements statements.
...
protected function newBaseQueryBuilder()
{
$conn = $this->getConnection();
$grammar = $conn->getQueryGrammar();
return new LdapQueryBuilder($conn, $grammar, $conn->getPostProcessor());
}
}
Now, everytime your model returns any result (including in Auth::user()), your returned model will contain attributes from LDAP and from DB, according the logic implemented in your custom query builder.
PS.: I did not tested this code thoroughly, but I didn't had any problems so far.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community