---
title: "PHP-Doc in Blade-Views"
description: "How to use PHP-doc tags for better autocompletion in Blade views."
canonical: "https://gummibeer.dev/blog/2020/phpdoc-in-blade-views"
---

# PHP-Doc in Blade-Views

How to use PHP-doc tags for better autocompletion in Blade views.

In my [Telegram Newsletter](/blog/2020/telegram-newsletter-command) post I've used PHP-doc type-hints without explaining them as I'm doing it every day.
In the comments [@alexfwulf](https://twitter.com/alexfwulf/status/1339576771222642689) mentioned that this was learning for him. So I'm dedicating a whole post on that topic.

With Laravel 7 we got Blade Components which are beautiful but also introduced even more ways to inject variables in a Blade View and for components we get some default variables.

Even before it was hard to know which variables are available in a Blade View and even harder what type they're.

The [Laravel IDEA](https://laravel-idea.com) plug-in gets better and better in resolving them. But isn't perfect so some manual work is still required.
My solution is to put PHP-doc variable type-hints to the start of my Blade files.
This way I immediately know which variables I can use and what type they're.

I'm using a single line and PHP-tag per type-hint. This way it's easier to copy or remove them.

```php
<?php /** @var \Illuminate\Support\Collection|\App\Models\User[] $users */ ?>
<?php /** @var string $name */ ?>
```

After I've added all the tags I can use the variables and can use PhpStorm awesome suggestions/autocompletion.

## Blade components

I start every Blade component with one to two tags as these are default component variables.
Primary the `$attributes` variable has a lot of undocumented methods you can use to do cool things like cherry-picking special attributes.

```php
<?php /** @var \Illuminate\View\ComponentAttributeBag $attributes */ ?>
<?php /** @var \Illuminate\Support\HtmlString $slot */ ?>
```
