php - How may I call a blade view in a custom Http Exception? (Laravel 7)

I am looking to return a view from the HttpException that is triggered by my package's middleware, currently, it returns a static 403 exception and I'd like to change that to a custom view from the package.
I have attempted returning a view in the exception itself, however, that proved unfruitful due to a receiving a TypeError.TypeError Return value of Username\Roles\Exceptions\InsufficientRoleException::forRoles() must be an instance of Username\Roles\Exceptions\InsufficientUsergroupException, instance of Illuminate\View\View returned
Here's the block of code itself, if anybody knows a way that this can be done without modifying theApp\Exceptions\Hander.php
it would be amazing, as I'm trying to keep this within package code itself and to not make manual edits for each Laravel app.
<?php
namespace Username\Roles\Exceptions;
use Symfony\Component\HttpKernel\Exception\HttpException;
class InsufficientUsergroupException extends HttpException
{
private $requiredRoles = [];
public static function forRoles(array $$roles): self
{
$permStr = implode(', ', $roles);
$error = 'Insufficient permissions to access this page.';
$exception = new static(403, $error, null, []);
$exception->requiredRoles = $roles;
//return $exception;
return view('role::InsufficientRoleAccess')->with('role', $permStr);
}
public function getRequiredRoles): array
{
return $this->requiredRoles;
}
}
Any support you can provide would be most appreciated! Thank you for reading this. :)
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: mysqli::real_connect(): (hy000/2002): connection refused
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.