1

i have permissions for this role and other permission that this role don't have i want to display both permission in this role and other ones in the same page separated heres index in my controller

public function index(Request $request , $id,$permission_id)
{
    $rolepermission =DB::table('permission_role')
        ->join('permissions', 'permissions.id', '=', 'permission_role.permission_id')
        ->where('permission_role.role_id' , $id)
        ->get();

    $rolepermissiongetid =DB::table('permission_role')->select('role_id')
        ->where('permission_role.role_id' , $id)
        ->get();

    $notrolepermision =DB::table('permission_role')
        ->join('permissions', 'permissions.id', '=', 'permission_role.permission_id')
        ->whereNotIn('permission_role.role_id' ,$rolepermissiongetid)
        ->get();



    $nodata = '';
    if($rolepermission==null){
        $nodata="This Roles Does Not Have Permissions";
    }

    $role=DB::table('roles')->where('id' ,$id)->first();

    return view('managements.role-permission-list')
        ->with('role' ,$role)
        ->with('data' , $rolepermission)
        ->with('role2', $notrolepermision)
        ->with('nodata' , $nodata)
        ->with('role_id' ,$id);
}

but i keep getting Object of class stdClass could not be converted to string,

i did foreach to get the data in my view

<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            @foreach($role2 as $role2s)
                <button class="btn btn-primary">{{$role2s->name}}</button>

             @endforeach

            <!-- /.panel-heading -->
            <div class="panel-body">
        @if(isset($success_alert))
            <div class="alert alert-success">{{$success_alert}}</div>
        @endif
        @if(isset($danger_alert))
            <div class="alert alert-danger">{{$danger_alert}}</div>
        @endif


            @foreach($data as $dat)


                <div class="col-lg-3">
                    <button class="btn btn-default">{{$dat->name}}</button>
                    <hr>
                </div>


              <!--      <td>
                        <a href='/role-permission-confirm-delete/{{$dat->role_id}}/{{$dat->permission_id}}' class='btn btn-danger'><i class='fa fa-close'></i> Delete</a>

                       <!-- <a href='/role-permission/{{$dat->role_id}}/{{$dat->permission_id}}' class='btn btn-warning confirm'> View </a>
                    </td>-->

            @endforeach


        <!-- /.table-responsive -->

    </div>
        </div>
   <!-- <a href="/role-permission/create/{{$role->id}}" class="btn btn-primary">
        <i class="fa fa-plus"></i> New Permission
    </a> -->
</div>
</div>

this im getting with the error

Object of class stdClass could not be converted to string in RolePermissionsController.php line 32 at HandleExceptions->handleError('8', 'Trying to get property of non-object', 'C:\xampp\htdocs\terkwazmng\app\Http\Controllers\RolePermissionsController.php', '32', array('role_id' => '1', 'rolepermission' => array(object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass)), 'rolepermissiongetid' => array(object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass), object(stdClass)))) in RolePermissionsController.php line 32

0

4 Answers 4

1

The issue would be with this piece of code, $role2s is an object. Since you are trying to print the object it is throwing the error

<button class="btn btn-primary">{{$role2s}}</button>

Trying running var_dump on the particular variable.

Sign up to request clarification or add additional context in comments.

2 Comments

i get Object of class stdClass could not be converted to string error in the view page, and i changed {{$role2s}} to {{$role2s->name}} kept getting the same error
Please share the entire view page content as well as error message you are getting
1

Try to do this: it works 100%

$rolepermissiongetid =DB::table('permission_role')->select('role_id')
 ->where('permission_role.role_id' , $id)
    ->get();




$arrQuery = array();
foreach($rolepermissiongetid as $key => $rolepermissiongetid){
$arrQuery[$key] = rolepermissiongetid->role_id;
 }




$notrolepermision =DB::table('permission_role')
    ->join('permissions', 'permissions.id', '=', 'permission_role.permission_id')
    ->whereNotIn('permission_role.role_id' ,$arrQuery)
    ->get();



//tunisian_developpers_team

Comments

0

curly braces are equals to PHP's echo statement. In $role2s variable you are getting object/array so it'll not print but give you an error. So you can use below solution. and after that -> or [' '] get it's object or array.

Try

{{dd($role2s)}}

or

{{print_r({{$role2s}})}}

or

{{var_dump({{$role2s}})}}

**

1 Comment

i know i used that the problem is not from the view but the controller
0

You don't have specify your exact error. But May be error is in controller. check code below

$notrolepermision =DB::table('permission_role')
        ->join('permissions', 'permissions.id', '=', 'permission_role.permission_id')
        ->whereNotIn('permission_role.role_id' ,$rolepermissiongetid->role_id) //<--------------check this line you need $rolepermissiongetid->role_id in stead of $rolepermissiongetid
        ->get();

1 Comment

i have $rolepermissiongetid =DB::table('permission_role')->select('role_id') ->where('permission_role.role_id' , $id) ->get(); so no need to use $rolepermissiongetid->role_id

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.