Skip to content
Advertisement

Variable and function types in PHP 7.4 (laravel) [closed]

Yesterday I was at an interview and after looking at my code I was told that I did not have enough typing, I still cannot understand how to use it in PHP, I will be grateful for your help

This is an example of my code(laravel)

https://github.com/MrKrist17/Reasons/blob/master/app/Http/Controllers/ListOfReasonsController.php

(I’m asking for just an example of one of my functions, but with the addition of typing in the return and variables)

Advertisement

Answer

It looks like you already have a typehint on the variable – ListOfReasons. This returns a laravel redirect response, so a return type hint would look like this:

use IlluminateHttpRedirectResponse;
...
  public function destroy(ListOfReasons $listOfReasons): RedirectResponse
    {
        Storage::disk('public')->delete($listOfReasons->photo);
        $listOfReasons->delete();
        return redirect()->route('adminIndex');
    }
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement