3
My page shows posts that have been registered in the database. Some posts have files that have been uploaded. These files are saved in server folders and the database has the table "Archive" with the 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 am now trying to use the foreach above to scroll through the posts and perform another select in the "Archive" table where the "post" column receive the post id value and store the result in another array so that I send it to the page and can work with each one of them.
However, it’s not working. I searched and saw some Array videos in PHP but I couldn’t get the information I needed. Could you help me?
Thank you
Bench:
Table Posts Fields: Id_postagem, data_publicacao, description, disciplina (dsa), Title
Table Archive_posts Fields: File Id_name, Post(Id_post), Size
Select desired:
Assuming the Id_post is equal to 5 I want to return a table like this:
Id_file Name Post Size
3 reades.txt 5 1024
4 photo.jpg 5 6780
5 class.pdf 5 12304
Put in your question the two tables and relation fields that will be shown in select... What is the version of your Laravel?
– novic
My Standard is 5.3. I will make the edits in the question by putting what you requested.
– WitnessTruth
The relationship is 1
postagem
has severalArquivo_postagens
?– novic
This Virgilio. A post may have 0 or multiple files...
– WitnessTruth
I made an answer!
– novic