Skip to content

Commit

Permalink
Bugfix - Unique Validation in PostgreSQL (#19)
Browse files Browse the repository at this point in the history
* Fix unique validation in Postgres

* wip

* wip

* Inline the subscriber unique email rule.

Co-authored-by: Joshua Franks <[email protected]>
Co-authored-by: David Field <[email protected]>
  • Loading branch information
3 people authored Jun 11, 2020
1 parent 116e59c commit b48cd8b
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/Http/Requests/SubscriberRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,27 @@

namespace Sendportal\Base\Http\Requests;

use Illuminate\Database\Query\Builder;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

/**
* @property-read string $subscriber
*/
class SubscriberRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
public function rules(): array
{
return [
'email' => [
'required',
'email',
'max:255',
'unique:subscribers,email,' . $this->subscriber . ',id,workspace_id, ' . auth()->user()->currentWorkspace()->id
Rule::unique('subscribers', 'email')
->ignore($this->subscriber, 'id')
->where(static function (Builder $query) {
$query->where('workspace_id', auth()->user()->currentWorkspace()->id);
})
],
'first_name' => [
'max:255',
Expand Down

0 comments on commit b48cd8b

Please sign in to comment.