For example, I develop an api and I have to type all my functions, I have a function that returns a list of movements, so how to define the return type of my function ? I tried to do this : public function getAllMovements() : Movement[] {}
But it does’nt work, i work with laravel 10.
2
Answers
I have defined a Movement Resource that return a movement collection
and in my function I have defined the resource as a return type and everything is working correctly
With this we are sure that the return type will be a collection of movements.
If you want it only available in documentation, it’s supported by phpdoc like so:
Else, I think you should create a strongly typed collection yourself, for example answered here: https://stackoverflow.com/a/73738459/3090890
In API’s its not uncommon to build typed collections like that.