0
Hello guys I’m starting with the Standard, I’ve come across a problem. I created the controller, the routes, but even so, it’s giving me the following error:
Class App Http Controllers Contact2controller does not exist.
What should I do, guys? I already searched the net, but without success. Thanks.
For better understanding, the following is 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 the Standard.
Nor is it a Laravel pattern problem, PHP does not actually recognize points in class names, functions and namespaces. This actually emits something like
Parse error: syntax error, unexpected '.', expecting '{'
.– Guilherme Nascimento
@Guilhermenascimento was about to comment, the strange thing is that in the question itself this is not part of the problem.
– Edilson
@Edilson probably the user is or Laravel issued that custom error without details (maybe AP accidentally turned off debug mode)
– Guilherme Nascimento
But to display the syntax errors cited above the file in question should be executed. Probably the file name does not match the class name.
– Juven_v
Okay guys! I took all the tips given, created another controller (contact3Controller), copied the code from the previous controller and pasted it into this one. That error disappeared, and another one came up: Fatalerrorexception in contact3Controller.php line 24: Class 'Http Controllers App Contact' not found This error occurs when I try to record something in the bd.
– Daniel dos Santos
You did not create a class called Contact, in the model folder of the Laravel and did not import this class in the Contact3controller controller. Take a look in this and in this start guide.
– Juven_v
Thank you very much @Juven. I actually had already created the class, I just needed to care about it in the controller. That ended and it worked, it’s working. Thanks!
– Daniel dos Santos