Entry for characters: Character1, Character2
$personajes = explode(',',$character);
$result = array();
if (count($personajes)>1) {
//count(personajes) = 2
foreach ($personajes as $persona) {
$obt_id = Tag::where('name', $persona)->get();
foreach ($obt_id as $id) {
//obtengo los id de los personajes
echo $id->id;
$result[] = FileTags::with('file')->where('tag_id', $id->id)->get();
}
}
}
The problem when I do echo only returns a single id instead of 2 (1 for each character), therefore my results are only those of a character. I need to be able to get the results of both characters.
EDIT: To explain myself a little better in this result, I bring all the filetags that have the tag_id 1 and 2, as I am using with I bring the data of the files as well.
Then from my table I would get only files 2, 3 and 4.
|tabla filetags|
| id | tag_id | file_id |
| 1 | 1 | 2 |
| 2 | 1 | 3 |
| 3 | 2 | 4 |
| 4 | 3 | 1 |
$result = FileTags::with('file')->where('tag_id', $id->id)->get();
TAG model
public function fileTag(){
return $this->hasMany('App\FileTags');
}
Model Archive
protected $table = 'files';
public function fileTag(){
return $this->hasMany('App\FileTags');
}
My FileTags Model
public function tag(){
return $this->belongsTo('App\Tag' , 'tag_id');
}
public function file(){
return $this->belongsTo('App\Archive', 'file_id');
}
I complement the EDIT:
|table tag|
| id | name |
| 1 | Personaje1 |
| 2 | Personaje2 |
I should get the id of Character1 and Character2, that is, 1 and 2, but I'm only getting the id of character 1.