简体   繁体   English

如何解决未定义的变量

[英]How to solve undefined variable

view page:查看页面:

 @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>

controller: controller:

 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);

    }    

What I want to do is when click delete button the application will deleted and will do increments at the leave_summaries table.我想要做的是当单击删除按钮时,应用程序将被删除,并将在 leave_summaries 表中进行增量。 The increment at the leave_summaries based on the value of day and leave type in the application that has been deleted. leave_summaries 的增量基于已删除的应用程序中的日期和休假类型的值。 After i run this code i got undefined variable error as shown below:运行此代码后,出现未定义变量错误,如下所示:

运行此代码后的结果

In this Code Please Pass $user_id, $leaveType,$day:在此代码中请传递 $user_id、$leaveType、$day:

 public function deleteLeave($appId){


        $req = DB::table('leave_summaries')
        ->where('user_id',$user_id)
        ->increment($leaveType,$day);

        }   

You didn't defined these three variables: $user_id, $leaveType, $day你没有定义这三个变量:$user_id, $leaveType, $day

You need to pass these values as parameters into the deleteLeave() method or these values had to be defined before the method called.您需要将这些值作为参数传递给 deleteLeave() 方法,或者必须在调用方法之前定义这些值。

public function deleteLeave($user_id, $leaveType, $day){
    $req = DB::table('leave_summaries')
        ->where('user_id',$user_id)
        ->increment($leaveType, $day);
}   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM