内部错误未定义索引

时间:2017-11-02 08:07:19

标签: angularjs laravel

我收到内部错误

in AdminController.php line 85
at HandleExceptions->handleError('8', 'Undefined index: name', 'C:\wamp64\www\laravel\dev.oasis-portal.my\app\Http\Controllers\AdminController.php', '85', array('data' => array())) in AdminController.php line 85

当我跑

public function courseDelete()
  {
    $data = Input::all();

    $student = Course::where('name', '=', $data["name"]);

    if($student->delete()) {

      User::find($data["name"])->delete();

      return json_encode(array('success' => true));

    } else {

      return json_encode(array('success' => false, 'errors' => "Unable to remove student."));
    }
  }

我的路线是:Route :: get('/ course / delete /','AdminController @ courseDelete');

1 个答案:

答案 0 :(得分:0)

$data["name"]未设置,因此抛出异常。更好的解决方案是使用request()简写:

获取参数

即。 request()->get('name'); //will return null if not set