A
A
Anton Vasiliev2021-03-05 23:02:11
Laravel
Anton Vasiliev, 2021-03-05 23:02:11

How to display information from 2 unrelated tables on a page in Laravel?

I need to display 2 unrelated tables on one page. I wrote this code:
web.php code Controller code
Route::get('/events', '[email protected]');

public function index()
    {
        return view('events', [
            'events' => DB::table('events')->paginate(7),
            'info' => DB::table('info')
        ]);
    }

Output in events.blade.php
<select>
 @foreach($events as $event) 
    <option value="{{ $event->id }}">{{ $event->$name}}</option>
  @endforeach
</select>
<select>
 @foreach($info as $inf) 
   <option value="{{ $inf->id }}">{{ $inf->$infname}}</option>
 @endforeach
</select>

The second table is not displayed. How to implement the output of the second table on this page, given that they are not related?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
the5x, 2021-03-05
@tambovvolk88

DB::table('info')->get();

I
Ilya, 2021-03-05
@New_Horizons

https://laravel.com/docs/8.x/queries

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question