| 1 | <?php |
||
| 9 | class PostController extends Controller |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var PostsRepository |
||
| 13 | */ |
||
| 14 | protected $posts; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * PostController constructor. |
||
| 18 | * @param PostsRepository $postsRepository |
||
| 19 | */ |
||
| 20 | public function __construct(PostsRepository $postsRepository) |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Index blog page. |
||
| 27 | * |
||
| 28 | * @return \Illuminate\View\View |
||
| 29 | */ |
||
| 30 | public function index() |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Single post view. |
||
| 39 | * |
||
| 40 | * @param \App\Post $post |
||
| 41 | * @return \Illuminate\View\View |
||
| 42 | */ |
||
| 43 | public function show($post) |
||
| 51 | } |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: