Sindbad~EG File Manager

Current Path : /var/www/html/xfacil.desafio.com.py/app/Http/Livewire/
Upload File :
Current File : /var/www/html/xfacil.desafio.com.py/app/Http/Livewire/Noticias.php

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use Livewire\WithPagination;
use App\Models\Noticia;
use Livewire\WithFileUploads;
use Image;
use App\Models\Emoticonnoticia;
use App\Models\Comentarionoticia;
use App\File;
use App\Models\User;
use App\Notifications\NuevaNotificacion;
use Auth;

class Noticias extends Component{

    use WithPagination;
    use WithFileUploads;

    protected $paginationTheme = 'bootstrap';

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

    public $search='';

    public $titulo,$video,$noticia_id,$tipo;

    public function render(){

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

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

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

    public function store(){

        $validatedDate = $this->validate([
            'titulo' => 'required',
            'video' => 'required|max:100024', // 1MB Max
        ],
        [
            'titulo.required' => 'El campo titulo es requerido',
            'video.required' => 'El campo noticia es requerido',
        ]);

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

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

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

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

        $this->resetInputFields();


    }
    public function edit($id){

        $noticia = Noticia::find($id);

        $this->tipo = 'editar';
        $this->noticia_id = $id;
        $this->titulo = $noticia->titulo;
        $this->video = $noticia->video;

    }
    public function update(){

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

        $noticia = Noticia::find($this->noticia_id);

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

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

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

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

        $this->resetInputFields();


    }

    public function delete($id){

        $emociones = Emoticonnoticia::where('noticia_id',$id)->get();
        $comentarios = Comentarionoticia::where('noticia_id',$id)->get();

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

        $noticia = Noticia::find($id);

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

}

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