Cast Laravel query results to class

前端 未结 6 1379
清酒与你
清酒与你 2021-02-02 12:04

When creating a query using the syntax DB::table(\'foo\'), it creates a generic class (stdClass). Is there any way to cast the resulting rows to a specific class?

6条回答
  •  被撕碎了的回忆
    2021-02-02 12:39

    Yes. For example:

      $query = DB::table('example_tbl')->where('id', $id)->get();
      $cast = (array)$query;
      var_dump($cast);
    

提交回复
热议问题