jeudi 7 septembre 2017

Best way to create separate users table for different organisations in Laravel

We have a requirement where different users from different organisations would be using our site (getting built with Laravel). For legal reasons, we are considering keeping each organisations data in separate user's table.

My approach to this is to override the table property in App\User.php. This property get's initialized in constructor using session['company'] as shown below:

class User extends Authenticatable {

    protected $table = 'my_testing_table';

    public function __construct() {
        $table = session['company'] . 'users';
    }

    ...
}


class LoginController extends Controller {
    protected function authenticated(Request $request, $user) {
        session['company'] = "SomeCompany";
    }
}

What should be overriden in Registration? Is there a better approach to this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire