将数据从laravel控制器传递给Modal

时间:2017-02-16 21:15:13

标签: php laravel-5 bootstrap-modal laravel-blade

我想在Modal中编辑,但数据没有通过包含Modal的opgaveRet.blade.php :-(这是我的代码: 谁能帮我看看我做错了什么?

// route.php

Route::resource('/admin/opgave', 'Admin\OpgaveController');

// OpgaveController.php

 public function edit($id)
    {

    $tasks = Tasks::findOrFail($id);

       return view('admin.opgaver.opgaveRet', ['tasks' => $tasks ]);
    // also tried :-(:
    //return view('admin.opgave', compact('tasks'));
    }

// opgave.blade.php

@foreach ($opgaver as $opgave)
// here is a table, and then comes the Action
    <a href="{{ route('opgave.edit', $opgave->id) }}"
           data-toggle="modal"
           data-target="#RetOpgave"
           class="btn btn-primary btn-xs">Edit</a>
    @endforeach

//在opgave.blade.php的底部   // @include('admin.opgaver.opgaveRet')

<div class="modal fade" id="RetOpgave" tabindex="-1" role="dialog" aria-labelledby="RetOpgave">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
              <h4 class="modal-title" id="RetOpgave">Ret opgave</h4>
            </div>
            <div class="modal-body" >

              @if(!empty($tasks))

    // Here i want to build a FORM::
    // But there is nothing in $tasks  ???????


              {{ dd($tasks) }}
              @endif

            </div>
            <div class="modal-footer">
              <button type="button" class="btn btn-default" data-dismiss="modal">Luk</button>

            </div>
          </div>
        </div>
      </div>

1 个答案:

答案 0 :(得分:0)

您必须在AJAX中调用编辑功能。

这个可以帮到你: https://tutorials.kode-blog.com/laravel-5-ajax-tutorial