An error in the abstract must be compatible with
I have an abstract class, something like this
protected function update(Request $request, $id)
{
//function body
}
and an extended class like
protected function update(PageRequest $request, $id)
{
//function body
}
entered PageRequest
expanded from request
<?php
namespace App\Http\Requests;
use App\Helpers\Helpers;
use App\Http\Requests\Request;
class PageRequest extends Request
{
//function body
}
I am getting this error
The application declaration \ Http \ Controllers \ PagesController :: update () must be compatible with App \ Http \ Controllers \ MasterController \ CrudController :: update (App \ Http \ Requests \ request $ request, $ id)
I know to pass all arguments and access them for update () methods and I think I am doing it right.
source to share
The best solution is to use an interface as described in this answer .
Another solution is to declare the method update()
in the child class without changing its signature and check in the code that the argument is of the correct type.
Something like that:
protected function update(Request $request, $id)
{
if (! $request instanceof PageRequest) {
throw new \InvalidArgumentException('Unexpected type ('.get_class($request).') of argument $request. Expecting an object of type PageRequest.');
}
// Do whatever you need to do with $request here
// It is an object of type PageRequest
}
This solution has its advantages in some contexts, but it makes the code more verbose and adds additional code to run.
source to share