VaKeR CYBER ARMY
Logo of a company Server : Apache
System : Linux host44.registrar-servers.com 4.18.0-513.18.1.lve.2.el8.x86_64 #1 SMP Sat Mar 30 15:36:11 UTC 2024 x86_64
User : vapecompany ( 2719)
PHP Version : 7.4.33
Disable Function : NONE
Directory :  /proc/thread-self/root/home/vapecompany/demo.vapecompany.com.bd/app/Http/Controllers/Backend/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/thread-self/root/home/vapecompany/demo.vapecompany.com.bd/app/Http/Controllers/Backend/RoleController.php
<?php

namespace App\Http\Controllers\Backend;
use App\Http\Controllers\Controller;

use App\Models\Role;
use Illuminate\Http\Request;
use App\Models\Module;
use App\Models\User;
use App\Models\UserPermission;
use App\Models\RolePermission;
use App\Models\RoleModule;
use App\Models\RoleEvent;
use App\Models\UserRole;
use App\Models\ModuleEvent;

class RoleController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function __construct()
    {
        $this->middleware('admin');

    }
    public function index()
    {
//        if(!auth()->user()->canEvent('all_role'))
//        {
//            return redirect('/');
//        }
        $roles = Role::get();
        return view('backend.role.list',['roles'=>$roles]);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
//        if(!auth()->user()->canEvent('new_role'))
//        {
//            return redirect('/');
//        }
        return view('backend.role.create');
    }
    public function change_password($id)
    {
//        if(!auth()->user()->canEvent('change_password'))
//        {
//            return redirect('/');
//        }
        return view('backend.role.change_password',['id'=>$id]);
    }
    public function user_list(){
        // if(!auth()->user()->canEvent('user_list'))
        // {
        //     return redirect('/'); 
        // }
        $users=User::get();
         return view('backend.role.user_list',['users'=>$users]);
    }
    public function rolePermission()
    {
//       if(!auth()->user()->canEvent('role_permission'))
//        {
//            return redirect('/');
//        }
        $modules = Module::where('module_id',2)->get();
        $roles = Role::get();
        //dd($modules[0]);
        return view('backend.role.rolePermission',['modules'=>$modules,'roles'=>$roles]);
    }
    public function userPermission($id)
    {
//       if(!auth()->user()->canEvent('user_permission'))
//        {
//            return redirect('/');
//        }
        $modules = Module::get();
        $roles = Role::get();
        $user=User::where('user_id',$id)->first();
        $role_id= UserRole::where('user_id',$id)->first();

        return view('backend.role.user_permission',['modules'=>$modules,'roles'=>$roles,'user'=>$user,'role_id'=>$role_id]);
    }

    public function getRolePermission(Request $request){
        $modules = Module::get();
        $role=Role::where('role_id',$request->role_id)->first();

      // return $role->module_event;
        return view('backend.role.permission_list',['modules'=>$modules,'role'=>$role]);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $validator = \Validator::make($request->all(), [
            'role_name' => 'required|unique:roles|max:150',

        ]);

        if ($validator->fails())
        {
            return response()->json(['errors'=>$validator->errors()->all()]);
        }else{
           //return  response()->json(['re'=> auth()->user()->user_id]);
            $role =  new Role;
            $role->role_name = $request->role_name;
            $role->created_by = auth()->user()->user_id;
            $role->save();
        }
        return response()->json(['errors'=>'0','success'=>'Record is successfully added']);
    }
    public function updatePassword(Request $request)
    {
        $validator = \Validator::make($request->all(), [
            'password' => 'required|max:150',

        ]);

        if ($validator->fails())
        {
            return response()->json(['errors'=>$validator->errors()->all()]);
        }else{
           //return  response()->json(['re'=> auth()->user()->user_id]);
            User::where('user_id',$request->user_id)->update([
                'password'=>bcrypt($request->password),
            ]);

        }
        return response()->json(['errors'=>'0','success'=>'Record is successfully added']);
    }


    /**
     * Display the specified resource.
     *
     * @param  \App\Models\Role  $role
     * @return \Illuminate\Http\Response
     */
    public function show(Role $role)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Models\Role  $role
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
//        if(!auth()->user()->canEvent('edit_role'))
//        {
//            return redirect('/');
//        }
        $role=Role::where('role_id',$id)->first();
        return view('backend.role.edit',['role'=>$role]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Models\Role  $role
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Role $role)
    {
        $id=$request->role_id;
       $validator = \Validator::make($request->all(), [
            'role_name' => 'required|max:150|unique:roles,role_name,'.$id.',role_id',

        ]);

        if ($validator->fails())
        {
            return response()->json(['errors'=>$validator->errors()->all()]);
        }else{
           //return  response()->json(['re'=> auth()->user()->user_id]);
            $role =  Role::find($request->role_id);
            $role->role_name = $request->role_name;
            // $role->updated_by = auth()->user()->user_id;
            $role->save();
        }
        return response()->json(['errors'=>'0','success'=>'Record is successfully Updated']);
    }
    public function updateRolePermission(Request $request, Role $role)
    {
     // return ModuleEvent::where('module_event_id',136)->get();
        try{
            if($request->navigation_event){
                foreach ($request->navigation_event as $key => $value) {
                    $roleEvent = RoleEvent::where('module_event_id',$key)->where('role_id',$request->role)->first();
                   // return $roleEvent;
                    if($roleEvent == null){
                       $roleEvent = new RoleEvent;
                      // return ModuleEvent::where('module_event_id',$key)->get();
                       $e=ModuleEvent::where('module_event_id',$key)->first()->url;
                       $roleEvent->event_name=$e;
                    }
                     //$role = new UserPermission;
                     $roleEvent->role_id=$request->role;
                     $roleEvent->module_id=$value[0];
                     $roleEvent->module_event_id=$key;


                     $roleEvent->status=1;
                     $roleEvent->save();

                }
            }
            if($request->navigation_module){
                foreach ($request->navigation_module as $key => $value) {
                    $roleModule = RoleModule::where('module_id',$value)->where('role_id',$request->role)->first();
                    if($roleModule == null){
                       $roleModule = new RoleModule;
                    }
                     //$role = new UserPermission;
                     $roleModule->role_id=$request->role;
                     $roleModule->module_id=$value;
                     $roleModule->status=1;
                     $roleModule->save();

                }
            }
            if($request->old_nav_event){
                foreach ($request->old_nav_event as $key => $value) {
                    $role = RoleEvent::where('module_event_id',$key)->where('role_id',$request->role)->first();

                     //$role = new UserPermission;
                     $role->role_id=$request->role;
                     $role->module_id=$value[0];
                     $role->module_event_id=$key;
                    // $role->module_id=$key;
                    //  $role->module_event_id=$value;
                     $role->status=0;
                     $role->save();

                }
            }
            if($request->old_nav_module){
                foreach ($request->old_nav_module as $key => $value) {
                    $role = RoleModule::where('module_id',$value)->where('role_id',$request->role)->first();

                     //$role = new UserPermission;
                     $role->role_id=$request->role;
                     $role->module_id=$value;
                     $role->status=0;
                     $role->save();

                }
            }

        }catch (\PDOException $e) {
             return response()->json(['errors'=>['eroor'=>$e]]);
        }
        return response()->json(['errors'=>'0','success'=>'Record is successfully Updated']);
    }
        public function updateUserPermission(Request $request, Role $role)
        {
            $userRole = UserRole::where('user_id',$request->user_id)->first();
            if($userRole == null){
                $userRole = new UserRole;
                $userRole->user_id=$request->user_id;
            }

            $userRole->role_id=$request->role;
            $userRole->save();
            return response()->json(['errors'=>'0','success'=>'Record is successfully Updated']);
        return $request;
        // try{
        //     foreach ($request->navigation as $key => $value) {
        //         $role = RolePermission::where('module_id',$value[0])->where('module_event_id',$key)->where('role_id',$request->role)->first();
        //         if($role == null){
        //            $role = new RolePermission;
        //         }
        //          //$role = new UserPermission;
        //          $role->role_id=$request->role;
        //          $role->module_id=$value[0];
        //          $role->module_event_id=$key;
        //          $role->status=1;
        //          $role->save();

        //     }
        //     if($request->old_nav){
        //         foreach ($request->old_nav as $key => $value) {
        //             $role = RolePermission::where('module_id',$value[0])->where('module_event_id',$key)->where('role_id',$request->role)->first();

        //              //$role = new UserPermission;
        //              $role->role_id=$request->role;
        //              $role->module_id=$value[0];
        //              $role->module_event_id=$key;
        //              $role->status=0;
        //              $role->save();

        //         }
        //     }

        // }catch (\PDOException $e) {
        //      return response()->json(['errors'=>['eroor'=>$e]]);
        // }
        // return response()->json(['errors'=>'0','success'=>'Record is successfully Updated']);
       //  $id=$request->role_id;
       // $validator = \Validator::make($request->all(), [
       //      'role_name' => 'required|max:150|unique:roles,role_name,'.$id.',role_id',

       //  ]);
       // $role =  UserPermission::where($request->role_id);

       //  if ($validator->fails())
       //  {
       //      return response()->json(['errors'=>$validator->errors()->all()]);
       //  }else{
       //     //return  response()->json(['re'=> auth()->user()->user_id]);
       //      $role =  UserPermission::find($request->role_id);
       //      $role->role_name = $request->role_name;
       //      $role->updated_by = auth()->user()->user_id;
       //      $role->save();
       //  }
        return response()->json(['errors'=>'0','success'=>'Record is successfully Updated']);
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Models\Role  $role
     * @return \Illuminate\Http\Response
     */
    public function destroy(Role $role)
    {
        //
    }
}

VaKeR 2022