Answer the question
In order to leave comments, you need to log in
How to pull in data from two tables?
Hello. Faced difficulties when using Laravel 4.2
There is a Blog model:
<?php
class Blog extends Eloquent {
protected $table = 'blog';
public function comments()
{
return $this->hasMany('comments','page_id');
}
}
public function showWelcome()
{
$take_main = blog::where('active', '=', true)->take(3)->get();
$total_comments = Blog::find(1)->comments()->where('active', '=', 1)->get()->count();
print_r($total_comments);
//return View::make('hello', array('blog' => $take_main));
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question