Instead of:
Route::controller('/', 'FrontendController');
Do this:
Route::controller('', 'FrontendController');
In the documentation there is no indication of the slash within the parameter in the prefix (at the beginning of the string), so if root should be empty.
Also note that you can not use uppercase letters in the methods except for the first letter, or change this (because in Laravel it's all case-sensitive):
-
public function getTrabalheConosco(){
and public function getQuemSomos(){
For this reason:
-
public function getTrabalheconosco(){
and public function getQuemsomos(){
I tested it on Laravel5 and it worked with both slash /
and no, if the problem still exists it might be that you are not using the public
folder as root
as you did in the other answer.
The situation of redirecting requests with .htaccess to public
even works, but since Laravel was not a project to run so maybe this is a side effect.
Note that if you are in a development environment you may prefer to use server.php
which is a script to be run as stand-alone php server .
The command line to run it is this:
php -S localhost:8000 server.php
The server will be accessible on port 8000, you can easily change it, but note that port 80 may sometimes be in use (as in Apache already pre-installed on some Linux-based or Windows-based distros sometimes by IIS or Skype).
If you are using Windows to make it easier, you can create a .bat
(and the php path is not in the environment variable PATH
) in your project:
@echo off
set PHP_BIN="C:\wamp\php\php.exe"
set PHP_INI="C:\wamp\php\php.ini"
%PHP_BIN% -S localhost:8000 -c %PHP_INI% server.php
Run it and to end the server just click on Ctrl + C on the open CMD screen (or simply click close).
Note also that to simulate the test I have two files, one called Controller.php and one called HomeController.php, the second extends from Controller.php and not from BaseController.php, like this:
-
Controller.php
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
abstract class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
-
HomeController.php
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
class HomeController extends Controller
{
# Contato
public function getContato(){
return ('frontend.contato');
}
# Trabalhe Conosco
public function getTrabalheconosco(){
return ('frontend.trabalhe');
}
# Serviços
public function getServicos(){
return ('frontend.servicos');
}
# Quem Somos
public function getQuemsomos(){
return ('frontend.agencia');
}
}
-
routes.php:
<?php
Route::get('/', function () {
return view('welcome');
});
Route::controller('', 'HomeController');