summaryrefslogtreecommitdiff
path: root/src/Models
diff options
context:
space:
mode:
Diffstat (limited to 'src/Models')
-rw-r--r--src/Models/BaseModel.php23
-rw-r--r--src/Models/LogEntry.php46
2 files changed, 69 insertions, 0 deletions
diff --git a/src/Models/BaseModel.php b/src/Models/BaseModel.php
new file mode 100644
index 00000000..cf718e4f
--- /dev/null
+++ b/src/Models/BaseModel.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace Engelsystem\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+abstract class BaseModel extends Model
+{
+ /** @var bool Disable timestamps by default because of "Datensparsamkeit" */
+ public $timestamps = false;
+
+ /**
+ * @param array $attributes
+ * @return BaseModel
+ */
+ public function create(array $attributes = [])
+ {
+ $instance = new static($attributes);
+ $instance->save();
+
+ return $instance;
+ }
+}
diff --git a/src/Models/LogEntry.php b/src/Models/LogEntry.php
new file mode 100644
index 00000000..ca9702de
--- /dev/null
+++ b/src/Models/LogEntry.php
@@ -0,0 +1,46 @@
+<?php
+
+namespace Engelsystem\Models;
+
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Database\Eloquent\Collection;
+
+class LogEntry extends BaseModel
+{
+ /** @var bool enable timestamps for created_at */
+ public $timestamps = true;
+
+ /** @var null Disable updated_at */
+ const UPDATED_AT = null;
+
+ /**
+ * The attributes that are mass assignable.
+ *
+ * @var array
+ */
+ protected $fillable = [
+ 'level',
+ 'message',
+ ];
+
+ /**
+ * @param $keyword
+ * @return Builder[]|Collection|LogEntry[]
+ */
+ public static function filter($keyword = null)
+ {
+ $query = LogEntry::query()
+ ->select()
+ ->orderByDesc('created_at')
+ ->orderByDesc('id')
+ ->limit(10000);
+
+ if (!empty($keyword)) {
+ $query
+ ->where('level', '=', $keyword)
+ ->orWhere('message', 'LIKE', '%' . $keyword . '%');
+ }
+
+ return $query->get();
+ }
+}