How to identify the data type returned from a controller?

Asked

Viewed 38 times

0

I noticed that when creating a controller in Laravel it informs that some methods will return an object \Illuminate\Http\Response.

I used a dd() at the end of the method and saw the following return: \Illuminate\View\View and in another method \Illuminate\Http\RedirectResponse

In this case, when documenting the methods I should always consider: \Illuminate\Http\Response or I can insert the object displayed in the method output dd()?

  • Show an example of documentation ... I could not see your doubt.

1 answer

0

You can use the instanceof of PHP

if ($objeto instanceof \Illuminate\Http\Response) {
    ... faz algo aqui ...
} else if ($objeto instanceof \Illuminate\View\View) {
    ... faz algo aqui ...
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.