Sindbad~EG File Manager
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Livewire\WithPagination;
use App\Models\Boletin;
use App\Models\User;
use App\Notifications\NuevaNotificacion;
use Auth;
class Boletines extends Component{
use WithPagination;
protected $paginationTheme = 'bootstrap';
protected $queryString = ['search' => ['except' => '']];
public $search='';
public $boletin_id,$titulo,$boletin,$tipo,$padre,$boletintitulo,$navegador=[];
public $updateMode = 0;
public function render(){
if($this->padre){
$boletines = Boletin::where('titulo','LIKE','%'.$this->search.'%')->where('padre',$this->padre)->paginate(20);
$this->boletintitulo = Boletin::find($this->padre);
}else{
$boletines = Boletin::where('titulo','LIKE','%'.$this->search.'%')->wherenull('padre')->paginate(20);
}
return view('livewire.boletines.index',["boletines"=>$boletines]);
}
private function resetInputFields(){
$this->boletin_id = '';
$this->titulo = '';
$this->tipo = '';
$this->emit('boletin', '');
}
public function store(){
$validatedDate = $this->validate([
'titulo' => 'required',
'tipo' => 'required'
],
[
'titulo.required' => 'El campo Titulo es requerido',
'tipo.required' => 'El campo categorÃa o post es requerido',
]);
$post = Boletin::create([
'titulo' => $this->titulo,
'tipo' => $this->tipo,
'boletin' => $this->boletin,
'padre' => $this->padre,
]);
if($this->tipo != 1){
User::all()->each(function(User $user) use ($post){
$user->notify(new NuevaNotificacion([
'url' => '/boletinessolar/'.$post->id,
'titulo' => $post->titulo,
'descripcion' => 'Nuevo Boletin Solar agregado',
]));
});
}
$this->emit('alert', ['type' => 'success', 'message' => 'Boletin agregado correctamente!']);
$this->resetInputFields();
}
public function edit($id){
$this->updateMode = 2;
$boletin = Boletin::find($id);
$this->boletin_id = $id;
$this->titulo = $boletin->titulo;
$this->tipo = $boletin->tipo;
$this->emit('boletin', $boletin->boletin);
}
public function crear(){
$this->updateMode = 1;
$this->resetInputFields();
}
public function cancel(){
$this->updateMode = 0;
$this->resetInputFields();
}
public function update(){
$validatedDate = $this->validate([
'titulo' => 'required',
'tipo' => 'required'
],
[
'titulo.required' => 'El campo Titulo es requerido',
'tipo.required' => 'El campo categorÃa o post es requerido',
]);
if ($this->boletin_id) {
$boletin = Boletin::find($this->boletin_id);
$boletin->update([
'titulo' => $this->titulo,
'tipo' => $this->tipo,
'boletin' => $this->boletin,
]);
$this->updateMode = 0;
$this->emit('alert', ['type' => 'info', 'message' => 'Boletin actualizado correctamente!']);
$this->resetInputFields();
}
}
public function delete($id){
if($id){
$boletin = Boletin::find($id);
$boletin->estado = 0;
$boletin->update();
$this->emit('alert', ['type' => 'error', 'message' => 'Boletin eliminado correctamente!']);
}
}
public function padre($id){
$this->padre=$id;
$boletin = Boletin::find($id);
$this->navegador[$id]=$boletin->titulo;
}
public function deletepadre(){
$this->padre="";
$this->navegador=[];
}
public function deletenavegador($id){
$this->padre=$id;
while(count($this->navegador) >= $id){
$id+=1;
unset($this->navegador[$id]);
}
}
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists