Comments (5)
I added custom eloquent model support #21 , so using your own model should work better now hopefully...
https://github.com/danielme85/laravel-log-to-db#custom-eloquent-model
Please feel free to test it out with the master branch!
from laravel-log-to-db.
Hi mr DonSalvador,
so you're talking about this right..?
https://laravel.com/docs/7.x/eloquent#observers
I did manage to get a model observer to work.
\App\Providers\AppServiceProvider.php
namespace App\Providers;
use App\Observers\LogObserver;
use danielme85\LaravelLogToDB\LogToDB;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
LogToDB::model()->observe(LogObserver::class);
}
}
Custom observer class:
\App\Observers\LogObserver.php
class LogObserver
{
/**
* Handle the Log "created" event.
*
* @return void
*/
public function created($log)
{
dd($log->toArray());
}
}
Log::info("hello world...");
Result:
[2020-04-24 12:06:37][99] Processing: danielme85\LaravelLogToDB\Jobs\SaveNewLogEvent
array:10 [
"message" => "hello world..."
"level" => 200
"level_name" => "INFO"
"channel" => "local"
"datetime" => "2020-04-24 12:06:27:0427"
"extra" => array:1 [
"memory_peak_usage" => "18 MB"
]
"unix_time" => 1587744397
"updated_at" => "2020-04-24 12:06:37"
"created_at" => "2020-04-24 12:06:37"
"id" => 48316
]
Is this what you had in mind?
from laravel-log-to-db.
Hi @danielme85
Yes! that work.
Not fired if I use my own model.
And I is mandatory to use the DBLog model in the observer class too.
Argument 1 passed to App\Observers\LogObserver::created() must be an instance of App\Models\Log, instance of danielme85\LaravelLogToDB\Models\DBLog given
Works with AppServiceProvider like you said. Thanks
from laravel-log-to-db.
Oh yeah... let me look into better support for your own models.
I think there is a better way.
from laravel-log-to-db.
dev-master and v2.3.x have better support for custom eloquent models now.
Thanks for pointing it out @DonSalvador
from laravel-log-to-db.
Related Issues (20)
- "Cleanup" functions not working when using mongoDB HOT 1
- Add Console command for log pruning
- \Log::error not work HOT 3
- Array to string conversion on error logging HOT 4
- Add Lumen support HOT 2
- Laravel 7: Throwable HOT 3
- Laravel 6. Serialization of 'Closure' is not allowed HOT 2
- Log Cleaner does not read collection setting HOT 3
- Internal migration HOT 6
- Does not work correctly with Laravel Octane HOT 3
- Url issue HOT 1
- If queue or database is unavailable, emergency logging should be used HOT 3
- Wrong method check HOT 1
- Use database loging as optional? HOT 3
- getContextAttribute requires a value HOT 2
- Error on Lumen 9.1.2 and PHP 8.1 HOT 3
- Compatibility with Laravel 10.x and Monolog 3.x HOT 2
- Infinite circular log writes on database exception inside the job HOT 2
- Release for Laravel 11 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-log-to-db.