获取未定义的索引:提交表单时的ID

时间:2017-07-25 13:50:27

标签: php api laravel-5.4 guzzlehttp

昨天我收到了这个错误,我以为我修好了。我正在提交更新表格。

@extends('layouts.master')

 @section('content')
  <form action="{{url('/student/update')}}" method="POST" role="form">
  {{ csrf_field() }}

{{method_field('PUT')}}
<legend>Create a Student</legend>
<input type="hidden" name="id" class="form-control" value="{{$student->id}}">
<div class="form-group">
  <label for="">Name</label>
  <input type="text" class="form-control" name="name" value="{{$student->name }}"required="required">
</div>
<div class="form-group">
  <label for="">Address</label>
  <input type="text" class="form-control" name="address" value="{{$student->address }}" required="required">
</div>
<div class="form-group">
  <label for="">Phone</label>
  <input type="text" class="form-control" name="phone" value="{{$student->phone }}" required="required">
</div>
<div class="form-group">
  <label for="">Career</label>
  <select name="career" class="form-control" required="required">
    <option>Select a Career</option>
    <option value="math"{{$student->career == 'math' ? 'selected' : ''}}>Math</option>
    <option value="physics"{{$student->career == 'physics' ? 'selected' : ''}}>Physics</option>
    <option value="engineering"{{$student->career == '' ? 'engineering' : ''}}>Engineering</option>
  </select>
</div>
<button type="submit" class="btn btn-primary">Update Student</button>
</form>

@endsection

错误表明它与第82行的ClientController有关。

protected function updateOneStudent($parameters)
{

  $studentId = $parameters['id'];
  return $this-
 >performPutRequest("https://lumenapi.juandmegon.com/students/{$studentId}", 
 $parameters);
    }

昨天给我的问题是同样的功能。问题是我没有调用函数。 performPutRequest函数是这样的。

protected function performPutRequest($url, $parameters = [])
{
  $contents = $this->performAuthorizeRequest('PUT', $url, $parameters);

  $decodedContents = json_decode($contents);

  return $decodedContents->data;
}

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

感谢初学者指出我正确的方向。我有下面的代码。

protected function updateOneStudent($parameters)
{

  $studentId = $parameters['id';
  return $this->performPutRequest("https://lumenapi.juandmegon.com/students/{$studentId}", $parameters);

}

我错过了id的支架。所以看起来应该是这样的

protected function updateOneStudent($parameters)
{

  $studentId = $parameters['id'];
  return $this->performPutRequest("https://lumenapi.juandmegon.com/students/{$studentId}", $parameters);

}