If you plan to do this directly in your controller method you can do something like:

public function getUser(Request $request)
{
$request->merge(['id' => $request->route('id')]);
$request->validate([
'id' => [
'required',
'exists:users,id'
]
]);
}

To do this in a custom FormRequest class, add the following:

protected function prepareForValidation() 
{
$this->merge(['id' => $this->route('id')]);
}

or if you use model binding, example is Post, then

protected function prepareForValidation() 
{
$this->merge(['id' => $this->route('post')]);
}

And in your rules method:

public function rules()
{
return [
'id' => [
'required',
'exists:post,id'
]
];
}

References:

https://stackoverflow.com/questions/29578153/how-to-validate-route-parameters-in-laravel-5

--

--

Issue

SQLSTATE[21000]: Cardinality violation: 7 ERROR: ON CONFLICT DO UPDATE command cannot affect row a second time. HINT: Ensure that no rows proposed for insertion within the same command have duplicate constrained values.

Search Problems

Your query is using

insert into <table> (<values> on conflict (<on conflict columns name>) do update set <excluded solumn(s) name>

or in framework laravel is using upsert().

Check Your Table

  1. table must has key (ID primary) and (on conflict columns)
  2. table must has index unique about your on conflict columns.
  3. Check your table’s datas. No duplicate primary key, and no duplicate on conflict columns combine.

--

--

Since I had to face this issue as well, let me share how to make this work. If you have to switch back and forth on mac then this is what works for me.

Let’s say you have multiple PHP versions installed 7.2 and 7.4

Now my current PHP version is 7.4 & I have to switch back to 7.2, steps will be.

  1. brew unlink php@7.4 && brew link php@7.2 --force
  2. nano ~/.zshrc -> Update Export Path From 7.4 to 7.2

--

--

Budiaramdhan Rindi

Currently work as Coder since 2011 and still have to learn. Dota 2 and Football Manager are the games I still play to stay fresh.