Answer the question
In order to leave comments, you need to log in
How to get data from a table in Laravel?
Hello!
There is such a controller with the following code:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
class LectViewController extends Controller
{
public function index(){
$lecturers = DB::table('Преподаватели')->select('id_Преподавателя', 'ФИО')->get();
$id = $lecturers->with('id_Преподавателя')->get();
$name = $lecturers->with('ФИО')->get();
return view('account')
->with(compact('id'))
->with(compact('name'));
}
}
<template>
<table class="ViewData">
<thead>
<tr>
<th>ID</th>
<th>ФИО</th>
</tr>
</thead>
<tbody>
<tr v-for="info in lecturers">
<td>{{info.id}}</td>
<td>{{info.name}}</td>
</tr>
</tbody>
</table>
</template>
<script>
export default {
name: "ViewTable",
props: [
'lecturers'
]
}
</script>
<style scoped>
</style>
$data = [
['id' => 1, 'name' => 'Admin'],
['id' => 2, 'name' => 'Truehero'],
['id' => 3, 'name' => 'Truecoder'],
];
return view('test', ['data' => $data]);
Answer the question
In order to leave comments, you need to log in
Why exactly two columns are needed is not clear at all. The method of obtaining data is tin.
And for the transfer of the data itself, https://laravel.com/docs/7.x/blade#displaying-data will help , you need to scroll a little lower and see:
The@json
directive is also useful for seeding Vue components or data-* attributes:
<example-component :some-prop='@json($array)'></example-component>
Using@json
in element attributes requires that it be surrounded by single quotes.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question