首页 > 解决方案 > 带有 Livewire 的 Laravel 待办事项列表

问题描述

我需要一些帮助。我最近开始了一个测试项目,用 Laravel Livewire 制作一个基本的待办事项列表。一切都很好,但最后我有编辑功能我在删除未定义偏移量的 Todo 中的步骤时遇到错误:0 突出显示此特定代码行:$step=$this->steps[$index];。下面是代码

public function remove($index)
{
  $step=$this->steps[$index];
  if(isset($step['id']))
  {
    Step::find($step['id'])->delete();
  } 
  unset($this->steps[$index]);
}

$index 值由edit-step.blade.php 文件传递​​,如下所示:

@foreach ($steps as $step)
    <div class="form-group row" wire:key={{ $loop->index }}>

        <div class="col-lg-11">
            <input type="text" class="form-control" placeholder="Describe Step {{ $loop->index+1 }}" style="margin-bottom:2px;" name="stepName[]" value="{{ $step['name'] }}"/>
            <input type="hidden" name="stepId[]" value="{{ $step['id'] }}"/>
        </div>
        
        <span class="fa fa-times col-md text-md-left" style="color:red; cursor: pointer; margin-top:10px;" wire:click="remove({{ $loop->index }})"></span>

    </div>

你能帮我解决我哪里出错了。

标签: phplaravel

解决方案


对不起,我还不能评论!您正在传递$loop->indexremove函数而不是$step['id'].


推荐阅读