1
I have 2 tables where there is a relationship, client
and content
using a pivot table contents_clients
, when selecting the contents
of the "X" client I can know which contents belong to it, but I can’t apply a filter referencing a table column content
$client = Client::find($client_id)->contents;
// Retorna um array de collection com os conteudos
all: [
App\Content {#795
id: "76",
title: "Teste Client 1",
content: "TESTE",
client_alteration: null,
target: "2",
scheduled_to: "2016-08-30 00:00:00",
status: "2",
created_at: "2016-08-29 14:27:34",
updated_at: "2016-08-29 14:27:34",
pivot: Illuminate\Database\Eloquent\Relations\Pivot {#794
client_id: "1",
content_id: "76",
},
},............
How do I apply a filter and select the status = 2
?
I’ve tried to: $client = Client::find($client_id)->contents->where('status', 2)->get();
and I get;
PHP warning: Missing argument 1 for Illuminate\Support\Collection::get()
For this to work
contents->where
I believe the Contents has to be called as a methodClient::find($client_id)->contents()->where('status', 2)->get();
– Neuber Oliveira