【问题标题】:Undefined offset: 0 (View: path\profile.blade.php) issue in laravelLaravel 中未定义的偏移量:0(查看:path\profile.blade.php)问题
【发布时间】:2021-05-13 00:58:34
【问题描述】:

当我单击表单提交按钮页面重定向到 addshortlist 功能。显示未定义偏移量的函数:0(查看:path\profile.blade.php)错误。在我的表格下方

<form action="addshortlist" id="addshortlist" method="PUT">
  {{ csrf_field() }}
 <input type="hidden" name="shortlistid" value="{{$data[0]->id}}">         
 <button type="submit" class="btn btn-primary">Add Shortlist</button>
</form>

我的路由函数是

Route::post('addshortlist','UserController@addshortlist');

功能类似于

function addshortlist()
    { 
       //
    }

【问题讨论】:

  • 你能dd($data)检查它是否是一个数组吗?
  • 是的,它只是数组
  • 您可以编辑您的问题并在此处发布输出吗?
  • 另外,想看看你的编辑函数返回语句。
  • 因为你的 $data 是一个空数组

标签: laravel


【解决方案1】:

您是否包含 $data 数组以查看 addshortlist() 函数返回的内容? 喜欢

public function addShortList() {
    return view('profile')->with('data', $someDataArray);
}

public function addShortList() {
    return view('profile', compact($someDataArray);
}

【讨论】:

    猜你喜欢
    • 2014-06-25
    • 2015-12-20
    • 2020-01-02
    • 2021-07-06
    • 1970-01-01
    • 1970-01-01
    • 2021-01-25
    • 2019-03-21
    • 2018-10-09
    相关资源
    最近更新 更多