'How could search for records through your relationship records? with scope in laravel

How would you search for records by your (records) with which you have a relationship? Using scope.

public function scopeSearch($query, $search_option, $search) {
if($search_option != null) {
return $query->where("$search_option", 'LIKE', "%$search%");
}
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source