mardi 27 mars 2018

How can use constructer inside a controller for function redirection

in larvel i am creating constructer on my controller like :

public function __construct()
    {
      $perm=permission_Byid(Session::get('userid'));
       foreach ($perm as $key => $value) {
        if(in_array($value->permission_id,'4'))
        {

          echo "ok";exit;

        }
        else
        {
          echo "no";exit;

        }
       }
    }

In $perm i am getting data like:

Array
(
    [0] => stdClass Object
        (
            [permission_id] => 1
            [admin_permission_field] => Access Admin Page
        )

    [1] => stdClass Object
        (
            [permission_id] => 2
            [admin_permission_field] => Print/Export Log
        )

    [2] => stdClass Object
        (
            [permission_id] => 3
            [admin_permission_field] => Approve/Decline Request
        )

    [3] => stdClass Object
        (
            [permission_id] => 4
            [admin_permission_field] => Edit Lists
        )

    [4] => stdClass Object
        (
            [permission_id] => 5
            [admin_permission_field] => Edit Agent Info
        )

    [5] => stdClass Object
        (
            [permission_id] => 6
            [admin_permission_field] => Edit Listings
        )
)

i want when i get the [permission_id] => 4 its call my controller another function if there is not permission_id=4 its show me a view page like error page.

In may case if and else condition is not working ..

In heleper i have function like:

function permission_Byid($userid)
    {
        return DB::table('tbl_admin_permission as tap')
                                        ->select('tap.permission_id as permission_id','taa.permission_eng as admin_permission_field')
                                         ->join('tbl_admin_users as tau', 'tau.id', '=', 'tap.admin_id')
                                        ->join('tbl_admin_access as taa', 'taa.id', '=', 'tap.permission_id')
                                        ->where('tap.admin_id','=',$userid)
         ->get();

    } 

can you please help me related this .. i ll be very obilege



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Ga5eam
via IFTTT

Aucun commentaire:

Enregistrer un commentaire