helloxielan 2018-12-02 03:53 采纳率: 0%
浏览 26

非法偏移类型(Laravel)

Ajax code in laravel with controller:

<?php

namespace genericlothing\Http\Controllers;

use Illuminate\Http\Request;
use genericlothing\Tienda;
use DB;
class AjaxController extends Controller
{
      public function ajaxBodegasFind(Request $Request)
      {
        $str = "";
        $Tienda = new Tienda;
        $Bodegas = $Tienda->find($Request->ctienda)->bodegas;

        foreach($Bodegas as $Bodega){
          dd($Bodega);
          if($Bodega->estado == "0"){
              $str = $str.'<option value="'.$Bodega->cod_bodega.'">'.$Bodega->direccion_bodega.'</option>';
          }
        }

        return $str;
      }
}

Error image: error img

Array dd($Bodega): dd bodega

I do not understand what's happening, I'm a little desperate...

  • 写回答

1条回答 默认 最新

  • weixin_33730836 2018-12-02 04:36
    关注

    It looks like you are trying to do a search on a new instance of Tienda model which will be empty.

    $Tienda = new Tienda;

    $Bodegas = $Tienda->find($Request->ctienda)->bodegas;

    Should be something like

    $Bodegas = Tienda::find(some value)

    You may need a namespace in front of model name

    Edit: I am not completely sure what you are trying to achieve but it looks like you are trying to populate a select from a query. If this is the case you want to use something like

    $Bodegas = Tienda::where(fieldname, value)->get();

    Find(value) will only return one record matching records id field. Hope this helps.

    评论

报告相同问题?

悬赏问题

  • ¥15 急!C++指针编写相关的问题
  • ¥30 用python写一个多签情况下波场的代理资源和回收资源
  • ¥15 怎么在matlab中输出显示泵的流量-扬程和管路损失与流量均在一个表格里
  • ¥15 matlab学期例题代码答疑
  • ¥50 Hadoop:好友推荐
  • ¥15 在线手电筒追加按钮JS
  • ¥15 调用函数时,无关变量的改变引起函数值的改变
  • ¥15 xy坐标转化为经纬度坐标
  • ¥15 一般三角模糊数的上界值和下届值取中值的多少比较合理?
  • ¥15 cuda安装使用问题