Q:

Call a custom model method from controller laravel4

I have a model like this:
class Event extends Eloquent

    {
        protected $softDelete = true;
        public function scopeSearchEvents($search_criteria)
        {
            return Event::whereIn('title',$search_criteria)
                            ->orWhereIn('description',$search_criteria)
                            ->whereApproved('1')
                            ->orderBy('event_date','desc')
                            ->get();
        }
    }

And im calling it from the controller like this:
$data = Event::search($search_criteria);

But it gives this error:
Symfony \ Component \ Debug \ Exception \ FatalErrorException
Call to undefined method Illuminate\Events\Dispatcher::search()

What is the best way of calling a custom model method from your controller?

A:

Make changes to your method as given below:
public function scopeSearchEvents($query, $search_criteria)
{
    return $query->whereIn('title', $search_criteria)
                 ->orWhereIn('description', $search_criteria)
                 ->whereApproved('1')
                 ->orderBy('event_date','desc');
}

Then call it like searchEvents not search:
// Don't use Event as your model name
$data = YourModel::searchEvents($search_criteria)->get();

Also make sure that, you want to use whereIn instead of where('title', 'LIKE', "% $search_criteria") and so.
Update:
You should change the model name from  Event to anything else because Laravel has it's core Event class, actually a Facade which is mapped to 'Illuminate\Support\Facades\Event'.

