Answer the question
In order to leave comments, you need to log in
Is it possible to work with two models in one controller?
I'm trying to display the number of records in two different Laravel 5.2 databases, one is displayed, and the other is not. Where could you go wrong? In routes?
use App\User;
use App\Post;
use Session;
class HomeController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
$users = User::paginate(5);
$posts = Post::paginate(5);
return view('test', compact('users','posts'));
}
{{ count($posts) }}
Undefined variable: posts
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