I am trying to fetch records from tow tables with an existing values.
Sample table data:
tbl1
id | name | tbl2_id
-----+-------------+--------------
1 | file.jpg | 1
2 | flower.jpg | 5
3 | project.zip | 3
4 | cat.jpg | 2
5 | flower.jpg | 1
6 | file.php | 4
tbl2
id | name | parent_id
-----+-------------+---------------
1 | Pictures | null
2 | Samples | 1
3 | Files | null
4 | Samples | 3
5 | mypics | 2
the tbl1.tbls2_id
is a field to store tbl2.id
for making relation between these tables. tbl2.parent_id
for store parents from tbl2
Now I have this string :
Pictures/Sample/mypics/flower.jpg
Is there any way to write a Model
or everything else to return an array like this :
[
'file_id' => 2,
'directories' => [
1, 2, 5
]
]