I'm working on a photography website at the moment and am having trouble with the page that should show all the albums and pictures within the album. I always get an error
Class 'Photo' not found (View: /var/www/photography.website/resources/views/album/index.blade.php)
when trying to access the page.
Following are the view, controllers, and models;
Index View:
@extends('layout.main')
@section('title')
<title>Albums</title>
@endsection
@section('content')
<div class="content">
@if(count($albums)==0)
<p>Nothing here yet, come back later!</p>
@else
@foreach($albums as $album)
<div class="album">
<h3>{{$album->name}}</h3>
@foreach($album->photos()->getEager() as $photo)
<img src="/public/thumb-{{$photo->id->toString()}}.jpeg" class="">
@endforeach
</div>
</div>
@endforeach
@endif
@endsection
Album Controller (snippet):
<?php
namespace App\Http\Controllers;
use App\Photo;
use App\Album;
use Illuminate\Http\Request;
class AlbumController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$albums = Album::all();
return view('album.index')->with(compact($albums));
}
}
Album Model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Album extends Model
{
protected $fillable = ['name','cover'];
public function photos() {
return $this->hasMany('Photo');
}
}
Photo Model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Photo extends Model
{
public $incrementing = false;
protected $fillable = ['id','album_id','title'];
}