Php 我得到了那个错误;从空值“创建默认对象”;。有人能帮我吗?
这是我的刀。添加产品正在工作,但我在更新页面上遇到错误Php 我得到了那个错误;从空值“创建默认对象”;。有人能帮我吗?,php,laravel,Php,Laravel,这是我的刀。添加产品正在工作,但我在更新页面上遇到错误 @extends('base') @section('form') <div class="col-md-12"> <h2>Ürün Düzenle</h2> <div align="right"> <a href="{{route('urunler')}}"> <button class="btn btn-succe
@extends('base')
@section('form')
<div class="col-md-12">
<h2>Ürün Düzenle</h2>
<div align="right">
<a href="{{route('urunler')}}">
<button class="btn btn-success">Geri</button>
</a>
<br> <br>
</div>
<form action="{{route('arabaduzenlepost',['id'=>$products ?? 'id'])}}" method="POST">
@csrf
<select name="category_id">
<option selected="" value="default">Lütfen Kategori Seçiniz</option>
<option value="1">Sedan</option>
<option value="2">Hatchback</option>
<option value="3">Station Wagon</option>
</select>
</select>
<input name="adi" type="text" value="{{ $products ?? 'name' }}" >
<input name="renk" id="renk" type="text" value="{{ $products ?? 'color' }}">
<input name="km" type="text" value="{{ $products ?? 'km' }}">
<input name="fiyat" id="fiyat" type="text" value="{{ $products ?? 'price' }}">
<button type="submit" class="btn btn--lg btn--alt-color" style="float:right;">DÜZENLE
</button>
</form>
</div>
</div>
这是我的数据库
Schema::create('products', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('color');
$table->string('km');
$table->string('price');
$table->unsignedBigInteger('category_id');
$table->foreign('category_id')->references('id')->on('categories');
$table->timestamps();
更新你的刀片文件
@extends('base'))
@节(“表格”)
Ürün Düzenle
@csrf
吕特芬·卡泰戈里·塞西宁
轿车
掀背式汽车
旅行车
德泽勒
在php中,?
表示空合并
参考链接
@csrf
把这个换成
<form action="{{route('arabaduzenlepost',$products->id)}}"method="post">
{{method_field('PUT')}}
{{csrf_field()}}
{{method_字段('PUT')}
{{csrf_field()}}
我更新了blade,但现在我得到一个错误“undefined variable:products”,然后定义它
<form action="{{route('arabaduzenlepost',['id'=>$products ?? 'id'])}}" method="POST">
@csrf
<form action="{{route('arabaduzenlepost',$products->id)}}"method="post">
{{method_field('PUT')}}
{{csrf_field()}}