I am using spatie missing page redirector https://github.com/spatie/laravel-missing-page-redirector . this libray have interface to implement the interface name Redirector. I wanted to implements the interface to merge both my class(which implements Redirtor) array config/missing-page-redirector.php array but this not working here is my config/missing-page-redirector.php
return [
'redirector' => \Spatie\MissingPageRedirector\Redirector\ConfigurationRedirector::class,
'redirect_status_codes' => [],
'redirects' => [],
];
below is my class which implements spatie interface Redirector
namespace App\Services;
use App\Model\Redirect;
use Spatie\MissingPageRedirector\Redirector\Redirector;
use Symfony\Component\HttpFoundation\Request;
use Illuminate\Support\Facades\Cache;
class MyRedirector implements Redirector
{
public function getRedirectsFor(Request $request): array
{
// Get the redirects from the config
$configRedirects = config('missing-page-redirector.redirects');
// Merge both values
return array_merge(['/old/url' => '/new/url'], $configRedirects);
}
}
Can you please let me know what is problem?
My Answer:
The issue might be with the way you are registering your custom Redirector class in your Laravel application. Make sure you have properly registered your custom Redirector class in your Laravel service provider.
You can register your custom Redirector class in the `AppServiceProvider` or any other service provider by adding the following code in the `register` method:
php
$this->app->singleton(\Spatie\MissingPageRedirector\Redirector\Redirector::class, function ($app) {
return new \App\Services\MyRedirector();
});
This code snippet registers your custom Redirector class as an implementation of the `Redirector` interface provided by the spatie/laravel-missing-page-redirector package.
After registering your custom Redirector class, make sure to clear the config cache by running the following command:
bash
php artisan config:clear
This will ensure that Laravel picks up the changes you made to the configuration file and the custom Redirector class registration.
Once you have registered your custom Redirector class properly, it should be used by the missing page redirector package to handle redirects based on your custom logic.
Rate this post
3 of 5 based on 5420 votesComments