<legend id='uHdpI'><style id='uHdpI'><dir id='uHdpI'><q id='uHdpI'></q></dir></style></legend><tfoot id='uHdpI'></tfoot>
    <bdo id='uHdpI'></bdo><ul id='uHdpI'></ul>

      1. <small id='uHdpI'></small><noframes id='uHdpI'>

        <i id='uHdpI'><tr id='uHdpI'><dt id='uHdpI'><q id='uHdpI'><span id='uHdpI'><b id='uHdpI'><form id='uHdpI'><ins id='uHdpI'></ins><ul id='uHdpI'></ul><sub id='uHdpI'></sub></form><legend id='uHdpI'></legend><bdo id='uHdpI'><pre id='uHdpI'><center id='uHdpI'></center></pre></bdo></b><th id='uHdpI'></th></span></q></dt></tr></i><div id='uHdpI'><tfoot id='uHdpI'></tfoot><dl id='uHdpI'><fieldset id='uHdpI'></fieldset></dl></div>
      2. Laravel - 方法 Illuminate\Support\Collection::makeHidden 不

        时间:2023-09-22

          <small id='1d8tX'></small><noframes id='1d8tX'>

            <bdo id='1d8tX'></bdo><ul id='1d8tX'></ul>
              <tfoot id='1d8tX'></tfoot>

              <legend id='1d8tX'><style id='1d8tX'><dir id='1d8tX'><q id='1d8tX'></q></dir></style></legend>
              <i id='1d8tX'><tr id='1d8tX'><dt id='1d8tX'><q id='1d8tX'><span id='1d8tX'><b id='1d8tX'><form id='1d8tX'><ins id='1d8tX'></ins><ul id='1d8tX'></ul><sub id='1d8tX'></sub></form><legend id='1d8tX'></legend><bdo id='1d8tX'><pre id='1d8tX'><center id='1d8tX'></center></pre></bdo></b><th id='1d8tX'></th></span></q></dt></tr></i><div id='1d8tX'><tfoot id='1d8tX'></tfoot><dl id='1d8tX'><fieldset id='1d8tX'></fieldset></dl></div>
                    <tbody id='1d8tX'></tbody>
                1. 本文介绍了Laravel - 方法 Illuminate\Support\Collection::makeHidden 不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想隐藏列 password &OTP ,包含在 $uses 结果中.实际上,这 2 列是 users 表的一部分.我试过如下.但它会产生错误 - Method Illuminate\Support\Collection::makeHidden does not exist .如何解决这个问题?任何建议..

                  I want to hide the columns password & OTP ,that is included in $uses result. Actually these 2 columns are part of the users table. I've tried like below. But it generates the error - Method Illuminate\Support\Collection::makeHidden does not exist . How to solve this? Any suggestions..

                  $users = DB::table('users')
                              ->join('location', 'users.id', '=', 'location.id')
                              ->join('user_technical_details', 'users.id', '=', 'user_technical_details.id')
                              ->get();
                  $d=$users->makeHidden(['password','OTP']);    
                  return response()->json([
                              'message' => 'profile viewed successfully',
                              'data' => $d,
                              'statusCode' => 200,
                              'status' => 'success'],200);  
                  

                  推荐答案

                  您正在尝试在集合上执行此方法,但它是一个模型方法:

                  You're trying to execute this method on the collection but it's a model method:

                  $users = DB::table('users')
                              ->join('location', 'users.id', '=', 'location.id')
                              ->join('user_technical_details', 'users.id', '=', 'user_technical_details.id')
                              ->get();
                  foreach($users as $user) {
                      $user->makeHidden(['password','OTP']);
                  }
                  

                  这仍然不起作用,因为您使用 DB::table('users') 而不是 Users::all().

                  And this still doesn't work since you're using DB::table('users') over Users::all().

                  为了使用模型,您必须执行以下操作:

                  In order to use a model, you have to do the following:

                  型号:

                  class User extends Model
                  {
                      // Instead of `makeHidden()` you can do this if you want them always to be hidden
                      // protected $hidden = ['password','OTP'];
                  
                      public function location()
                      {
                          return $this->hasOne(AppModelsLocation::class, 'users.id', '=', 'location.id');
                      }
                  
                      public function technical_details()
                      {
                          return $this->hasOne(AppModelsUserTechnicalDetail::class, 'users.id', '=', 'user_technical_details.id');
                      }
                  }
                  

                  控制器:

                  $users = Users::with(['location', 'technical_details'])
                              ->get();
                  foreach($users as $user) {
                      $user->makeHidden(['password','OTP']);
                  }
                  

                  这篇关于Laravel - 方法 Illuminate\Support\Collection::makeHidden 不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Laravel whereIn whereJsonContains 的实现 下一篇:Laravel 4 eloquent 模型链接额外的 where 子句

                  相关文章

                  最新文章

                    <bdo id='loAxs'></bdo><ul id='loAxs'></ul>
                2. <small id='loAxs'></small><noframes id='loAxs'>

                3. <legend id='loAxs'><style id='loAxs'><dir id='loAxs'><q id='loAxs'></q></dir></style></legend>

                    1. <i id='loAxs'><tr id='loAxs'><dt id='loAxs'><q id='loAxs'><span id='loAxs'><b id='loAxs'><form id='loAxs'><ins id='loAxs'></ins><ul id='loAxs'></ul><sub id='loAxs'></sub></form><legend id='loAxs'></legend><bdo id='loAxs'><pre id='loAxs'><center id='loAxs'></center></pre></bdo></b><th id='loAxs'></th></span></q></dt></tr></i><div id='loAxs'><tfoot id='loAxs'></tfoot><dl id='loAxs'><fieldset id='loAxs'></fieldset></dl></div>
                      <tfoot id='loAxs'></tfoot>