Method on Laravel model to find courses related to a course
No, this code belongs in the Model (or a related repository if you where using such a design, though thats kind of overkill with Active Record).

You can however reduce the number of queries by using the foreach loop to build a single query, instead of making a query per word:

public function relatedCourses()
{   
    $words = explode($this-&gt;name, " ");
    return Course::where(function($query) use ($words) {
        $query-&gt;where('id', '&lt;&gt;', $this-&gt;id);
        foreach ($words as $key =&gt; $word) {
            if($key==0){
                $query-&gt;where('name_es', 'LIKE', "%$word%")-&gt;orWhere('name_cat', 'LIKE', "%$word%");
            }else{
                $query-&gt;orWhere('name_es', 'LIKE', "%$word%")-&gt;orWhere('name_cat', 'LIKE', "%$word%");
            }
        }
    })-&gt;get();
}