My page shows posts that have been registered to the database. Some posts have files that have been uploaded. These files are saved in server folders and the database has the table "Pivot_files" with columns ID, Post, Name and Size.
$postagens = DB::table('postagens')
->where('dsa', '=', $id)
->OrderBy('Data_publicacao', 'Desc')
->get();
foreach ($postagens as $postagem => $post)
{
$arquivos_postagens[$post['Id_postagem']] = DB::table('arquivos_postagens')
->where('postagem','=', $post['Id_postagem'])
->first();
}
I'm now trying to use the above foreach to traverse the posts and perform another select in the "PivotTable" table where the "post" column receives the value of the post id and stores the result in another array so I send it to the page and can work with each of them.
However, it is not working. I searched and saw some Array videos in PHP but did not get the information I needed. Could you help me?
Thank you
Bank:
Table Posts Fields: ID_Post, date_publication, description, discipline (dsa), Title
Table File Fields: File_ID, Name, Post (PID_ID), Size
Select desired:
Assuming the id_id is equal to 5, I want it to return a table like this:
File_ID Name Post Size Size
3 leiame.txt 5 1024
4 foto.jpg 5 6780
5 aula.pdf 5 12304