Мне не удается отобразить данные из моей базы данных (я работаю с Laragon).
Я уже пытался изменить некоторые имена (переменные и т. Д.) Здесь и там, но я не могу найти, откуда возникла проблема.
Сначала я ничего не отображал, поэтому мне нужно было изменить:
resources \ views \ artist \ index.php -> resources \ views \ artist s \ index. blade .php
Мне, вероятно, нужно изменить больше вещей в коде, но я не знаю, где.
ПРОСМОТР (views \ artist \ index.blade.php)
@extends('layouts.app')
@section('title', 'Liste des artistes')
@section('content')
<h1>Liste des {{ $resource }}</h1>
<table>
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
</thead>
<tbody>
@foreach($artists as $artist)
<tr>
<td>{{ $artist->firstname }}</td>
<td>{{ $artist->lastname }}</td>
</tr>
@endforeach
</tbody>
</table>
@endsection
МАРШРУТЫ (маршруты \ web.php)
<?php
Route::get('/', function () {
return view('welcome');
});
Route::get('artists', 'ArtistController@index');
КОНТРОЛЛЕР (Controllers \ ArtistController.php)
<?php
namespace App\Http\Controllers;
use App\Artist;
use Illuminate\Http\Request;
class ArtistController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
/*
Take the artist from the db
and send it to a specific template
*/
$artists = Artist::all();
return view('artists.index',
[
'artists' => $artists,
'resource' => 'artistes',
]);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param \App\Artist $artist
* @return \Illuminate\Http\Response
*/
public function show(Artist $artist)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Artist $artist
* @return \Illuminate\Http\Response
*/
public function edit(Artist $artist)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Artist $artist
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Artist $artist)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Artist $artist
* @return \Illuminate\Http\Response
*/
public function destroy(Artist $artist)
{
//
}
}
DATABASE (база данных \ ArtistsTableSeeder.php)
<?php
use Illuminate\Database\Seeder;
class ArtistsTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$artists = [
['firstname'=>'Bob','lastname'=>'Sull'],
['firstname'=>'Marc','lastname'=>'Flynn'],
['firstname'=>'Fred','lastname'=>'Durand'],
];
foreach ($artists as $a) {
DB::table('artists')->insert([
'firstname' => $a['firstname'],
'lastname' => $a['lastname'],
]);
}
}
}
Единственное, что отображается в моем браузере при переходе на 127.0.0.1:8000/artists
, это:
**Liste des Artistes**
Firstname Lastname
Но ничего из содержимого моей таблицы Artistes не отображается.