I am new to Laravel and use authorization. I am looking for a way to change the default sql for Auth. In fact, Laravel does this using the following sql command:
SELECT * FROM users WHERE login="something" AND password = "something" LIMIT 1
I am trying to change the default sql as follows:
SELECT
u.id, u.name, c.company
FROM
users u, companies c
WHERE
u.login="something" AND
u.password = "something" AND
u.companyId = c.id
LIMIT 1
I realized that I had to create a user authorization system: create a new user provider and provider Auth.
First, I created an Auth folder inside the application and added it there CustomUserProvider.php
CustomUserProvider.php
<?php namespace App\Auth;
use Illuminate\Contracts\Auth\Authenticatable as UserContract;
use Illuminate\Contracts\Auth\UserProvider as UserProviderInterface;
use App\Models\User;
class CustomUserProvider implements UserProviderInterface {
protected $model;
public function __construct(UserContract $model)
{
$this->model = $model;
}
public function retrieveById($identifier)
{
}
public function retrieveByToken($identifier, $token)
{
}
public function updateRememberToken(UserContract $user, $token)
{
}
public function retrieveByCredentials(array $credentials)
{
}
public function validateCredentials(UserContract $user, array $credentials)
{
}
}
My customAuthProvider.php file , in App/Providers:
<?php namespace App\Providers;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use App\Auth\CustomUserProvider;
use Illuminate\Support\ServiceProvider;
class CustomAuthProvider extends ServiceProvider {
public function boot()
{
$this->app['auth']->extend('custom',function()
{
return new CustomUserProvider(new User);
});
}
public function register()
{
}
}
At the end, I install the driver for custom in config/Auth.php
'driver' => 'custom'
I am looking for a way to use these custom classes, how can I use the sql custom command for Login? Or maybe this is wrong?