From 408dc67ba5081d73a5751eed831c96d677d0f6aa Mon Sep 17 00:00:00 2001 From: Dries Vints Date: Wed, 8 Sep 2021 15:12:06 +0200 Subject: [PATCH 1/2] Revert PR #38552 (#38711) --- .../Auth/Notifications/ResetPassword.php | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/Illuminate/Auth/Notifications/ResetPassword.php b/src/Illuminate/Auth/Notifications/ResetPassword.php index 15c8ff37abb9..00042d19c04d 100644 --- a/src/Illuminate/Auth/Notifications/ResetPassword.php +++ b/src/Illuminate/Auth/Notifications/ResetPassword.php @@ -59,31 +59,20 @@ public function via($notifiable) */ public function toMail($notifiable) { - $url = $this->resetUrl($notifiable); - if (static::$toMailCallback) { - return call_user_func(static::$toMailCallback, $notifiable, $this->token, $url); + return call_user_func(static::$toMailCallback, $notifiable, $this->token); } - return $this->buildMailMessage($url); - } - - /** - * Get the password reset URL for the given notifiable. - * - * @param mixed $notifiable - * @return string - */ - protected function resetUrl($notifiable) - { if (static::$createUrlCallback) { - return call_user_func(static::$createUrlCallback, $notifiable, $this->token); + $url = call_user_func(static::$createUrlCallback, $notifiable, $this->token); } else { - return url(route('password.reset', [ + $url = url(route('password.reset', [ 'token' => $this->token, 'email' => $notifiable->getEmailForPasswordReset(), ], false)); } + + return $this->buildMailMessage($url); } /** From d73de59683bf9bc1dd6000420f29379b36aaed9e Mon Sep 17 00:00:00 2001 From: Italo Date: Wed, 8 Sep 2021 10:16:47 -0300 Subject: [PATCH 2/2] Adds the `valueOfFail()`. (#38707) --- src/Illuminate/Database/Eloquent/Builder.php | 13 +++++++++++ .../Database/DatabaseEloquentBuilderTest.php | 23 +++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index cd64abbfc1a3..15075432e492 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -570,6 +570,19 @@ public function value($column) } } + /** + * Get a single column's value from the first result of the query or throw an exception. + * + * @param string|\Illuminate\Database\Query\Expression $column + * @return mixed + * + * @throws \Illuminate\Database\Eloquent\ModelNotFoundException + */ + public function valueOrFail($column) + { + return $this->firstOrFail([$column])->{Str::afterLast($column, '.')}; + } + /** * Execute the query as a "select" statement. * diff --git a/tests/Database/DatabaseEloquentBuilderTest.php b/tests/Database/DatabaseEloquentBuilderTest.php index 3ec4b97547d1..8e36ff1dc48e 100755 --- a/tests/Database/DatabaseEloquentBuilderTest.php +++ b/tests/Database/DatabaseEloquentBuilderTest.php @@ -251,6 +251,29 @@ public function testValueMethodWithModelNotFound() $this->assertNull($builder->value('name')); } + public function testValueOrFailMethodWithModelFound() + { + $builder = m::mock(Builder::class.'[first]', [$this->getMockQueryBuilder()]); + $mockModel = new stdClass; + $mockModel->name = 'foo'; + $builder->shouldReceive('first')->with(['name'])->andReturn($mockModel); + + $this->assertSame('foo', $builder->valueOrFail('name')); + } + + public function testValueOrFailMethodWithModelNotFoundThrowsModelNotFoundException() + { + $this->expectException(ModelNotFoundException::class); + + $builder = m::mock(Builder::class.'[first]', [$this->getMockQueryBuilder()]); + $model = $this->getMockModel(); + $model->shouldReceive('getKeyType')->once()->andReturn('int'); + $builder->setModel($model); + $builder->getQuery()->shouldReceive('where')->once()->with('foo_table.foo', '=', 'bar'); + $builder->shouldReceive('first')->with(['column'])->andReturn(null); + $builder->whereKey('bar')->valueOrFail('column'); + } + public function testChunkWithLastChunkComplete() { $builder = m::mock(Builder::class.'[forPage,get]', [$this->getMockQueryBuilder()]);