Class 'Album' not found

hatim ahadri

I have a problem in my controller(AlbumController) , I want to use one of my model(Album) in this controller but I got the error Class 'Album' not found AlbumController.php :

<?php
namespace App\Http\Controllers;
use Illuminate\Routing\Controller as BaseController;

class AlbumController extends BaseController
{
public function getList()
{
$albums =  \Album::find(1);
return View::make('index')
->with('albums' , $albums);
}
}

Model : Album.php (App/Models/Album)

<?php
namespace App\Models\Album;
class Album extends Model
{
protected $table = 'albums' ;
protected $fillable = ['name' , 'description' , 'cover_image'] ;
public function Photos()
{
return $this->hasMany('images');
}
}
?>
Imtiaz Pabel

you are getting this error for namespace mismatch.There is 2 way to solve one is use your namespace in top of class

namespace App\Http\Controllers;
use Illuminate\Routing\Controller as BaseController;
use App\Models\Album;
class AlbumController extends BaseController
{
public function getList()
{
  $albums =  Album::find(1);
  return View::make('index')
 ->with('albums' , $albums);
}
}

another is use full namespace in method

namespace App\Http\Controllers;
use Illuminate\Routing\Controller as BaseController;
class AlbumController extends BaseController
{
  public function getList()
  {
    $albums =  \App\Models\Album::find(1);
    return View::make('index')
    ->with('albums' , $albums);
  }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related