samedi 16 novembre 2019

Laravel Through Relationship

Given below are the tables I have:

keywords
--------
id
keyword

Keyword table has many footprints

footprints
----------
id 
keyword_id
footprint

Each serp is associated with a footprint

serps
-----
id
footprint_id
phrase 

I need to get the keyword each serp is associated with. By reading about Laravel's Has One through relationship, I get the feeling that it can be done with has one trough relationship.

I want to get the keyword using:

  $serp->keyword;

On Serp Model, I wrote the following code which is not working. I will highly appreciate your help to the write right relationship code.

class Serp extends Model {
 //

 public function keyword(){
     return $this->hasOneThrough(
     '\App\Keyword',
     'App\Footprint') ;
 }
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire