1
votes

Laravel 5.1

//////////////////////////////////////////////////////

My Route://

Route::resource('/books', 'BookController@index');

////////////////////////////////////////////////////////

My BookController//

<?php

namespace App\Http\Controller;

use App\Book;

use App\Http\Requests;

use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

class BookController extends Controller {

   /**
    * Display a listing of the resource.
    *
    * @return Response
    */

public function index()

{

        $books=Book::all();

        return view('books.index',compact('books'));

    }

}

/////////////////////////////////////////////////////////

My Url:

http://localhost:8000/books

/////////////////////////////////////////////////////////

My Browser show this error//

Whoops, looks like something went wrong.

1/1 ReflectionException in C:\xampp\htdocs\bookstore\vendor\laravel\framework\src\Illuminate\Container\Container.php line 737:

Class App\Http\Controllers\BookController does not exist

2

2 Answers

0
votes

Notice the error says Class App\Http\Controllers\BookController does not exist. That doesn't match your namespace set in the BookController class.

It's looking for your class in the "App\Http\Controllers" location with an "s". Your namespace says "App\Http\Controller" (without the "s"). Fix your namespace and it should work.

0
votes

You are using a resourceful route and you don't need to specify the method.Also the / before the books is not needed. Your route should be like this:

Route::resource('books', 'BookController');