Laravel repository and controller

Viewed 83

this is my repository

public function showInterface(int $id)
    {
        $role = $this->model->find($id);

        $rolePermissions = Permission::join("role_has_permissions","role_has_permissions.permission_id","=","permissions.id")
            ->where("role_has_permissions.role_id",$id)
            ->get();


        return $role && $rolePermissions;
    }

this is my controller

 public function show($id)
    {
        $role=$this->repository->showInterface($id);

        return view('roles.show',compact('role'));
    }

Problem is I should to compact $role and $rolePermissions in Controller , what I should do ?

1 Answers

I think you should change it to:


public function showInterface(int $id)
    {
        $role = $this->model->find($id);

        $rolePermissions = Permission::join("role_has_permissions","role_has_permissions.permission_id","=","permissions.id")
            ->where("role_has_permissions.role_id",$id)
            ->get();


        return [$role, $rolePermissions];
    }

and

public function show($id)
    {
        [$role, $rolePermissions] = $this->repository->showInterface($id);

        return view('roles.show',compact('role', 'rolePermissions'));
    }
Related