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:
app/Http/Controllers/ContactController.php
<?php
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:
routes/web.php
Route::controller('contact', 'Pages\ContactController');
Strangely, when I access the /contact URL -> http://laravel.devpeaks.com/public/contact, I get:
BadMethodCallException in compiled.php line 6271: Method controller does not exist.
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.Route::controller()
was deprecated in 5.2 and was removed in 5.3. Try this route instead:
Route::resource('contact', 'Pages\ContactController');
Then run php artisan route:list
command to make sure all routes exists.
Also, you should fix web server settings by pointing it to public
directory instead of Laravel project root. After doing this use normal URLs like domain.com/contact
.