0
I’m creating a note control system, which basically contains 3 tables at the moment: Teachers, Materials and Activities. I am at the beginning of the project, in which I only made the teacher registration view.
However, when entering the record, the ID (which is hidden in the html) is not receiving value. It does not return any error. When giving Confirm, only a refresh occurs on the screen. I looked for tips on some videos and forums but nothing that helped. I’m using Pgadmin. Below is the Migration code, controller and routes.
HTML
@extends('cabecalho')
@extends('form')
@section('cont2')
<form action="{{url('professor')}}" method="post">
@csrf
<input type="hidden" name="idprofessor">
<label for="">Nome</label>
<br>
<input type="text" name="nome" id="nome" placeholder="Nome do professor">
<br><br>
<label for="nome">Sobrenome</label>
<br>
<input type="text" name="sobrenome" id="sobrenome" placeholder="Sobrenome do professor">
<br><br>
<label for="materia">Materia</label>
<br>
<input type="text" name="materia" id="materia" placeholder="Matéria">
<br><br>
<label for="numero">Número</label>
<br>
<input type="text" name="numero" id="numero" placeholder="(xx) x xxxx-xxxx" maxlength="12">
<br><br>
<label for="observacao">Observação</label>
<br>
<textarea name="observacao" id="observacao" cols="30" rows="10"></textarea>
<br>
<input type="submit" class="submit" value="Confirmar">
</form>
@stop
Migration
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateProfessoresTable extends Migration
{
public function up()
{
Schema::create('professores', function (Blueprint $table) {
$table->increments('id');
$table->string('nome',20);
$table->string('sobrenome',50);
$table->foreignId('materia_id',30);
$table->string('numero',11);
$table->longText('observacao');
});
}
public function down()
{
Schema::dropIfExists('professores');
}}
Controller
<?php
namespace App\Http\Controllers;
use App\Professor;
use Illuminate\Http\Request;
use Symfony\Component\Console\Input\Input;
use Illuminate\Database\Eloquent\Model;
class ProfessorController extends Controller
{
public function create()
{
return view('professor.cadastro-professor');
}
public function store(Request $request)
{
$this->validate($request, [
'idprofessor' => 'required',
'nome' => 'required',
'sobrenome' => 'required',
'materia' => 'required',
'telefone' => 'required'
]);
$professor = new Professor([
'idprofessor' => $request->get('idprofessor'),
'nome' => $request->get('nome'),
'sobrenome' => $request->get('sobrenome'),
'materia' => $request->get('materia'),
'telefone' => $request->get('telefone')
]);
$professor->save();
return view('professor.cadastro-professor');
}
Routes
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function() {
return view('inicio');
});
Route::resource('Professor', 'ProfessorController');
Route::get('/cadastros', 'Controller@list');
Route::get('/cadastros/cadastro-professor', 'ProfessorController@create');
Route::post('/professor', 'ProfessorController@store');
In short, my problem is with the ID that is not increasing. I thank you, and I also apologize if it is something gross.
Confirm that the request received in the controller has value, with
dd($request->get('idprofessor'))
. If yes, the problem must be in the teacher’s creation, where you assign the value of the$request->idprofessor
toidprofessor
, and in the database the field is calledid
– Lucas Pace