My validation rule is...
$rules = [];
foreach($this->request->get('email') as $key=>$value){
$rules['email.'.$key] = 'required|regex:/[a-zA-Z]+#[a-zA-Z]+(\.[a-zA-Z]+)+/|unique:admins,admin_email,'.$this->request->get('admin_id')[$key].',admin_id';
}
Basically, the rule is that it's required, the regex passes, and the email isn't already in use with the exception of if the email is in use by that particular row. However, I'm getting this error message when I run the form:
The email.0 has already been taken.
To be clear, this form has 8 different users and only the first one is giving me this problem. I did a dd() of the rules to see what was different between the validation rules that were being applied, and I didn't see any.
"email.0" => "required|regex:/[a-zA-Z]+#[a-zA-Z]+(\.[a-zA-Z]+)+/|unique:admins,admin_email,0,admin_id"
"email.1" => "required|regex:/[a-zA-Z]+#[a-zA-Z]+(\.[a-zA-Z]+)+/|unique:admins,admin_email,1,admin_id"
"email.2" => "required|regex:/[a-zA-Z]+#[a-zA-Z]+(\.[a-zA-Z]+)+/|unique:admins,admin_email,2,admin_id"
If I update email.0, I don't get this problem. I also don't get this problem with any other rows regardless of whether I update email.0 or not. I can not delete this user as there is a foreign key constraint. To be incredibly clear, the admin_id for this specific admin is 0. Or, in other words, this is how the table looks for this specific entry
admin_id|admin_email
--------+------------
0 | ab#c.d
Edit: Where does Laravel build and run the actual query? If I can do a dd() on the database log I might be able to find what my problem is (see the actual raw query).
I am obviously missing something here - any help would be greatly appreciated!
The unique rule shouldn't be as this:
unique:admins,admin_email,0,admin_id
The zero 0 refers to the value of admin_id column which should be ignored by the unique rule.
So if you have table admins as:
admin_id | admin_email
---------+-------------
1 | a#b.c
2 | b#c.d
3 | c#d.e
and you are updating where admin_email == b#c.d
Your rule should look as
unique:admins,admin_email,2,admin_id
Related
It seems there are lot of posts about this error, but before everything, I must say that I have use SoftDeletes; because I use it and I need it to manage trashed models.
Column 'deleted_at' also exists.
Solution like this saying to remove it does not suit in my case.
I am looking for help to keep use SoftDeletes; but making my request working properly.
Here is my query:
public function scopeWithRowNumber($query)
{
$sub = Model::selectRaw('*, #row:=#row+1 as row')
->orderBy('some_date', 'desc')->toSql();
$query->from(DB::raw("({$sub}) as sub"));
}
The sql exit gives me :
select *, #row:=#row+1 as row from `model_table`
where `model_table`.`deleted_at` is null order by `entry_date` desc
How to fix it?
I finally use this:
withoutGlobalScope('Illuminate\Database\Eloquent\SoftDeletingScope')
on my queries to avoid checking deleted_at column.
The issue is relative to nested queries and seems "normal". In my case, this helps me to fix/avoid error:
> Unknown column 'deleted_at' or column not found.
Maybe it will help someone else.
Also for ranking, I was inspired by this post. But I have to edit my query a little bit because of more conditions with dynamic parameters I added. But this is another subject.
I'm used to compare 2 data, one data has an id and the other data is the one that needs comparing to get the matching datas. see code below.
DB::table('requests')->where('reqItem',$inventory->invItem)->get();
The code shown above displays all requests information that equals to the compared inventory item.
Now what i want to do now is to compare 2 tables without any id (ex. $inventory->invItem). I don't know how to ask this question but i hope you get what i mean. The figure below shows the way i wanted it to be.
You can run this query. Here, 'inventory' is the name of second table (change it accordingly)
DB::table('requests')
->join('inventory', 'requests.reqItem', '=', 'inventory.invItem')
->select('inventory.reqItem')
->get();
I have come across problems with Laravel relations when couple of model ids are identical but another has leading zero and the another has not.
Product ID | Productname
-----------|------------
012345 | Product A
12345 | Product B
If those relations are loaded in the same query, only the first one will be returned and the other will not.
The database columns are strings and in the Product model I have been set the incrementing to false and cast of id attribute to string. Doesn't Laravel's eager loading take leading zeros into account?
I'm not able to change those product ids with leading zeros.
Thanks in advance!
I just run a test on a local laravel installation and I can't reproduce the problem.
Are you sure it is not a problem of the way you structure a query? Because if at any time during your program the $id variable is treated as an integer, the future conversion to string will remove the leading zero.
For example, maybe you get the id from the request:
$productId = $request->get('product_id');
At this point $productId is considered an integer, so if you use productId to query your DB, the leading zero will be removed.
You need to be sure that during the lifecycle of your request that variable is never converted to integer.
You can test the proper query using tinker, and obtaining your products manually:
Product::find('012345');
Product::find('12345');
I have a record group that is using a block item, i.e. where cust_id = :order.cust_id
Sometimes it works, sometimes not.
When I query an existing record, I am able to add a new line and enter the condition code i.e. from the populated record group. But when I enter a new order, the list is empty. I tried to put the code in when-new-record-instance, but I get an error
select profile profile1, profile profile2
from dss.v_unit_conditions
where cust_id = :order.dsp_cust_id
and profile_type = 'UC'
and active = 'Y'
41337 - cannot populate list from record group
If I use that in when-tab-change, then I get the same error.
When you perform query, you acquire :ORDER.DSP_CUST_ID value so Record Group Query fetches something.
On the other hand, when you're entering a new order, I presume that :ORDER.DSP_CUST_ID is empty, query doesn't return anything and raises an error.
It means that :ORDER.DSP_CUST_ID must be known. In order to make the Record Group Query work, consider creating it dynamically, i.e. when :ORDER.DSP_CUST_ID gets its value. As it seems that you're entering it manually, the WHEN-VALIDATE-ITEM might be your choice. Have a look at CREATE_GROUP_FROM_QUERY (and, possibly, POPULATE_GROUP_FROM_QUERY) built-ins. They are described (with examples) in Forms Online Help System.
Hi everyone I use Crystal Reports with Visual Studio 2010 and have the following issue that I can't seem to solve. I have a parameter called name, and I make it so a user chooses from a drop down list of employee names. It is an optional parameter so the user can select nothing in which case I would like the report to show ALL the employees except for the rows that have field Employee name empty. Now I think I got the second part of it down, because I put a formula in the detail section that seems to hide all the empty employees. The problem is that if I leave the parameter unselected the report ONLY shows rows with field Employee name empty. I created a formula like so:
if not (hasvalue(({?Zaduzioc}))) then True
else if
hasvalue({?Zaduzioc}) then
{Inventar_Model_ReportClass.ImeZaduzioca} in {?Zaduzioc} and
{Inventar_Model_ReportClass.Status} = "Aktivno"
Now this exact same formula works for me if I use it with a different report and parameter but that parameter has no empty values so I'm guessing it equates to something like if there are empty values show only those rows if not show everything.
The problem is I can't figure out how to tell it to show everything.
Any help would be greatly appreciated.
I managed to make it work, the problem was in the edit for the parameter I didn't set optional to true, overlooked it and as soon as I did that it all worked. So to recap for anyone with this problem: Make your parameter set optional to true, and put this in the formula for record selection:
if not (hasvalue(({?Parameter}))) then True
else if
hasvalue({?Parameter}) then
{table.column} in {?Parameter}
That should be that.
If you are selecting from a dropdown, you can add an item, Value = ALL, Description = ALL. Set your default to this value. Then in the Selection Expert, add this to your selection query:
....
AND
(IF {?Parameter} = 'ALL' THEN
{databasefield} = {databasefield}
ELSE
{databasefield} = {?Parameter})