How to filter by method? Laravel 5.4

1

I need to filter all the images that have a specific link, I was able to filter through status of the product table, but what binds the image to the product is the image(); method of the Produto class:

Method image() of class Product:

public function image()
{
    return $this->hasOne('App\ProdutoImage', 'erp_productid', 'erp_productid');
}

I need to get the value erp_image from ProdutoImage and pass to the filter I tried to do this, but it does not filter:

if(request()->has('erp_image'))
{
    $produtos = Produtos::where('erp_image', request('erp_image'))
              ->paginate(25)
              ->appends('erp_image', request('erp_image'));
} 
else 
{
    $produtos = Produtos::paginate(25);
}

In my View I added Link :

<a href="/products/?erp_image=http://teste.s3-website-sa-east-1.amazonaws.com/produtos/teste.jpg">
    <span class="label label-primary">Sem Imagem</span>
</a>

Any suggestions?

    
asked by anonymous 23.03.2017 / 12:57

1 answer

0

Could not understand right, but would this?

Produtos::whereHas('image', function ($query){
    $query->where('erp_image', request('erp_image'));
})->paginate();

Returns the products that have an image that satisfies the filter.

    
29.03.2017 / 21:21