مشکات
4 سال پیش توسط مشکات مطرح شد
1 پاسخ

آبجکت در لاراول

سلام
خسته نباشید دوستان
یه سوالی داشتم

    public function index()
    {
        $phoneBookDTO =  new \App\Http\DTO\GetPhoneBookDTO();
        $phoneBookDTO->userId=auth()->user()->id;
//        dd($phoneBookDTO);
        $phoneBooks = \App\Http\Objects\PhoneBook::getPhoneBooks($phoneBookDTO);
        return view("phoneBook.index", ['phoneBooks' =>$phoneBooks]);
    }

من توی این قسمت وقتی از$phoneBookDTO ،ddمیگیرم بهم مقدار رو برمیگردونه
ولی وقتی به قسمت زیر پاسش میدم مقدار null میده بهم
ممنون میشم اگر راهنماییم کنید

 public static function getPhoneBooks(\App\Http\DTO\GetPhoneBookDTO $getPhoneBookDTO) {

        $phoneBookQuery = \App\Models\Phonebook::query();
        dd($getPhoneBookDTO);

        if(!empty($getPhoneBookDTO->id)) {
            $phoneBookQuery->where("id", $getPhoneBookDTO->id);
        } elseif(!empty($getPhoneBookDTO->ids)) {
            $phoneBookQuery->whereIn("id", $getPhoneBookDTO->ids);
        }

        if(!empty($getPhoneBookDTO->publishStatus) && (count($getPhoneBookDTO->publishStatus) > 0)){
            $phoneBookQuery->whereIn("publish_status", $getPhoneBookDTO->publishStatus);
        }
        if(!is_null($getPhoneBookDTO->status)){
            $phoneBookQuery->where("status", $getPhoneBookDTO->status);
        }

        $superUser= User::query()->where('is_superUser',1)->get('id');
//        dd($getPhoneBookDTO->userId);

//        if ($superUser==$getPhoneBookDTO->userId){
            $phoneBooks = $phoneBookQuery->with(["users", "users.phonetypes"])->get();
//        }

//

        // if(!empty($getPhoneBookDTO->withRelationByOrCondition)){
        //     foreach($getPhoneBookDTO->withRelationByOrCondition as $relationKey => $relationValue){
        //         // $x = $phoneBookQuery->relationships();
        //         // if(in_array($relationKey , $phoneBookQuery->getRelations())){
        //             if(!empty($relationValue)){

        //                 $phoneBookQuery->with([$relationKey => function($query)use($relationValue){
        //                     foreach($relationValue as $key => $relationWhereClause) {
        //                         if ($key === array_key_first($relationValue)) {
        //                             $query->where($relationWhereClause[0], $relationWhereClause[1], $relationWhereClause[2]);
        //                         } else {
        //                             $query->orWhere($relationWhereClause[0], $relationWhereClause[1], $relationWhereClause[2]);
        //                         }
        //                     }
        //                 }]);

        //             } else {
        //                 $phoneBookQuery->with($relationKey);
        //             }
        //         // }
        //     }
        // }
        // DB::enableQueryLog();
//        else{
//            $phoneBooks = $phoneBookQuery->where("user_id",Auth::id())->with(["users", "users.phonetypes"])->get();
//        }
        // dd(DB::getQueryLog());
        return self::make($phoneBooks);
        // dd($phoneBooks);
        // return $phoneBooks;
    }