Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Rymercyble's avatar

retrieve data related to related table on model query

hello, i have got tables articles, files and uploads

my current query

ArticleNew::where('article_id', 2931)
            ->with([
                'files' => function($query){
                    $query->select('url', 'filename', 'mimetype', 'db_files_new.file_id')
                        ->orderBy('file_id');
                },
                'uploads' => function($query){
                    $query->where('thumbnail_id', '!=', 0)
                        ->select('db_uploads_new.file_id', 'thumbnail_id');
                },
                'category',
                'relations',
            ])->select('article_id', 'lang_id', 'url', 'author_id', 'created_on', 'title', 'description', 'content')
            ->get();

it returns article itself and related files (images/videos) but if it is video then it got thumbnail paired via uploads table but this returns only thumbnail_id from uploads table and i also need to get data from files table for that thumbnail_id

0 likes
0 replies

Please or to participate in this conversation.