CasperSecurity

Current Path : /var/www/orientalss.com/app/Http/Livewire/Settings/
Upload File :
Current File : /var/www/orientalss.com/app/Http/Livewire/Settings/DepartmentsLivewire.php

<?php

namespace App\Http\Livewire\Settings;

use App\Models\Team;
use Illuminate\Support\Str;
use Livewire\Component;
use Livewire\WithPagination;

class DepartmentsLivewire extends Component
{
    use WithPagination;
    protected $paginationTheme = 'bootstrap';

    public $search;
    public $perPage=10;
    public $orderBy='id';
    public $orderAsc='1';

    public $dept_name;
    public $modelid;
    public $showmodal=false;

    public $successmsg="The Department data has been saved successfully.";
    public $updatemsg="The Department data has been updated successfully.";
    public $deletemsg="The Department data has been deleted successfully.";
    public $duplicateerrormsg="Sorry !!! Department name has already exists in our database. Please Try Another Name";
    public $errormsg="Sorry !!! Something went wrong. Please Try Again.";

    protected $listeners = ['delete'];

    public $rules=[
        'dept_name'=>'required|max:255'
    ];

    public $updatedrules=[
        'dept_name'=>'required|max:255'
    ];

    public $messages=[
        'dept_name.required'=>'This field is required',
        'dept_name.max'=>'This field allows maximum 255 character',
    ];

    public function updatingSearch()
    {
        $this->resetPage();
    }

    public function showmodalclick(){
        $this->resetValidation();
        $this->showmodal=true;
        //$this->dispatchBrowserEvent('livewire:load');
    }

    public function closemodalclick(){
        $this->resetValidation();
        $this->showmodal=false;
    }

    public function updateclick($id){
        $this->modelid=$id;
        $this->loadData($this->modelid);
        $this->showmodal=true;
    }

    public function deleteclick($id){
        $this->modelid=$id;
        $this->dispatchBrowserEvent('confirmdelete',[
            'message'=>'Are you sure want to delete this data ?',
            'funcname'=>'delete'
        ]);
    }

    public function cleanVar(){
        $this->modelid=null;
        $this->dept_name=null;
        $this->showmodal=false;
    }

    public function loadData($id){
        $response=Team::find($id);
        if($response){
            $this->dept_name=$response['display_name'];
        }
    }

    public function save(){
        $this->validate($this->rules,$this->messages);
        $response=Team::where('display_name',$this->dept_name)->latest()->first();
        if($response){
            $this->dispatchBrowserEvent('showsuccessmsg',[
                'type'=>'error',
                'message'=>$this->duplicateerrormsg
            ]);
        }else{
            $response=Team::create([
                'name'=>Str::kebab($this->dept_name),
                'display_name'=>$this->dept_name,
            ]);
            if($response){
                $this->cleanVar();
                $this->dispatchBrowserEvent('closeOffCanvas');
                $this->dispatchBrowserEvent('showsuccessmsg',[
                    'type'=>'success',
                    'message'=>$this->successmsg
                ]);
            }else{
                $this->dispatchBrowserEvent('showsuccessmsg',[
                    'type'=>'error',
                    'message'=>$this->errormsg
                ]);
            }
        }
    }

    public function update(){
        $this->validate($this->updatedrules,$this->messages);
        $response=Team::find($this->modelid);
        if($response){
            $response->update([
                'name'=>Str::kebab($this->dept_name),
                'display_name'=>$this->dept_name,
            ]);
            if($response){
                $this->cleanVar();
                $this->dispatchBrowserEvent('closeOffCanvas');
                $this->dispatchBrowserEvent('showsuccessmsg',[
                    'type'=>'success',
                    'message'=>$this->updatemsg
                ]);
            }else{
                $this->dispatchBrowserEvent('showsuccessmsg',[
                    'type'=>'error',
                    'message'=>$this->errormsg
                ]);
            }
        }
    }

    public function delete(){
        $response=Team::find($this->modelid);
        if($response){
            if($response->delete()){
                $this->cleanVar();
                $this->dispatchBrowserEvent('showsuccessmsg',[
                    'type'=>'success',
                    'message'=>$this->deletemsg
                ]);
            }else{
                $this->dispatchBrowserEvent('showsuccessmsg',[
                    'type'=>'error',
                    'message'=>$this->errormsg
                ]);
            }
        }
    }


    public function read(){
        $depts=Team::search($this->search)->orderBy($this->orderBy, $this->orderAsc ? 'asc' : 'desc')->paginate($this->perPage);
        return $depts;
    }
    public function render()
    {
        $departments=$this->read();
        return view('livewire.settings.departments-livewire',compact('departments'));
    }
}
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY