Can not find the php controller with laravel [closed]

0

Hello everyone, I'm starting with laravel, I've come across a problem. I created the controller, the routes, but still, it is giving me the following error:

Class App \ Http \ Controllers \ Contact 2Controller does not exist.

What should I do? I already searched the net, but to no avail. Thanks in advance.

For a better understanding, here's the code.

Controller:

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class Contato2Controller.php extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('welcome');
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function enviar(Request $request)
    {
        $contato = new Contato();
        $contato->nome = $request->get('nome');
        $contato->email = $request->get('email');
        $contato->mensagem = $request->get('mensagem');
        $contato->save();

        echo "Dados armazenados com sucesso! Código: " .$contato->id;
    }

    public function lista()
    {
        return view('lista', array('contatos'=>Contatos::all()));
    }
}

Routes:

Route::get('/','Contato2Controller@index');
Route::post('/enviar','Contato2Controller@enviar');
Route::get('/lista','Contato2Controller@lista');

OBS: I'm using version 5.1 of laravel.

    
asked by anonymous 15.04.2017 / 22:01

1 answer

1

Assuming that the routes are correct and the name nomenclature conforms to laravel standards, the problem should be here:

class Contato2Controller.php extends Controller
{
...

There is one .php left, so there really is no Contact2Controller controller (there is only Contact2Controller.php). So solving it goes something like this:

class Contato2Controller extends Controller
    {
    ...

laravel has a command-line tool for automatic generation of both the controller and the route, called artisan . .

    
15.04.2017 / 22:36