0
Good afternoon guys, I’m trying to do an update but the values entered in the fields not saved in the database, follow files to check.
Index.blade.php
@extends('layouts.app')
@section('content')
<?php
if (session('message')):?>
<div class="alert alert-success" style=" opacity: 1;">
{{ session('message') }}
</div>
<?php
else:?>
<?php
endif;
?>
<div class="col-sm-12">
<div class="card">
<div class="card-header">
</div>
<div class="card-block">
<div class="dt-responsive table-responsive">
<a href="{{route('Aulas.create')}}" class="btn btn-primary ">Cadastrar uma nova aula </a>
<p> </p>
<table id="simpletable" class="table table-striped table-bordered nowrap">
<thead>
<tr>
<th style="text-align: center;">Ritmo</th>
<th style="text-align: center;">Dia da Semana</th>
<th style="text-align: center;">Horário</th>
<th style="text-align: center;">Status</th>
<th style="text-align: center;">Alterar</th>
<th style="text-align: center;">Excluir</th>
</tr>
</thead>
<tbody>
<?php
$RowsCount = $Aulas->count();
if($RowsCount >= 0 ):
foreach($Aulas as $models):
?>
<tr>
<td style=""><?php echo $models['Ritmo']; ?></td>
<td style="text-align: center;"><?php echo $models['DiaSemana']; ?></td>
<td style="text-align: center;"><?php echo $models['Horario']; ?></td>
<td style="text-align: center;"><?php echo $models['Status']; ?></td>
<td style="text-align: center;">
<a class="btn btn-primary btn-outline-primary btn-icon" href="{{route('Aulas.edit', $models->Id)}}">A</a>
</td>
<td style="text-align: center;">
<form method="POST" action="{{ route('Aulas.destroy', $models->Id) }}">
@csrf
@method('DELETE')
<button type="submit" name="btn-deletar" class="btn btn-warning btn-outline-warning btn-icon" data-type="success" data-from="top" data-align="right">E</button>
</form>
</td>
</tr>
<?php
endforeach;
else: ?>
<tr>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
<?php
endif;
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
@stop
route/web
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::group(['middleware' => 'web'], function () {
Route::get('/home', 'HomeController@index')->name('home');
Route::get('/ListAula', 'CadastrosBasicos\AulasController@Index')->name('aulas');
Route::get('/CadAula', 'CadastrosBasicos\AulasController@create')->name('create');
Route::get('/edit', 'CadastrosBasicos\AulasController@edit')->name('edit');
Route::post('/store', 'CadastrosBasicos\AulasController@store')->name('store');
Route::post('/update', 'CadastrosBasicos\AulasController@update')->name('update');
Route::resource('Aulas','CadastrosBasicos\AulasController');
});
Controller
<?php
namespace App\Http\Controllers\CadastrosBasicos;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use App\Models\CadastrosBasicos\Aulas;
use Illuminate\Routing\Controller;
use Illuminate\Http\Request;
class AulasController extends Controller
{
public function edit(Request $request, $Id )
{
$Aula = Aulas::find($Id);
return view('CadastrosBasicos.Aulas.Editar', compact('Aula'));
}
public function update(Request $request, $Id)
{
$AulaDb = Aulas::find($Id);
$AulaDb->Id = $Id;
$AulaDb->Ritmo = $request->get('Ritmo');
$AulaDb->DiaSemana = $request->get('DiaSemana');
$AulaDb->Horario = $request->get('Horario');
$AulaDb->Status = $request->get('Status');
$AulaDb->save();
return redirect() ->route('aulas')
->with('message', 'Aula Alterada com sucesso!');
}
}
Molds
<?php
namespace App\Models\CadastrosBasicos;
use Illuminate\Database\Eloquent\Model;
class Aulas extends Model
{
protected $table = 'Aulas';
public $timestamps = false;
protected $fillable = ['Id','Ritmo','Horario','DiaSemana','Status'];
}
Failed to put the form you are using to update.
– Bulfaitelo
its routes have no pattern, and bad if the project is growing, the names should also follow a nomenclature, all this is good not to have shock routes.
– novic