diff --git a/app/Http/Livewire/ShowLogGeneral.php b/app/Http/Livewire/ShowLogGeneral.php index de48dd8..1465880 100755 --- a/app/Http/Livewire/ShowLogGeneral.php +++ b/app/Http/Livewire/ShowLogGeneral.php @@ -10,8 +10,8 @@ class ShowLogGeneral extends Component public $entradas; public $buscar; - public $filtro_fecha; - + public $filtro_fecha; + public function render() { $query = Log_general::query(); @@ -23,11 +23,12 @@ class ShowLogGeneral extends Component if ($this->filtro_fecha) { $query->whereDate('created_at', $this->filtro_fecha); } - - $logs = $query->orderBy('id', 'desc')->paginate($this->entradas); + + $logs = $query->orderBy('id', 'desc')->paginate($this->entradas); return view('livewire.show-log-general', [ 'logs' => $logs ]); } } + diff --git a/app/Http/Livewire/ShowLogHistorial.php b/app/Http/Livewire/ShowLogHistorial.php index 993c48a..c36d27d 100644 --- a/app/Http/Livewire/ShowLogHistorial.php +++ b/app/Http/Livewire/ShowLogHistorial.php @@ -4,6 +4,7 @@ namespace App\Http\Livewire; use App\Models\Log_general; use App\Models\Log_historial; +use App\Models\User; use Livewire\Component; class ShowLogHistorial extends Component @@ -13,9 +14,11 @@ class ShowLogHistorial extends Component public $buscar; public $filtro_fecha; + public $user_id; + public function render() { - $query = Log_general::query(); + $query = Log_historial::query(); if ($this->buscar) { $query->where('detalle', 'like', '%' . $this->buscar . '%'); @@ -25,10 +28,17 @@ class ShowLogHistorial extends Component $query->whereDate('created_at', $this->filtro_fecha); } + if ($this->user_id) { + $query->where('user_id', $this->user_id); + } + $logs = $query->orderBy('id', 'desc')->paginate($this->entradas); + $users = User::orderBy('name')->get(); + return view('livewire.show-log-historial', [ - 'logs' => $logs + 'logs' => $logs, + 'users' => $users ]); } } diff --git a/app/Http/Livewire/ShowPlanes.php b/app/Http/Livewire/ShowPlanes.php index 2897cd5..9c2b25e 100755 --- a/app/Http/Livewire/ShowPlanes.php +++ b/app/Http/Livewire/ShowPlanes.php @@ -6,6 +6,7 @@ use App\Models\Cuentas; use App\Models\Historiale; use App\Models\Historial_cuenta; use App\Models\Log_general; +use App\Models\Log_historial; use App\Models\Notificacion; use App\Models\Pendientes; use App\Models\Role; @@ -280,6 +281,11 @@ class ShowPlanes extends Component $cuenta->estado = $this->estado; $cuenta->save(); + Log_historial::create([ + 'user_id' => Auth::user()->id, + 'detalle' => 'El usuario ha creado la cuenta ' . $cuenta->correo + ]); + if ($this->estado === 'activo') { $servicioPantallas = Servicio::find($this->servicio_newCuenta)->pantallas; @@ -487,8 +493,24 @@ class ShowPlanes extends Component public function eliminarCuentas() { + $cuentas = Cuentas::whereIn('id', $this->delete_1)->get(); + + if ($cuentas) { + forEach ($cuentas as $cuenta) { + Log_historial::create([ + 'user_id' => Auth::user()->id, + 'detalle' => 'El usuario ha eliminado la cuenta ' . $cuenta->correo + ]); + } + } $consulta_cuentas = Cuentas::whereIn('id', $this->delete_1)->delete(); + + $this->alert('success', 'Cuentas eliminadas correctamente!', [ + 'position' => 'top' + ]); + + $this->delete_1 = []; } public function openAdd() diff --git a/database/migrations/2024_03_01_095422_create_log_historials_table.php b/database/migrations/2024_03_01_095422_create_log_historials_table.php new file mode 100644 index 0000000..ef84be7 --- /dev/null +++ b/database/migrations/2024_03_01_095422_create_log_historials_table.php @@ -0,0 +1,27 @@ +id(); + + $table->text('detalle'); + $table->unsignedBigInteger('user_id'); + + $table->timestamps(); + + $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + }); + } + + public function down() + { + Schema::dropIfExists('log_historial'); + } +}; diff --git a/resources/views/livewire/show-log-historial.blade.php b/resources/views/livewire/show-log-historial.blade.php index eec8a24..2efd220 100644 --- a/resources/views/livewire/show-log-historial.blade.php +++ b/resources/views/livewire/show-log-historial.blade.php @@ -1,28 +1,46 @@
| Nombre | @@ -119,8 +109,10 @@ - +
|---|