File: /var/www/vhost/disk-apps/dev-beg.teky.com.co/app/Http/Controllers/LogsController.php
<?php
namespace App\Http\Controllers;
use App\Log;
use DataTables;
use App\Module;
use Illuminate\Http\Request;
class LogsController extends Controller
{
public function createLog($data_operation, $registry_id, $module_id, $operation_id, $user_id){
if($module_id == 2){
$data = json_decode($data_operation);
if(isset($data->password)){
$data->password = '*****';
}
}
Log::create([
"data_operation" => $module_id == 2 ? json_encode($data) : $data_operation,
"registry_id" => $registry_id,
"module_id" => $module_id,
"operation_id" => $operation_id,
"user_id" => $user_id,
]);
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
abort_unless(\Gate::allows('log_access'), 403);
$modules = Module::where('active', 1)->get();
return view('logs.list', compact('modules'));
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function showByRegistry($registry_id,$module_name)
{
abort_unless(\Gate::allows('log_show'), 403);
$module = Module::where('name',$module_name)->first();
if(!$module){
return redirect()->back();
}
abort_unless(\Gate::allows($module->name_gate), 403);
$logs = Log::where([['registry_id',$registry_id],['module_id',$module->id]])->with(['module','operation','user'])->latest('created_at')->limit(1)->get();
if(!count($logs)){
return redirect()->back();
}
return view('logs.show', compact('logs'));
}
public function showByModule($module_id,$start_date,$final_date)
{
abort_unless(\Gate::allows('log_access'), 403);
$logs = Log::where([['module_id',$module_id]])
->with(['module','operation','user'])
->whereBetween('created_at', [$start_date." 00:00:00", $final_date." 23:59:59"]);
return DataTables::of($logs)
->make(true);
}
}