SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'null' for column 'firm_id' at row 1
(SQL: update `tdauction` set `status` = 0, `firm_id` = null where `idauction` = 4025)
<tr>
<td>Выигравшая фирма</td>
<td>
<select class="form-control" name="firm_id" id="firm_id" >
@foreach($firms as $firm)
<option @if($auction->firm_id == $firm->id) {{'selected'}} @endif
value="{{$firm->id}}" >{{$firm->name}}</option>
@endforeach
<option @if( is_null($auction->firm_id)) {{'selected'}} @endif value="null" ></option>
</select>
</td>
</tr>
public function postEditWinAuction(Request $request){
if (isset($_POST['idauction'])) {
$idauction = $_POST['idauction'];
} else {
return null;
}
$value =
[
'idauction' => $idauction,
'protokol' => $_POST['protokol'],
'kontrakt' => $_POST['kontrakt'],
'firm_id' => $_POST['firm_id'],
'status' => $_POST['status']
];
return $id = \App\Auction::editWinAuction($value);
}
public static function editWinAuction($value){
if(is_null($value['idauction'])){
return null;
}
else{
$auction = self::find($value['idauction']);
}
//Сделал пока так что бы не выходила ошибка
if ($value['firm_id']== 'null'){
$firm_id = null;
}
else{
$firm_id = $value['firm_id'];
}
$auction->protokol = $value['protokol'];
$auction->kontrakt = $value['kontrakt'];
$auction->firm_id = $firm_id;
$auction->status = $value['status'];
$auction->save();
$id_name = $auction->primaryKey;
return $id = $auction->$id_name;
}
$auction->firm_id = $value['firm_id'] === 'null' ? null : $value['firm_id'];
public function postEditWinAuction(Request $request){
$this->validate($request, [
'idauction' => 'required|integer', // Если должен быть обязательным
// Тут условия для остальных полей
]);
$values = $request->only([
'protokol',
'kontrakt',
'firm_id',
'status',
]);
return Auction::find($request->idauction)->update($values);
}
class Auction extends Model
{
protected $fillable = [
'protokol',
'kontrakt',
'firm_id',
'status',
];
}
Schema::create('auctions', function($table)
{
$table->increments('id');
$table->string('firm_id')->nullable();
});