Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

TarikAli's avatar

TarikAli wrote a reply+100 XP

5mos ago

Refactor function and DB Transaction

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

5mos ago

Refactor function and DB Transaction

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

5mos ago

get user in multi guards same route

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

5mos ago

get user in multi guards same route

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

5mos ago

get user in multi guards same route

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