Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Error 'The name is already used' on crud update #5241

Closed
AndreNeny opened this issue Jul 29, 2023 · 6 comments
Closed

[Bug] Error 'The name is already used' on crud update #5241

AndreNeny opened this issue Jul 29, 2023 · 6 comments
Labels

Comments

@AndreNeny
Copy link

Bug report

What I did

my model has two keys :
primary key Id
unique key chantiers_nom_unique (firm_code + chantier_name)
nothing special on standard crud, no implementation of the save method.

What I expected to happen

standard crud update () when another field (not firm_code or chantier_name) is modified in the model
and message "item has been updated with success"

What happened

Error "The name already used"

What I've already tried to fix it

/

Is it a bug in the latest version of Backpack?

I don't think so but my double key is recent.

After I run composer update backpack/crud the bug... is it still there?
Yes

Backpack, Laravel, PHP, DB version

    "backpack/crud": "5.1.2",
    "backpack/logmanager": "^4.0",
    "backpack/permissionmanager": "^6.0",
    "backpack/pro": "^1.0",

    "laravel/framework": "^9.2",
    "laravel/sanctum": "^2.14.1",
    "laravel/tinker": "^2.7",
    "laravel/ui": "^3.4",

When I run php artisan backpack:version the output is:

PHP VERSION:

PHP 8.1.20 (cli) (built: Jun 7 2023 08:21:17) (NTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.1.20, Copyright (c) Zend Technologies

LARAVEL VERSION:

v9.17.0@091e287678ac723c591509ca6374e4ded4a99b1c

BACKPACK VERSION:

5.1.2@a15f93a784e8d130f5ea5c3341fb7bca1f3c25e3

Thank's to look at this !

@welcome
Copy link

welcome bot commented Jul 29, 2023

Hello there! Thanks for opening your first issue on this repo!

Just a heads-up: Here at Backpack we use Github Issues only for tracking bugs. Talk about new features is also acceptable. This helps a lot in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.

Backpack communication channels:

  • Bug Reports, Feature Requests - Github Issues (here);
  • Quick help (How do I do X) - Gitter Chatroom;
  • Long questions (I have done X and Y and it won't do Z wtf) - Stackoverflow, using the backpack-for-laravel tag;
  • Showing off something you've made, asking for opinion on Backpack/Laravel matters - Reddit;

Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.

Thank you!

--
Justin Case
The Backpack Robot

@AndreNeny
Copy link
Author

my rules on ChantiersRequest
public function rules()
{
return [
'nom' => [
'required',
'min:3',
'max:40',
Rule::unique('chantiers')->where(function ($query) { // Clé unique composée : societe_id + nom
return $query->where('societe_id', $this->societe_id);
}),
],
'image' => 'max:65535',
'latitude' => 'required|numeric',
'longitude' => 'required|numeric'
];
}

@jcastroa87
Copy link
Member

Hello @AndreNeny i dont think this is a backpack bug because is about rules, Backpack didnt handle it:

if i see your rules did you try with ignore?

public function rules()
{
return [
  'nom' => [
  'required',
  'min:3',
  'max:40',
  Rule::unique('chantiers')->where(function ($query) { // Clé unique composée : societe_id + nom
  return $query->where('societe_id', $this->societe_id)->ignore([here_the_current_id]);
  }),
  ],
  'image' => 'max:65535',
  'latitude' => 'required|numeric',
  'longitude' => 'required|numeric'
  ];
}

Cheers.

@pxpm
Copy link
Contributor

pxpm commented Aug 7, 2023

Doing a cleanup of stalled issues.

Please @AndreNeny report back if you were not able to fix it and we can re-open this.

Cheers

@pxpm pxpm closed this as completed Aug 7, 2023
@AndreNeny
Copy link
Author

AndreNeny commented Aug 7, 2023 via email

@AndreNeny
Copy link
Author

Hello Jorge, That's good with your advice. Thank's a lot !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

No branches or pull requests

3 participants