他试图使用Eloquent ORM一对一地将数据保存到db中,但是它没有保存并且没有显示任何错误来修复它(由于没有显示任何错误,所以无法找到任何解决方案),
public function store(Request $request)
{
$request->validate([
'owner_id' => 'required',
'phone_name' => 'required|unique:phones'
]);
$phone = new Phone;
$phone->owner_id = $request->owner_id;
$phone->phone_name = $request->phone_name;
$phone->save();
return redirect()->route('phone.index')->with('flash_messages_success', 'Phone has been added successfully');
}
protected $fillable = [
'pphone_name', 'owner_id'
];
public function owner()
{
return $this->belongsTo('App\Owner');
}
<form method="POST" action="{{ route('phone.store') }}">
@csrf
<div class="form-group">
<label for="">Phone Title</label>
<input type="text" name="phone_name" class="form-control" id="" placeholder="Phone Name">
</div>
<div class="form-group">
<label>Select Owner</label>
<select class="form-control" name="category_id">
<option selected="">Under Owner</option>
@foreach($owners as $owner)
<option value="{{ $owner->id }}">{{ $owner->owner_name }}</option>
@endforeach
</select>
</div>
<input type="submit" name="submit" class="btn btn-primary" value="submit">
</form>
答案 0 :(得分:0)
您选择名称为category_id的选择名称中的问题,因此视图应为:
<select class="form-control" name="owner_id">