1. Go to this page and download the library: Download dzaki236/logging-services library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
public function user()
{
# code...
return $this->belongsTo('App\User','user_id');
}
public function user()
{
# code...
return $this->belongsTo(User::class,'user_id');
}
use App\Models\User;
LogActivity::with('user')->all();
return [
....
'flush' => TRUE, // change this for activate / disactivated flush (default = true)
'limit' => 1000, // change this for limit you want to flush
];
// use App\Services\LogActivitiesServices\MainLogActivitiesServices; // You can use namespacing like this at first line before class on contoller
/**
* Display a listing of the resource.
*
* @return void
*/
public function __construct(MainLogActivitiesServices $logs) {
...
$this->loging = $logs; // variable name (optional)
}
/*
Or, just write the source like this by following code (without namespacing) :
*/
/**
* Display a listing of the resource.
*
* @return void
*/
public function __construct(\App\Services\LogActivitiesServices\MainLogActivitiesServices $logs) {
...
$this->loging = $logs; // variable name (optional)
}
// Example at store function on controller
public function store(Request $request)
{
//if
$data = new Student($request->all());
$con = $data->save();
if ($con) {
# code...
$this->loging->activitylog(true,'add student data'); // if success set to true
return redirect()->route('students.index')->with(['success'=>'Success!']);
} else {
# code...
$this->loging->activitylog(false,'add student data'); // if had failure on proccess set to false
return redirect()->route('students.index')->with(['error'=>'Failure!']);
}
}
// Example at update function on controller
public function update($id,Request $request)
{
//if
$data = Student::find($id)
$data->update($request->all());
$con = $data->save();
if ($con) {
# code...
$this->loging->activitylog(true,'success update student data'); // if success set to true
return redirect()->route('students.index')->with(['success'=>'Success!']);
} else {
# code...
$this->loging->activitylog(false,'failure update student data'); // if had failure on proccess set to false
return redirect()->route('students.index')->with(['error'=>'Failure!']);
}
}
public function store(Request $request)
{
//if
$data = new Student($request->all());
$con = $data->save();
if ($con) {
# code...
$this->loging->activitylog(true,'add student data');
// loging services this is optional, if you want to record a some log activities on your project but somehow you need it or not.
/* try this */
$config = new \Dzaki236\LoggingServices\FileServicesConfig('config.txt');
// the models allowed a constructor to open a new config file (by default : at public path),jsust following the code.
$config->fieldInsert($field,$fill);
/*$field = Field To Scaffolding at txt file!*/
/*$fill = fill this with value (default: request value)*/
// For example anyway field id you can use at some case!..
$config->fieldInsert(array('id','name','class','email'),array($data->id,$request->name,$request->class,$request->email));
return redirect()->route('students.index')->with(['success'=>'Success!']);
} else {
# code...
$this->loging->activitylog(false,'add student data'); // if had failure on proccess set to false
return redirect()->route('students.index')->with(['error'=>'Failure!']);
}
}
# Wrong code
/*
* Do not use return something else before library loaded!.
* just see some an example's here
*/
# wrong example
... action ...
$data = Model::create($request->all());
return $data;// return some from action
$this->logvariables->activitilog(true,'message logs here');
$files = new \Dzaki236\LoggingServices\FileServicesConfig('vendorlogs.txt');
$files->fieldInsert(['field1','field2','field3'],[$request->field1,$request->field2,$request->field3]);
}
# right example
... action ...
$data = Model::create($request->all());
$this->logvariables->activitilog(true,'message logs here');
$files = new \Dzaki236\LoggingServices\FileServicesConfig('vendorlogs.txt');
$files->fieldInsert(['field1','field2','field3'],[$request->field1,$request->field2,$request->field3]);
return $data;// return some from action here
}
bash
$ php artisan logging-services:publish
bash
$ php artisan migrate
bash
$ php artisan migrate:fresh --seed
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.