Support the ongoing development of Laravel.io →
posted 6 years ago

Hi I'm new to Laravel and I'm working on a project for my school, I've followed the roadmap given by the teacher but I still do not manage to display the data from my database.

I already tried to change some names (variables etc.) here and there but I can't find where come from the problem.

VIEW (views\artists\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

ROUTES (routes\web.php)

<?php

Route::get('/', function () {
    return view('welcome');
});

Route::get('artists', 'ArtistController@index');

CONTROLLER (Controllers\Auth\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)
    {
        //
    }
}

The only thing who get displayed on my browser when I go to this address

127.0.0.1:8000/artists

is :

Liste des Artistes

Firstname Lastname

But nothing from the content of my Artistes table is displayed.

Any idea? Thanks!

Last updated 3 years ago.
0

try doing a dd($artists); just before your return view(), see what artist all is giving you. if you get results try return view('artists.index')->with($artists);

or return view(artists.index,compact('artists'));

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Ali mcfly Joined 27 Apr 2019

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.