Sorry, I'm new to developing on Laravel. I'm trying to show info contained in the database on my page. But it can't find the variable holding all the data. I can see the info in Tinker, but i can't seem to deplay is.
I posted some pictures so you can have a look. I'd love to hear your feedback.
Images: https://i.sstatic.net/ynfkP.jpg
Code:
Route:
<?php
Route::get('/', function () {
return view('index');
});
Route::resource('complaints', 'ComplaintController');
Controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Complaint;
class ComplaintController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$complaints = Complaint::all();
return view('index', compact('complaints'));
}
Blade:
@extends('layout')
@section('title','Welcome')
@section('content')
{{-- @foreach ($complaints as $complaint)
<h1>{{ $complaint->title }}</h1>
<p>{{ $complaint->body }}</p>
@endforeach --}}
{{ $complaints }}
@endsection
You are not routing to the correct function in your controller. Try this
Route::resource('complaints', 'ComplaintController@index');