From 6d68d6df6ded629749a74b34f1c3f5d82cec74f6 Mon Sep 17 00:00:00 2001 From: James Alton Date: Thu, 5 Mar 2020 16:21:23 -0700 Subject: [PATCH] Ardent: Laravel 6 support --- README.md | 14 +++--- composer.json | 12 ++--- src/Ardent/Ardent.php | 16 +++---- src/Ardent/Facades/Ardent.php | 14 ++++++ .../Providers/ArdentServiceProvider.php | 45 +++++++++++++++++++ 5 files changed, 80 insertions(+), 21 deletions(-) create mode 100644 src/Ardent/Facades/Ardent.php create mode 100644 src/Ardent/Providers/ArdentServiceProvider.php diff --git a/README.md b/README.md index 00a1d91..5f3cc03 100644 --- a/README.md +++ b/README.md @@ -85,13 +85,13 @@ Route::post('register', function() { 'password_confirmation' => 'required|min:6' ); - $validator = Validator::make(Input::all(), $rules); + $validator = Validator::make(request()->all(), $rules); if ($validator->passes()) { User::create(array( - 'name' => Input::get('name'), - 'email' => Input::get('email'), - 'password' => Hash::make(Input::get('password')) + 'name' => request()->get('name'), + 'email' => request()->get('email'), + 'password' => Hash::make(request()->get('password')) )); return Redirect::to('/')->with('message', 'Thanks for registering!'); @@ -321,9 +321,9 @@ Let's see it action. Consider this snippet of code: ```php $user = new User; -$user->name = Input::get('name'); -$user->email = Input::get('email'); -$user->password = Hash::make(Input::get('password')); +$user->name = request()->get('name'); +$user->email = request()->get('email'); +$user->password = Hash::make(request()->get('password')); $user->save(); ``` diff --git a/composer.json b/composer.json index a3fb066..8203fd7 100644 --- a/composer.json +++ b/composer.json @@ -19,12 +19,12 @@ "support": { "issues": "https://github.com/laravelbook/ardent/issues" }, - "require": { - "illuminate/support": "~5.1", - "illuminate/database": "~5.1", - "illuminate/validation": "~5.1", - "illuminate/events": "~5.1", - "illuminate/hashing": "~5.1" + "require": { + "illuminate/support": ">5.1", + "illuminate/database": ">5.1", + "illuminate/validation": ">5.1", + "illuminate/events": ">5.1", + "illuminate/hashing": ">5.1" }, "autoload": { "psr-4": { diff --git a/src/Ardent/Ardent.php b/src/Ardent/Ardent.php index e76775f..9a537cc 100755 --- a/src/Ardent/Ardent.php +++ b/src/Ardent/Ardent.php @@ -8,7 +8,7 @@ use Illuminate\Events\Dispatcher; use Illuminate\Hashing\BcryptHasher; use Illuminate\Support\MessageBag; -use Illuminate\Support\Facades\Input; +use Illuminate\Http\Request; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Validator; use Illuminate\Database\Eloquent\Model; @@ -77,7 +77,7 @@ abstract class Ardent extends Model { public static $throwOnFind = false; /** - * If set to true, the object will automatically populate model attributes from Input::all() + * If set to true, the object will automatically populate model attributes from request()->all() * * @var bool */ @@ -423,7 +423,7 @@ public function belongsTo($related, $foreignKey = NULL, $otherKey = NULL, $relat } if (is_null($foreignKey)) { - $foreignKey = snake_case($relation).'_id'; + $foreignKey = Str::snake($relation).'_id'; } // Once we have the foreign key names, we'll just create a new Eloquent query @@ -457,7 +457,7 @@ public function morphTo($name = null, $type = null, $id = null, $ownerKey = null $backtrace = debug_backtrace(false); $caller = ($backtrace[1]['function'] == 'handleRelationalArray')? $backtrace[3] : $backtrace[1]; - $name = snake_case($caller['function']); + $name = Str::snake($caller['function']); } // Next we will guess the type and ID if necessary. The type and IDs may also @@ -481,7 +481,7 @@ public function getAttribute($key) { $attr = parent::getAttribute($key); if ($attr === null) { - $camelKey = camel_case($key); + $camelKey = Str::camel($key); if (array_key_exists($camelKey, static::$relationsData)) { $this->relations[$key] = $this->$camelKey()->getResults(); return $this->relations[$key]; @@ -572,7 +572,7 @@ public function validate(array $rules = array(), array $customMessages = array() $customAttributes = (empty($customAttributes))? static::$customAttributes : $customAttributes; if ($this->forceEntityHydrationFromInput || (empty($this->attributes) && $this->autoHydrateEntityFromInput)) { - $this->fill(Input::all()); + $this->fill(request()->all()); } $data = $this->getAttributes(); // the data under validation @@ -591,8 +591,8 @@ public function validate(array $rules = array(), array $customMessages = array() $this->validationErrors = $this->validator->messages(); // stash the input to the current session - if (!self::$external && Input::hasSession()) { - Input::flash(); + if (!self::$external && request()->hasSession()) { + request()->flash(); } } } diff --git a/src/Ardent/Facades/Ardent.php b/src/Ardent/Facades/Ardent.php new file mode 100644 index 0000000..d8eb8f3 --- /dev/null +++ b/src/Ardent/Facades/Ardent.php @@ -0,0 +1,14 @@ +package('LaravelArdent/ardent'); + } + + /** + * Register the service provider. + * + * @return void + */ + public function register() + { + // + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return array('ardent'); + } + +} \ No newline at end of file