【问题标题】:Call to a member function where() on array调用数组上的成员函数 where()
【发布时间】:2018-12-03 10:36:46
【问题描述】:

我有以下 MySQL 例程存储过程“Sel_All_Observation_SP”:-

    BEGIN
    SELECT Observations_TBL.observation_id, Observations_TBL.number, Observations_TBL.date, Observations_TBL.status, Observations_TBL.content, Observations_TBL.recommendation, Observations_TBL.remark, Users_TBL.User_name, Type_Name_TBL.Type_Name, Supervisors_TBL.supervisor_name
    FROM ((Observations_TBL INNER JOIN Supervisors_TBL ON (Supervisors_TBL.supervisor_id = Observations_TBL.supervisor_id) AND (Observations_TBL.supervisor_id = Supervisors_TBL.supervisor_id)) INNER JOIN Type_Name_TBL ON (Observations_TBL.Type_Name_ID = Type_Name_TBL.Type_Name_ID) AND (Observations_TBL.Type_Name_ID = Type_Name_TBL.Type_Name_ID)) INNER JOIN Users_TBL ON (Users_TBL.User_ID = Observations_TBL.user_id) AND (Observations_TBL.user_id = Users_TBL.User_ID);

END

我正在使用 laravel 查询生成器在 laravel 中调用上述过程:-

DB::select('call Sel_All_Observation_SP()')

以上是以数组的形式返回结果。

我正在尝试在上面的查询中使用 where 语句:-

$observations = DB::select('call Sel_All_Observation_SP()')->where('user_id',1);

返回错误:-

Symfony\组件\调试\异常\ FatalThrowableError (E_ERROR)

调用数组上的成员函数 where()

我什至尝试通过以下方式从数组转换为集合:-

$observations = collect(DB::select('call Sel_All_Observation_SP()')->where('user_id',1)->get());

返回同样的错误

【问题讨论】:

  • 死转储时得到了什么? dd(DB::select('call Sel_All_Observation_SP()'));

标签: php mysql laravel stored-procedures eloquent


【解决方案1】:

由于您没有选择表,where 语句将不起作用。至于collect,代码,试着稍微改变一下语法,让它变成:

$observations = collect(DB::select('call Sel_All_Observation_SP()'))->where('user_id',1);

以上代码将存储过程中的数据放入一个集合中。然后,您可以使用where 函数过滤结果。最后不用加->get()

【讨论】:

    猜你喜欢
    • 2018-06-28
    • 2022-01-05
    • 1970-01-01
    • 1970-01-01
    • 2021-09-04
    • 2016-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多