In my Laravel 6.9.0 app, I have some code which I need to run from many places, so I'm working on creating this as a service layer.
I've created the file /app/Actions/Music/GetRecentArtists.php
and added it to my composer autoload config:
<?php
namespace App\Actions\Music;
use \Barryvanveen\Lastfm\Lastfm;
class GetRecentArtists {
public function get(Lastfm $lastfm)
{
return true;
}
}
But when I run it in Tinker using:
(new App\Actions\Music\GetRecentArtists())->get()
I get the following error:
TypeError: Too few arguments to function App/Actions/Music/GetRecentArtists::get(), 0 passed in Psy Shell code on line 1 and exactly 1 expected
I'd thought that dependency injection would inject the Lastfm
instance. When I remove the function argument, it runs fine.