Instead of littering your controller method with multiple request()->has(‘field’) checks, you can employ the request object’s intersect method. The intersect method will return a new array containing only the keys that are present in both the specified list and the request itself.
Using intersect allows you to easily handle a PATCH request – one where you partially update a resource’s data, rather than all of it as with a PUT – in a much more concise manner.
Every two weeks I send out a newsletter containing lots of interesting stuff for the modern PHP developer. You can expect quick tips, links to interesting tutorials, opinions and packages. Want to learn the cool stuff? Then sign up now!