2

I have a function within an AdminController for sending emails. I want to access this within another controller. Can anyone advise how I would modify this to work?

OrdersController

public function postOrder()
{
   $order = New Order;
   ...
   $order->save();
   // email order (call function in other controller)
   $this->emailOrder($order);
}

AdminController

public function emailOrder($order)
{
//email processing goes here
}

1 Answer 1

1

You would strip it out, either into an abstract controller, that your controllers inherit from:

class AdminController extends MyController

Or to a service that you can call from your controller:

Mail::sendOrder($order)
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I have set up a helper class to handle this, but it gives me error 'Undefined variable: order'. The service is set up to grab the ($order).
I take that back, all working well. My method was set to private static instead of just private. Thank you for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.