Start to learn here.
It's free.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello guys. I have a table with2 foreign keys and I want to be able to update data thru a form. So far I got in my view:
<form action="{{url('formInfo.edit/'.$testInfo->ID) }}" method="POST" style="display: grid">
@method('PUT')
@csrf
<input type="text" name="Name" value="{{ old('NAME') ?? $testInfo->NAME}}" placeholder="Name" class="form-control" style="margin-bottom: 8px">
<input type="text" name="Time" value="{{ old('TIME') ?? $testInfo->TIME}}" placeholder="Time" class="form-control" style="margin-bottom: 8px">
<select name='guys_id' class='form-control mt-2 mb-2'>
@foreach($guys as $guy)
<option value="{{ $guy->ID }}">{{ $guy->NAME}}</option>
@endforeach
</select>
<select name='LOCATION_ID' class='form-control mt-2 mb-2'>
@foreach($locations as $location)
<option value="{{ $location->id }}">{{ $location->Location_name}}</option>
@endforeach
</select>
<button type="submit" class="btn btn-primary">Post</button>
</form>
In my controller I have this update function:
public function update(Request $req, $id){
locations::all();
observer::all();
$ID = $req->ID;
$input = $req->all();
$testInfo = testInfo::find($id);
$testInfo->NAME = $input['Name'];;
$testInfo->TIME = $input['Time'];;
$testInfo->guys_ID = observer::where('ID','=',$req->guy_id)->get('ID');;
$testInfo->LOCATION_ID = locations::where('id','=',$req->LOCATION_ID)->get('id');;
$testInfo->save();
return redirect()->route('testInfo');
}
in my Model:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class testInfo extends Model
{
protected $table = "infotest";
public $timestamps = false;
protected $fillable=['ID','NAME','TIME', 'guys_ID', 'LOCATION_ID'];
}
And in my routes:
Route::put('formInfo.edit/{ID}', 'App\Http\Controllers\testInfoController@update');
My issue is that when I submit the form I get redirected to the correct page and get 302 Found in my network panel but table is not updated.
Please or to participate in this conversation.