Skip to content

How to use Laravel helper functions in config files

Earlier today I needed to run a migration on a Laravel project I’m working on and got the following error after running php artisan migrate.

Argument 2 passed to Illuminate\Routing\UrlGenerator::__construct() must be an instance of Illuminate\Http\Request,
   null given, called in /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/RoutingServiceProvider.php on
  line 65

Like everybody else I went out Googling and Stack Overflow came through.

Turns out the issue was a config file for a library that I had just added. Because it was working with CSS and JS file paths I was using the url() helper function. Apparently that’s a no-go when running artisan commands.

But the solution was easy enough. The original line looked something like this.

'url' => url('path/to/file.js')

It just took a catch to see if we’re running on the command line.

'url' => app()->runningInConsole() : '' ? url('path/to/file.js')

Since the url wasn’t relevant when running the artisan command it doesn’t matter that it’s an empty string.

Published inCoding

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *