Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Antonella's avatar

can I call a controller method in the seeder?

i created a method in the controller that calls a trello api i was wondering how to invoke this method in the seeder?

0 likes
8 replies
sr57's avatar

Just use the controller class

Antonella's avatar

for example he created the controller dog.

within it I create a method:

public  function _returnDog(Dog $dog) {
    

    return $dog;
}

how do I call this method inside the seeder?

sr57's avatar
use App\Http\Controllers\DogController;

assuming that the name of your contriller class is DogController, if not, adjust

Antonella's avatar

ok but then how do I call that function inside the seeder?

if I call it like this it gives me an error:

$this->_returnDog($dog);

@sr57

sr57's avatar

You have to instantiate your class first.

$obj1 = new ;

see last msg of @newbie360

2 likes
MichalOravec's avatar

Make an another class for that and then use it where you need.

forrestedw's avatar

Yes, like this:

$controller = new TheController();

$bar = $controller->methodYouWantToCall(...$args);
2 likes

Please or to participate in this conversation.