How To Pass Multiple Parameter In Laravel Query Scope

Hello Artisan,

In this Laravel tip, the example will show you how to pass multiple parameters in the Laravel scope. You know that Laravel scope receives query parameters. But sometimes we need to pass one more parameter along with the query parameter.

So if you don't know Laravel scope - pass 2 parameters to scope then this example is completely for you. See the below example:

     * @param Eloquent Builder $query
     * @param Searchable Columns
public function scopeSearch(Builder $query, array $columns)
  return $query->when(request()->get('q'),function(Builder $q) use ($columns) {
    $q->whereLike($columns, request()->get('q'));


Read also: Laravel 9 Route Controller Group Improvements Example


Hope this example will help you.


#laravel #laravel-9x