Denis Saidov Denis Saidov - 1 year ago 52
PHP Question

new controller creation Laravel

So while learning Laravel 5, I've experienced the following problem.

I've created the new controller named ContactController in the folder:


and I have the following code in it:


namespace App\Http\Controllers\Pages;

use App\Http\Controllers\Controller;

class ContactController extends Controller {

public function index() {
return 'This is the Contact page.';

public function getMyDetails() {
return 'This is the My Details page.';

and I also added the following code into my web routes:


Route::resource('contact', 'Pages\ContactController');

According to what I understood, it should automatically show me the message "This is the My Details page." when I open the URL address: Instead I get the error:

BadMethodCallException in compiled.php line 6271:
Method controller does not exist.

Answer Source

Resource controllers do not work like that. Route::resource will create 7 CRUD routes for you: index, show, create, store, edit, update, delete

If you want to add my-details route, add this to routes.php:

Route::get('contact/my-details', 'Pages\ContactController@getMyDetails');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download