Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 2 years ago.
0

Where do you want to call it? Whithin the model's class or whitin another controller's class? Anyway you can use dependency injection

Last updated 9 years ago.
0

controller method within model class

0
public function yourMethodWhitinTheModelClass(OrderController $controller)
{
    return $controller->mailInvoice($this->id);
}
0

got error:

Argument 2 passed to Orders::autoPay() must be an instance of OrderController, none given, called in /var/www/haroldas.test.com/app/controllers/OrderController.php on line 137 and defined

function autoPay($user, OrderController $controller)
{
      // ...
      return $controller->mailInvoice($this->id);
}
Last updated 9 years ago.
0

got error:

Argument 2 passed to Orders::autoPay() must be an instance of OrderController, none given, called in (filename) on line (linenumber)

Aha! So you are passing a function call with only 1 variable, you need to add another variable:

function autoPay($user, OrderController $controller)
{
      $nowwhereismysecondvariableplease = object_instance_of_OrderController;
      return $controller->mailInvoice($this->id, $nowwhereismysecondvariableplease);
}

I would pass $controller as that variable ...

Last updated 9 years ago.
0

Better to invoke an event that the controller observes so you don't wind up with code that is unnecessarily bound.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Dewilas dewilas Joined 13 Mar 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.