Answer the question
In order to leave comments, you need to log in
How to display data from two different tables?
Good afternoon, I need to display in one view from two different tables, but when I try to display from the second table, it gives an error Undefined variable
In the controller, both models are connected
<?php
namespace App\Http\Controllers;
use Auth;
use Morelive\Models\User;
use Morelive\Models\Events;
use Morelive\Models\Live;
use Illuminate\Http\Request;
class LiveController extends Controller
{
public function getLive()
{
$games = Live::all();
return view('live.index', ['games' => $games]);
$events = Events::all();
return view('live.index', ['events' => $events]);
}
@foreach($games as $game)
<small class="pull-right">{{ $game->created_at }}</small>
@endforeach
@foreach ($events as $event)
<p>{{ $event->match }}</p>
@endforeach
Answer the question
In order to leave comments, you need to log in
public function getLive()
{
$games = Live::all();
$events = Events::all();
return view('live.index', compact('games', 'events'));
}
This is not a problem with Laravel. You don't know how to program. Get a programming materiel. There should not be two returns in a function on the same execution branch.
As soon as the function returns something, its work seems to stop)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question