The documentation Here suggests php artisan passport:client --client
for creating a client, but I want to do it using a controller, or ideally, using the native JSON apis provided by passport.
Is that possible at all or will I have to override the methods in Passport::client
?
Asked
Active
Viewed 1,184 times
1

Cœur
- 37,241
- 25
- 195
- 267

Riju Pramanik
- 23
- 1
- 9
-
have you tried `https://laravel.com/docs/5.8/artisan#programmatically-executing-commands` ? – Kishore Kadiyala Oct 31 '19 at 11:24
2 Answers
2
Old question, but here's a 2021 answer for people finding this on Google.
I find calling Artisan commands from code unsavory, especially as @kishore-kadiyala mentioned because you get back printed output, rather than code.
Instead, you can use the Laravel\Passport\ClientRepository class to create a client directly:
use Laravel\Passport\ClientRepository;
// ... snip ...
$clients = App::make(ClientRepository::class);
// 1st param is the user_id - none for client credentials
// 2nd param is the client name
// 3rd param is the redirect URI - none for client credentials
$client = $clients->create(null, 'My Client Name', '');
Here, $client
is a Laravel\Passport\Client instance directly. This is exactly how the Artisan command creates the clients anyway.

garrettmills
- 660
- 6
- 13
0

Kishore Kadiyala
- 154
- 3
-
I did look into this but I can't access the values generated using the command using the Artisan Facade – Riju Pramanik Nov 01 '19 at 07:22
-
-