1
votes


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

I've created the new controller named ContactController in the folder:
app/Http/Controllers/Pages/ContactController.php
and I have the following code in it:

<?php

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:
routes/web.php

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: http://laravel.devpeaks.com/public/contact/my-details. Instead I get the error:
BadMethodCallException in compiled.php line 6271: Method controller does not exist.

1

1 Answers

2
votes

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');