Code Monkey home page Code Monkey logo

Comments (5)

danielme85 avatar danielme85 commented on June 27, 2024 1

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.

danielme85 avatar danielme85 commented on June 27, 2024

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.

DonSalvador avatar DonSalvador commented on June 27, 2024

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.

danielme85 avatar danielme85 commented on June 27, 2024

Oh yeah... let me look into better support for your own models.
I think there is a better way.

from laravel-log-to-db.

danielme85 avatar danielme85 commented on June 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.