DEV Community

Cover image for Running Laravel IDE Helper Generator automatically
Richard Dobroň
Richard Dobroň

Posted on

3 2

Running Laravel IDE Helper Generator automatically

When working on Laravel projects, I always try to keep working on hooks and automation.

There is no exception in this case when using the package barryvdh/laravel-ide-helper that generates helper files that enable your IDE to provide accurate autocompletion.

If you are working on a project where you regularly add database migrations then you will definitely find it handy to automatically call the command to generate those helpers.

The solution is very simple. Just register event listener MigrationsEnded in the file app/Providers/EventServiceProvider.php like this:

<?php
namespace App\Providers;
use Illuminate\Database\Events\MigrationsEnded;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Event;
class EventServiceProvider extends ServiceProvider
{
public function boot()
{
Event::listen(
MigrationsEnded::class,
function () {
Artisan::call('ide-helper:models -r -W');
}
);
}
}

You can customize the artisan command according to your needs.

Of course, I recommend creating the same command for the composer.json:

{
…,
"scripts": {
"schema": "php artisan ide-helper:models -r -W"
}
}
view raw composer.json hosted with ❤ by GitHub

Then just simply run:

composer run scripts
Enter fullscreen mode Exit fullscreen mode

Heroku

Deliver your unique apps, your own way.

Heroku tackles the toil — patching and upgrading, 24/7 ops and security, build systems, failovers, and more. Stay focused on building great data-driven applications.

Learn More

Top comments (0)

Image of Stellar post

How a Hackathon Win Led to My Startup Getting Funded

In this episode, you'll see:

  • The hackathon wins that sparked the journey.
  • The moment José and Joseph decided to go all-in.
  • Building a working prototype on Stellar.
  • Using the PassKeys feature of Soroban.
  • Getting funded via the Stellar Community Fund.

Watch the video

👋 Kindness is contagious

If you found these insights valuable, a like or a brief comment would be much appreciated. Also, consider joining our vibrant community and sharing your perspective on DEV!

Join the Community