I am trying to call a custom method in my Email model from my SessionsController. This is my model
<?php
class Email extends Eloquent {
protected $guarded = array();
public static $rules = array();
public function sendMail($type,$data)
{
echo "yes";
}
}
From my SessionsController I wanna call sendMail method. How am I supposed to call it?
You can do it either, using
class Email extends Eloquent {
public static function sendMail($type, $data)
{
//...
}
}
And call from controller
Email::sendMail('someType', $dataArray);
Or, you can use Scope (instead of static)
class Email extends Eloquent {
public function scopeSendMail($query, $type, $data)
{
// You can use $query here
// i.e. $query->find(1);
}
}
And call it from controller
Email::sendMail('someType', $dataArray);
Also check this answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With