php - 如何解决未定义的变量
问题描述
查看页面:
@if(count($applications)>0)
<table class= "table table-striped">
<tr>
<th>Email</th>
<th>Date Applied</th>
<th>Leave Type</th>
<th>Leave Status</th>
<th></th>
</tr>
@foreach($applications as $application )
<tr>
<td>{{$application ->user->email}}</td>
<td>{{$application ->dateApplied}}</td>
<td>{{$application ->leaveType}}</td>
<td>{{$application ->leaveStatus}}</td>
<td>
{!!Form::open(['action'=>['ApplicationAdminController@destroy', $application ->appId], 'method'=>'DELETE'])!!}
{{Form::hidden('_method', 'DELETE')}}
{{Form::submit('Delete', ['class' => 'btn btn-danger'])}}
{!!Form::close()!!}
</td>
</tr>
@endforeach
</table>
控制器:
public function destroy($appId)
{
$application = Application::find( $appId);
$application ->delete();
$this->deleteLeave($appId);
return redirect('/applicationAdminHistory')->with ('success', 'Application Removed');
}
public function deleteLeave($appId){
$user_id = Auth::id();
$req = DB::table('leave_summaries')
->where('user_id',$user_id)
->increment($leaveType,$day);
}
我想要做的是当单击删除按钮时,应用程序将被删除,并将在 leave_summaries 表中进行增量。leave_summaries 的增量基于已删除的应用程序中的日期和休假类型的值。运行此代码后,出现未定义变量错误,如下所示:
解决方案
您没有定义这三个变量:$user_id、$leaveType、$day
您需要将这些值作为参数传递给 deleteLeave() 方法,或者必须在调用方法之前定义这些值。
public function deleteLeave($user_id, $leaveType, $day){
$req = DB::table('leave_summaries')
->where('user_id',$user_id)
->increment($leaveType, $day);
}
推荐阅读
- javascript - 更改布尔属性时不更新子级
- git - 删除分支中间的提交
- kubernetes - 是否有一种设计模式可以定期更新 kubernetes 中的数据库而不会出现不一致?
- java - 为什么我的按钮在点击后没有变化?
- android - 如何使使用本地存储的 webview 应用在 Google Play 中不被禁止?
- javascript - vuex(javascript)中的方括号后跟括号表达式
- angular - 创建“一次发射”可观察对象
- java - Spring Data Couchbase - 获取 java.lang.ArrayIndexOutOfBoundsException:分页查询的索引 1 超出长度 1 的范围
- kubernetes - kubernetes:无法加载现有证书 apiserver-etcd-client:
- windows-10 - 有没有办法离线更新多个笔记本电脑上的 Windows 10?