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:
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:
Type in the PHP terminal Artisan route:list check if the route appeared
– novic
Thanks @novic, I updated my question with the result of the PHP Artisan route:list command, can help me discover the error?
– Jean Carlos Galhardi
I found the solution, just change the route to Route::get('/products/new', 'App Http Controllers Products');
– Jean Carlos Galhardi