Laravel @typehint Directive

It's worth noting that Laravel IDEA makes 90% of type annotations obsolete. If you're not using Laravel IDEA, go buy it now! For the other 10%, this trick helps!

If you use PhpStorm, you might find yourself adding type annotations to your Blade templates from time to time. This directive gives you a more ergonomic option:

		
1{{-- Now my IDE knows that $user is a User object --}}
2<?php /** @var \App\User $user **/
3@typehint(\App\User $user)

First, open up the PhpStorm blade settings and add this:

(The null| portion is unfortunately necessary due to how PhpStorm parses custom Blade configs.)

Then register an empty directive in your service provider. Note that the directive doesn't have to actually do anything, because it's just there to support code intelligence in the IDE.

		
1Blade::directive('typehint', static fn() => '');

Now you can swap out clunky phpdoc annotations with slightly more elegant @typehint directive!