Denis Saidov Denis Saidov - 1 year ago 109
PHP Question

new controller mistake Laravel

I was testing out while learning Laravel 5, creating a new controller, but I do get a strange error, when it is supposed to work fine. Here it is:

I created a new folder Pages in the app/Http/Controllers/ directory, and added the controller ContactController into it:



namespace App\Http\Controllers\Pages;

use App\Http\Controllers\Controller;

class ContactController extends Controller {

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

and then I created a route in the routes/web file:


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

Strangely, when I access the /contact URL ->, I get:

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

Answer Source
  1. You should adjust your nginx/apache config in a way that root directory is pointed to /public.
  2. Route::controller is deprecated since Laravel-5.2. You should use Route::resource and name rename the method from getIndex to index. If you use Laravel-5.1 implement the first point only.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download