skip to Main Content

Laravel 9: authenticate while running a command

Here is an example of Laravel command: class TestUserCommand extends Command { protected $signature = 'test:user'; protected $description = 'Command description'; public function handle(): void { auth('api')->loginUsingId(1); ... domain service call } } It gives me the following error: Method…

VIEW QUESTION

Laravel use randomly created factory for relation

I'm trying to seed random belongsTo relationships for a Post, but they are all just being created with the same User and Community. Code: $users = AppModelsUser::factory(100) ->create(); $communities = AppModelsCommunity::factory(10) ->create(); AppModelsPost::factory() ->for($users->random()->first()) ->for($communities->random()->first()) ->create(); After seeding, when I…

VIEW QUESTION

Prevent repeating almost identical code in laravel

I have a controller in my API that contains methods that fetches various data from different tables like account statuses, account types, etc and returns it to the API consumer. use AppModelsAccountStatus; use AppModelsAccountType; use AppModelsAlertLevel; class ClientController extends Controller…

VIEW QUESTION
Back To Top
Search