Yes, it is a good idea to create separate tables for different types of users. This will help you to keep your code clean and organized. You can create two tables, one for SPA users and another for mobile application users. You can use Laravel's built-in authentication system to authenticate both types of users.
To create separate guards for both types of users, you can define them in your config/auth.php file. Here's an example:
'guards' => [
'spa' => [
'driver' => 'session',
'provider' => 'spa_users',
],
'mobile' => [
'driver' => 'session',
'provider' => 'mobile_users',
],
],
In this example, we have defined two guards, one for SPA users and another for mobile application users. We have also specified the providers for each guard. You can define the providers in the config/auth.php file as well.
'providers' => [
'spa_users' => [
'driver' => 'eloquent',
'model' => App\Models\SpaUser::class,
],
'mobile_users' => [
'driver' => 'eloquent',
'model' => App\Models\MobileUser::class,
],
],
In this example, we have defined two providers, one for SPA users and another for mobile application users. We have also specified the models for each provider.
Once you have defined the guards and providers, you can use them in your controllers and routes. Here's an example:
Route::middleware('auth:spa')->get('/spa', function () {
// Only authenticated SPA users can access this route
});
Route::middleware('auth:mobile')->get('/mobile', function () {
// Only authenticated mobile application users can access this route
});
In this example, we have defined two routes, one for SPA users and another for mobile application users. We have also specified the guards for each route using the auth middleware.
I hope this helps!