A few days ago, while working on a project where I wanted to use strict types and also have Larastan on the highest level, I needed to pass parameters from within the Laravel Request class into methods that expect a specific type, but the standard input() method on the Request class for retreiving parameters from the request returns a mixed type, which leads to a lot of single use variables just for type casting. Well, the good news is Larastan now passes, but, the bad news, you've now got six extra lines of code just for two extra variables to keep Larastan happy.... More bad news, the code has lost a bit of that elegance that we're all used to with Laravel....

Did you know that those methods return native types, rather than a mixed type? I didn't until a few days ago, but using those methods we can bring our code back to just three lines...
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners