Я проверил атрибуты, и все они соответствуют правильно. Я использовал этот метод обновления данных в другом контроллере, и он отлично работает. Очень странно, что только этот набор данных не обновляется при запуске кода. Кроме того, нет никаких ошибок, поэтому я точно не знаю, как их устранить.
Код в "HawkerInfoController":
public function update(Request $request)
{
$request->validate([
'fname' => ['required'],
'fid' => ['required'],
'job' => ['required'],
'marital' => ['required'],
'income' => ['required'],
]);
$hawkerAdd = HawkerAdd::find(Auth::user()->user_id);
$hawkerAdd->hawker_id = Auth::user()->user_id;
$hawkerAdd->job = $request->input('job');
$hawkerAdd->marital = $request->input('marital');
$hawkerAdd->income = $request->input('income');
$hawkerAdd->picture = $request->input('picture');
$hawkerAdd->utility_bil = $request->input('bil');
$hawkerAdd->ty2_inject = $request->input('inject');
$hawkerAdd->father_name = $request->input('fname');
$hawkerAdd->father_id = $request->input('fid');
$hawkerAdd->save();
return redirect()->route('hawkerInfo.index')->with('success',"Additional Information has been updated");
}
Код в "hawker_info.blade":
<form method="POST" action="{{ route('hawkerInfo.update',Auth::user()->user_id) }}">
@csrf
@method('PUT')
<div class="form-group mb-4">
<strong><label for="fname">Father's Name</label></strong>
<input type="text" class="form-control" id="fname" name="fname" value="{{$hawkeradd->father_name}}" placeholder="Name" readonly>
</div>
<div class="form-group mb-4">
<strong><label for="fid">Father's Identification Card</label></strong>
<input type="text" class="form-control" id="fid" name="fid" value="{{$hawkeradd->father_id}}" placeholder="Identification Card" readonly>
</div>
<div class="form-group mb-4">
<strong><label for="job">Occupation</label></strong>
<input type="text" class="form-control" id="job" name="job" value="{{$hawkeradd->job}}" placeholder="Your Occupation">
</div>
<div class="form-group mb-4">
<strong><label>Marital Status</label><br></strong>
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" id="marit1" name="marital" class="custom-control-input" value="Single" {{$hawkeradd->marital == 'Single' ? 'checked' : '' }}>
<label class="custom-control-label" for="marit1">Single</label>
</div>
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" id="marit2" name="marital" class="custom-control-input" value="Married" {{$hawkeradd->marital == 'Married' ? 'checked' : '' }}>
<label class="custom-control-label" for="marit2">Married</label>
</div>
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" id="marit3" name="marital" class="custom-control-input" value="Divorced" {{$hawkeradd->marital == 'Divorced' ? 'checked' : '' }}>
<label class="custom-control-label" for="marit3">Divorced</label>
</div>
<div class="custom-control custom-radio custom-control-inline">
<input type="radio" id="marit4" name="marital" class="custom-control-input" value="Widow" {{$hawkeradd->marital == 'Widow' ? 'checked' : '' }}>
<label class="custom-control-label" for="marit4">Widow</label>
</div>
</div>
<div class="form-group mb-4">
<strong><label for="income">Household Income</label></strong>
<select id="income" name="income" class="form-control" readonly>
<option value="Below 1,500" {{$hawkeradd->income == 'Below 1,500' ? 'selected' : '' }} {{$hawker->income != 'Below 1,500' ? 'disabled' : '' }}>Below 1,500</option>
<option value="1501 - 2500" {{$hawkeradd->income == '1501 - 2500' ? 'selected' : '' }} {{$hawker->income != '1501 - 2500' ? 'disabled' : '' }}>1501 - 2500</option>
<option value="2501 - 3500" {{$hawkeradd->income == '2501 - 3500' ? 'selected' : '' }} {{$hawker->income != '2501 - 3500' ? 'disabled' : '' }}>2501 - 3500</option>
<option value="Above 3,501" {{$hawkeradd->income == 'Above 3,501' ? 'selected' : '' }} {{$hawker->income != 'Above 3,501' ? 'disabled' : '' }}>Above 3,501</option>
</select>
</div>
<button type="submit" class="btn btn-primary pull-right">Update</button>
</form>
Структура таблицы:
Schema::create('hawker_adds', function (Blueprint $table) {
$table->string('hawker_id', 12);
$table->string('job', 100);
$table->string('marital', 20);
$table->string('income', 20);
$table->string('picture', 50)->nullable();
$table->string('utility_bil', 50)->nullable();
$table->string('ty2_inject', 50)->nullable();
$table->string('father_name', 100);
$table->string('father_id', 12);
$table->primary('hawker_id');
$table->foreign('hawker_id')->references('hawker_id')->on('hawkers')->onDelete('cascade')->onUpdate('cascade');
});
HawkerAdd Модель:
protected $primaryKey = "hawker_id";
public $incrementing = false;
protected $keyType = 'string';
public $timestamps = false;
protected $fillable = [
'picture', 'job', 'marital', 'income', 'utility_bil', 'ty2_inject', 'father_name', 'father_id',
];