4

I am trying to play a bit around with Laravel Spark, and as a test I'd like to override the "Create API Token" request.

I notice the endpoint being used, when a user should create an API token is this:

POST     | settings/api/token | Laravel\Spark\Http\Controllers\Settings\API\TokenController@store

So according to their guide on customization you should use their Spark::swap method.

So I have tried adding below piece of code into SparkServiceProivder@booted, but it doesn't seem to work:

use Laravel\Spark\Http\Controllers\Settings\API\TokenController;

use Laravel\Spark\Http\Requests\Settings\API\CreateTokenRequest;

Spark::swap(
    TokenController::class . '@store',
    function(CreateTokenRequest $request) {
        exit('Hello World');
    }
);

What am I doing wrong?

FooBar
  • 5,752
  • 10
  • 44
  • 93

1 Answers1

1

My suggestion would be to use a code like this in the SparkServiceProvider.php register function:

$this->app->singleton(
    'Laravel\Spark\Http\Controllers\Auth\RegisterController',
    'App\Http\Controllers\RegistrationController'
);

And then extend the App\Http\Controllers\RegistrationController with Laravel\Spark\Http\Controllers\Auth\RegisterController and change the items you need to.

  • Just an example basically you can do the same for Laravel\Spark\Http\Controllers\Settings\API\TokenController – Dhrupad Shrivastava Jun 09 '20 at 19:50
  • $this->app->singleton( \Laravel\Spark\Http\Controllers\Auth\RegisterController:class, \App\Http\Controllers\RegistrationController::class ); works now too. – Shawn H Jun 01 '21 at 00:57