TarikAli's avatar

TarikAli wrote a reply+100 XP

4mos ago

it creats values with this option (master details table) in the same service

    public function createValue(Option $option, array $value): OptionValue
    {
        $optionValue = new OptionValue();
        $optionValue->option_id = $option->id;
        $optionValue->fill($this->mapOptionValue($value));
        $optionValue->save();

        return $optionValue;
    }
TarikAli's avatar

TarikAli started a new conversation+100 XP

4mos ago

Hello, i have this function in a service :

I want to use DB::Transaction to store option with values or rollback all

first: can we refactor this function second: can i use DB::Transaction in a service or in the controller

TarikAli's avatar

TarikAli liked a comment+100 XP

4mos ago

yes

Step 1, find out who they are (authentication)

Step 2, determine what they are allowed to do (authorization)

If you need to hold different user metadata for each type of user, polymorphic relationships are the way.

I wrote an article years ago... https://novate.co.uk/using-laravel-polymorphic-relationships-for-different-user-profiles/

TarikAli's avatar

TarikAli wrote a reply+100 XP

4mos ago

ok, what's you opinion to use one guard for dashboard and one route for dashboard then admin and teacher and ...., enter dashboard using roles and permissions also make tow tables (admins, teachers) and linked morph with users table

TarikAli's avatar

TarikAli started a new conversation+100 XP

4mos ago

Hello, i have these routes

Route::group([
        'prefix' => LaravelLocalization::setLocale(), 
        'middleware' => ['localeSessionRedirect', 'localizationRedirect', 'localeViewPath']
    ],
    function () {
        Route::group([
            'prefix' => 'shared', 
            'as' => 'shared.',
            'middleware' => ['auth:admin,teacher'],
        ], function () {

            Route::prefix('options')->name('options.')->group(function () {
                Route::resource('', OptionController::class)->parameters(['' => 'option']);
                
            });
        }); 
});

when i loged in in the same browser it tow tabs one admin and the other teacher and

@dd(auth()->guard('admin')->check(), auth()->guard('teacher')->check())

the tow gives true

i want to get the options accordding to admin or teacher