Redirect to Index Page instead of View after saving (Nova)
In Laravel Nova, if I block off access to the View pages of a Resource via a Resource Policy, I get a 403 when I create/update an instance of that resource. Is there a way to redirect to the index page of a resource after saving, as opposed to the detail page?
/**
* Return the location to redirect the user after creation.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @param \App\Nova\Resource $resource
* @return string
*/
public static function redirectAfterCreate(NovaRequest $request, $resource)
{
return '/resources/'.static::uriKey();
}
/**
* Return the location to redirect the user after update.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @param \App\Nova\Resource $resource
* @return string
*/
public static function redirectAfterUpdate(NovaRequest $request, $resource)
{
return '/resources/'.static::uriKey();
}
<?php
namespace App\Nova;
use Laravel\Nova\Http\Requests\NovaRequest;
trait RedirectAfterAction{
public static function redirectAfterUpdate(NovaRequest $request, $resource)
{
return static::redirectAfterAction();
}
public static function redirectAfterCreate(NovaRequest $request, $resource)
{
return static::redirectAfterAction();
}
public static function redirectAfterDelete(NovaRequest $request)
{
return static::redirectAfterAction();
}
public static function redirectAfterAction()
{
return '/resources/'.static::uriKey();
}
}