Support the ongoing development of Laravel.io →
Eloquent Architecture

I got category_to_news and news_main table

category_to_news : news_id (int),name (varchar),title (timestamp)

news_main : id (int),title (varchar),image (int),created_at (varchar)

class Newsmain extends Eloquent {
    protected $table = 'news_main';
}
class Categorytonews extends Eloquent {
    protected $table = 'category_to_news';
 	public $uniquekey = 'title';
	public function Newsmain()
    {
        return $this->belongsTo('Newsmain');
    }
	
}

how to return by news_main's field and category_news's field ? I've tried this method and it's not work

$posts = Categorytonews::with(array(
    'Newsmain' => function($query)
    {
        $query->orderBy('id', 'DESC')->select(array('title', 'id', 'created_at', 'image'));
    }
    ))
    ->get( );
Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

rezadaulay rezadaulay Joined 25 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.