【问题标题】:ErrorException (E_ERROR) rawurlencode() expects parameter 1 to be string, object givenErrorException (E_ERROR) rawurlencode() 期望参数 1 是字符串,给定对象
【发布时间】:2018-11-28 05:16:23
【问题描述】:

试图显示两个表中的数据并收到上述错误消息,有人可以帮助翻译此错误消息吗? 这是控制器

public function index()
{
  $maintenances = DB::table('tenants')->select('tenants.lastname','tenants.firstname','maintenances.m_status','tenants.designation',      'maintenances.description','maintenances.building_section','maintenances.category','maintenances.reported_date')
        ->join('maintenances','maintenances.tenants_id','=','tenants.id')
        ->get();
    //dd($maintenances);
    return view('agent/maintenance_list', compact('maintenances', 'assetTenants', 'tenants'));
}

然后查看

@foreach($maintenances as $maintenance)
              <tr>
                <td class="text-center">
                  <div class="checkbox-custom">
                    <input id="product-01" type="checkbox" value="01">
                    <label for="product-01" class="pl-0">&nbsp;</label>
                  </div>
                </td>
                <td>{{ $maintenance->designation }} {{ $maintenance->firstname }} {{ $maintenance->lastname }}</td>
                <td>{{ $maintenance->category }}</td>
                <td>{{ $maintenance->building_section }}</td>
                <td>{{ $maintenance->description }}</td>
                <td>{{ $maintenance->reported_date }}</td>
                <td>{{ $maintenance->m_status }}</td>
                <td class="text-center">
                  <div role="group" aria-label="Basic example" class="btn-group btn-group-sm">
                    <a href="{{ url('agent/edit_maintenance', $maintenance }}" type="button" class="btn btn-outline btn-success"><i class="ti-pencil"></i></a>
                  </div>
                </td>
              </tr>
              @endforeach

随着路线

Route::get('maintenance_list', 'MaintenanceController@index')->name('/maintenance_list');

但是,我注意到一旦我从 url 编辑按钮中删除 $maintenance 变量,页面就会显示得很好。可能是什么问题,因为我不明白列表中的错误消息

【问题讨论】:

  • 试试这样:&lt;a href="{{ url('agent/edit_maintenance', $maintenance-&gt;id }}" type="button" class="btn btn-outline btn-success"&gt;&lt;i class="ti-pencil"&gt;&lt;/i&gt;&lt;/a&gt;
  • 结果是什么dd($maintenance);??

标签: mysql laravel


【解决方案1】:

您传递的是整个 $maintenance 而不是 $maintenance-&gt;id 之类的东西,因此出现 object given 错误:

<a href="{{ url('agent/edit_maintenance', $maintenance }}" type="button" class="btn btn-outline btn-success"><i class="ti-pencil"></i></a>

【讨论】:

  • 我试过了,但我得到了这个 ErrorException (E_ERROR) 未定义属性:stdClass::$id。思路是把要编辑的数据带到编辑页面
  • 我以-&gt;id 为例,您需要传递一个唯一的参数,这样当它转到agent/edit_maintenance url 时,它可以获取参数并准确确定哪个“维护”编辑。如果您确实想使用-&gt;id,则需要在select 查询中添加maintenances.id(如果maintenances 表有id 列)
猜你喜欢
  • 2018-11-27
  • 2020-11-22
  • 2021-02-06
  • 1970-01-01
  • 2021-05-07
  • 2018-06-16
  • 2019-09-05
  • 2015-06-27
  • 1970-01-01
相关资源
最近更新 更多