Answer the question
In order to leave comments, you need to log in
Why doesn't laravel see a function in the controller?
There is a controller BookController
In which the following functions are
index(),create(),store(),show(),edit(),update(),destroy().
All of these functions work except for the test() function. I don't understand where the error could be.
Here is the entire code of my BookController controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class BookController extends Controller
{
public function index()
{
$allBooks = Book::all();
return view('books.booklist', compact('allBooks'));
}
public function create()
{
return view('books.addbook');
}
public function store(Requests\PublishBookRequest $requestData)
{
$book = new Book;
$book->title = $requestData['title'];
$book->description = $requestData['description'];
$book->author = $requestData['author'];
$book->save();
return redirect()->route('book.index');
}
public function show($id)
{
$book = Book::find($id);
return view('books.showbook')->with('book', $book);
}
public function edit($id)
{
$book = Book::find($id);
return view('books.editbook')->with('book', $book);
}
public function test(){
return 'hello!';
}
public function update($id, PublishBookRequest $requestData)
{
$book->title = $requestData['title'];
$book->description = $requestData['description'];
$book->author = $requestData['author'];
$book->save();
return redirect()->route('book.index');
}
public function destroy($id)
{
Book::find($id)->delete();
return redirect()->route('book.index');
}
}
Route::resource('book', 'BookController');
Route::get('book', '[email protected]');
Route::get('book/create', '[email protected]');
Route::post('book', '[email protected]');
Route::get('book/{book}/edit', '[email protected]');
Route::put('book/{book}', '[email protected]');
Route::delete('book/{book}', '[email protected]');
Route::get('book/test', '[email protected]');
Answer the question
In order to leave comments, you need to log in
Route::get('book/test', '[email protected]');
This must be specified before the resource, because the url 'book/test' falls under the get('book/{book}') rule.
Route::get('book', '[email protected]');
Route::get('book/create', '[email protected]');
Route::post('book', '[email protected]');
Route::get('book/{book}/edit', '[email protected]');
Route::put('book/{book}', '[email protected]');
Route::delete('book/{book}', '[email protected]');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question