Skip to content

Commit

Permalink
Use a different Exception Model (#63)
Browse files Browse the repository at this point in the history
* Use a different Exception Model

* Added new connection property to the config

* Update the readme
  • Loading branch information
tylercd100 committed Feb 16, 2018
1 parent 9525131 commit 9f4dd4b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
20 changes: 19 additions & 1 deletion README.md
Expand Up @@ -105,7 +105,24 @@ $mostRecentException = ExceptionModel::orderBy('created_at','DESC')->first();
To change what is recorded in to the database take a look at `config/lern.php`
```php
'record'=>[
'table'=>'vendor_tylercd100_lern_exceptions',
/**
* The Model to use
*/
'model' => \Tylercd100\LERN\Models\ExceptionModel::class,

/**
* Database connection to use. Null is the default connection.
*/
'connection'=>null,

/**
* Database table to use
*/
'table'=>'vendor_tylercd100_lern_exceptions',

/**
* Information to store
*/
'collect'=>[
'method'=>false, //When true it will collect GET, POST, DELETE, PUT, etc...
'data'=>false, //When true it will collect Input data
Expand All @@ -116,6 +133,7 @@ To change what is recorded in to the database take a look at `config/lern.php`
],
],
```
Note: If you change `lern.recorder.model` then `lern.recorder.table` and `lern.recorder.connection` will be ignored unless you extend `\Tylercd100\LERN\Models\ExceptionModel::class`

### Notifications
LERN uses the Monolog library to send notifications. If you need more than the supported notification channels, then you can add your own custom Monolog handlers. To start using any of the supported handlers just edit the provided config file `config/lern.php`.
Expand Down
16 changes: 16 additions & 0 deletions config/lern.php
Expand Up @@ -9,8 +9,24 @@
*/
'class' => \Tylercd100\LERN\Components\Recorder::class,

/**
* The Model to use
*/
'model' => \Tylercd100\LERN\Models\ExceptionModel::class,

/**
* Database connection to use. Null is the default connection.
*/
'connection'=>null,

/**
* Database table to use
*/
'table'=>'vendor_tylercd100_lern_exceptions',

/**
* Information to store
*/
'collect'=>[
'method'=>false, //When true it will collect GET, POST, DELETE, PUT, etc...
'data'=>false, //When true it will collect Input data
Expand Down
11 changes: 10 additions & 1 deletion src/Components/Recorder.php
Expand Up @@ -57,7 +57,16 @@ public function record(Exception $e)
}
}

return ExceptionModel::create($opts);
$class = config('lern.recorder.model');
$class = !empty($class) ? $class : ExceptionModel::class;

$model = new $class();
foreach($opts as $key => $value) {
$model->{$key} = $value;
}

$model->save();
return $model;
} catch (Exception $e) {
$code = (is_int($e->getCode()) ? $e->getCode() : 0);
throw new RecorderFailedException($e->getMessage(), $code, $e);
Expand Down
2 changes: 2 additions & 0 deletions src/Models/ExceptionModel.php
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Model;

class ExceptionModel extends Model {
protected $connection;
protected $table;
protected $guarded = array('id');

Expand All @@ -14,6 +15,7 @@ class ExceptionModel extends Model {

public function __construct(array $attributes = [])
{
$this->connection = config('lern.record.connection');
$this->table = config('lern.record.table');
parent::__construct($attributes);
}
Expand Down

0 comments on commit 9f4dd4b

Please sign in to comment.