Target class [Productoscontroller] does not exist

Asked

Viewed 890 times

0

I’m new to PHP and Laravel and I’m caught in an error when I try to load the page. The following error appears: inserir a descrição da imagem aqui

Model:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Produto extends Model
{
    protected $fillable = ['nome', 'custo', 'preco', 'quantidade'];
    use HasFactory;
}

Controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ProdutosController extends Controller
{
    public function create()
    {
        return view('produtos.create');
    }

}

View (create.blade.php):

<!DOCTYPE html>
<html lang="pt-br">
<head>
    <title>Cadastrar um novo produto</title>
</head>

<body>
    <form action="">
        <label for="">Nome</label> <br />
        <input type="text" name="nome"> <br />
        <label for="">Custo</label> <br />
        <input type="text" name="custo"> <br />
        <label for="">Preço</label> <br />
        <input type="text" name="preco"> <br />
        <label for="">Quantidade</label> <br />
        <input type="text" name="quantidade"> <br />
        <button>Salvar</button>
    </form>
</body>
</html>

Router:

<?php

use Illuminate\Support\Facades\Route;

Route::get('/', function () {
return view('welcome');
});

Route::get('/produtos/novo', 'ProdutosController@create');

I typed the command PHP artisan route:list and the following message appeared:

inserir a descrição da imagem aqui

  • 1

    Type in the PHP terminal Artisan route:list check if the route appeared

  • Thanks @novic, I updated my question with the result of the PHP Artisan route:list command, can help me discover the error?

  • I found the solution, just change the route to Route::get('/products/new', 'App Http Controllers Products');

1 answer

1


Solution

I changed the Router for:

<?php

use Illuminate\Support\Facades\Route;

Route::get('/', function () {
return view('welcome');
});

Route::get('/produtos/novo', 'App\Http\Controllers\ProdutosController@create');
  • 1

    Good morning. The correct one was that the default namespace was set to not enter the full controller path.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.