未定义的变量问题Laravel 5.4

jec*_*360 0 php laravel laravel-5.4

我一直坚持这个错误,所以如果有的话请原谅我,因为我还是在laravel的新人.我收到了这个错误

未定义的变量:clientTransactions(查看:C:\ xampp\htdocs\dcgwapo\resources\views\service_details\create.blade.php)

但我有一个正确的代码,但我仍然想知道为什么它仍然是未定义的变量,因为我在我的控制器中定义它.

服务详细信息代码中的create.blade.php

<div class="form-group">
    <label for="client_transaction_id">Client Trans ID: </label>
    <select class="form-control" name="client_transaction_id">
        @foreach ($clientTransactions as $clientTransaction)
            <option value= "{{ $clientTransaction->id }}">
              {{ $clientTransaction->id }}
            </option>
        @endforeach
    </select>
  </div>
Run Code Online (Sandbox Code Playgroud)

ServiceDetailsController代码

public function create()
{
    $users = User::pluck('fname', 'lname', 'id');
    $services = Service::pluck('name', 'id');
    $clientTransactions = ClientTransaction::all();
    return view('service_details.create', ['users' => User::all()], ['services' => Service::all()], ['clientTransactions' => ClientTransaction::all()]);
}
Run Code Online (Sandbox Code Playgroud)

ServiceDetail.php模型代码

public function clientTransaction()
{
  return $this->belongsTo(ClientTransaction::class);
}
Run Code Online (Sandbox Code Playgroud)

我希望你能帮助我.谢谢!

Mar*_*lln 6

您以错误的方式向视图发送变量.seconds参数应该是包含所有变量的数组.截至目前,您view为每个变量的函数添加了一个新参数.

view('view', [...], [...], [...])

它应该是这样的:

view('view', [...1, ...2, ...3])

所以你需要改变的是对此的return语句:

return view('service_details.create', ['users' => User::all(), 'services' => Service::all(), 'clientTransactions' => ClientTransaction::all()]);
Run Code Online (Sandbox Code Playgroud)