7 months ago

Undefined variable only showing online server, but on localhost works good

Posted 7 months ago by LYiub

Hi, I'm using Laravel 5.4, in my controller I defind variables inside if() statement, then I use access them from out of if statement, but when I upload my files online, It keep showing me this error for those variables.

For example:

 $role_permissions = DB::table('role_user')
            ->where('user_id', '=', $user_id)

        foreach ($role_permissions as $role) {
            $user_role = $role->role_id;

        if ($user_role == 1) {
            $user_status = 'Admin';
        } else {
            $user_status = 'User';

The error is :

Undefined variable: user_role

the error sign at the if($user_role == 1), why that error happened here ? I cant access the variables out brackets. ?

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