0
Good morning, everyone,
I’m having a problem in a relationship between tables with Elouquent (Laravel)
I have two tables [clients / activities_commercial] (innoDB MYSQL)
In the client table there is a field (FK) called: activity_commercial In the table activity_commercial has the field index: id, along with the activity field_commercial (scan)
At the moment when I try to recover the customer information, I would like you to come to the fields of business activity and your id related to that customer.
I’m doing it this way in Controller:
$return = \App\Cliente::find($id)->with('atividadesComerciais')->get();
return view('clientes.show', ['data'=>$return]);
No Model:
public function atividadesComerciais()
{
return $this->belongsTo('App\AtividadesComerciais', 'atividades_comerciais_id', 'id');
}
Before I could access the information in the view by Lade like this
{{ $data['razao_nome'] }}
but now it’s not possible.
Where can I be wrong ?
I’m having trouble with relationships, I did what you explained but the problem persisted. The Relationship property always comes empty.
– Matheus Ilário
But what’s the problem?
– Wallace Maxters
I have an N to N relationship between areas and courses. I look for a specific area and use '$area->courses' and always returns empty
– Matheus Ilário