Kiddypet
6 days ago
107
5
Laravel

PLUCK from an array

Posted 6 days ago by Kiddypet

Hi I have a project class that hasMany roleProjects a roleProject class that belongs to a Project

Here is my Controller :


       $roleprojects=RoleProject::where('user_id',$user)->where('role_id',1)->get();

    $projects= array();
      foreach ($roleprojects as $roleProject) {
            array_push($projects,$roleProject->project);
          }
    

I just want to know if there is some better more efficient way to do this without the loop

Please sign in or create an account to participate in this conversation.