Sindbad~EG File Manager

Current Path : /var/www/html/eva.sumar.com.py/app/Http/Livewire/
Upload File :
Current File : /var/www/html/eva.sumar.com.py/app/Http/Livewire/Rankings.php

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use Livewire\WithPagination;
use App\Models\Ranking;
use App\Models\Emoticonafteroffice;
use App\Models\Comentarioafteroffice;
use App\Models\User;
use App\Notifications\NuevaNotificacion;
use Auth;
use App\File;
use Livewire\WithFileUploads;
use Image;

class Rankings extends Component{

    use WithPagination;
    use WithFileUploads;

    protected $paginationTheme = 'bootstrap';

    protected $queryString = ['search' => ['except' => '']];

    public $search='';

    public $titulo,$video,$afteroffice_id,$tipo;

    public function render(){

        $afteroffices = Ranking::where('titulo','LIKE','%'.$this->search.'%')->paginate(20);

        return view('livewire.rankings.index',["afteroffices"=>$afteroffices]);
    }

    private function resetInputFields(){
        $this->video = '';
        $this->titulo = '';
        $this->tipo = '';
        $this->afteroffice_id = '';
    }

    public function store(){

        $validatedDate = $this->validate([ 
            'titulo' => 'required',
            'video' => 'required',
        ],
        [
            'titulo.required' => 'El campo titulo es requerido',
            'video.required' => 'El campo video es requerido',
        ]);

        if($file = $this->video) {
            $control=0;
            $nombre = rand().".".$file->getClientOriginalExtension();
            while ($control == 0) {
                if (is_file(public_path().'/videos/afteroffice'.$nombre )) {
                    $nombre = rand() . $nombre;
                }else{
                    $this->video->storeAs('/videos/afteroffice',$nombre,'subidavideos');
                    $control=1;
                }
            }
        }

        $post = Ranking::create([
            'titulo' => $this->titulo,
            'video' => $nombre,
        ]);

        User::all()
            ->each(function(User $user) use ($post){
                $user->notify(new NuevaNotificacion([
                    'url' => '/afteroffice?search='.$post->titulo,
                    'titulo' => $post->titulo,
                    'descripcion' => 'Nueva after office agregada',
                ]));
            });

        session()->flash('success', 'after office agregada correctamente!');

        $this->resetInputFields();


    }
    public function edit($id){

        $afteroffice = Ranking::find($id);

        $this->tipo = 'editar';
        $this->afteroffice_id = $id;
        $this->titulo = $afteroffice->titulo;
        $this->video = $afteroffice->video;

    }
    public function update(){

        $validatedDate = $this->validate([
            'titulo' => 'required',
        ],
        [
            'titulo.required' => 'El campo titulo es requerido',
        ]);

        $afteroffice = Ranking::find($this->afteroffice_id);

        if($afteroffice->video != $this->video){

            if($file = $this->video) {
                $control=0;
                $nombre = rand().".".$file->getClientOriginalExtension();
                while ($control == 0) {
                    if (is_file(public_path().'/videos/afteroffice'.$nombre )) {
                        $nombre = rand() . $nombre;
                    }else{
                        $this->video->storeAs('/videos/afteroffice',$nombre,'subidavideos');
                        $control=1;
                    }
                }
            }

            $afteroffice->update([
                'titulo' => $this->titulo,
                'video' => $nombre,
            ]);
        }else{
            $afteroffice->update([
                'titulo' => $this->titulo,
            ]);
        }

        session()->flash('success', 'afteroffice actualizada correctamente!');

        $this->resetInputFields();


    }

    public function delete($id){

        $emociones = Emoticonafteroffice::where('afteroffice_id',$id)->get();
        $comentarios = Comentarioafteroffice::where('afteroffice_id',$id)->get();

        foreach($emociones as $emo){
            $emo->delete();
        }
        foreach($comentarios as $com){
            $com->delete();
        }

        $afteroffice = Ranking::find($id);

        if(unlink(public_path().'/videos/afteroffice/'.$afteroffice->video)) {
            $afteroffice->delete();
        }
    }

}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists