In my project current_profile is a JSON object column for EmployeePromotionAndShifting model. I want to update a key named division_i of current_profile column.
The JSON object is like this:
"current_profile" =>
{"staff_id":"2927","division_id":"84","department_id":"200","unit_id":null}
I am getting an error:
"This database engine does not support JSON operations." at
vendor\yajra\laravel-oci8\src\Oci8\Query\Grammars\OracleGrammar.php:1
Code to update in database!
EmployeePromotionAndShifting::where('staff_id',$currentProfile['staff_id'])->update(['current_profile->division_id' => 555,]);
I want to update division_id key of current_profile column for a particular row.
Related
$wor= Warehouse_other_receive::where('or_no', $id)->first();
Warehouse_other_receive_detail::where('or_no', $id)->update(array('or_date'=>$wor->or_date);
$wor->update(['status' => '1']);
My goal is to get data and update it in one query in my Laravel project. On the first-line I get data from wharehouse_other_receive model, on the second line update data form first line get data the third line is after second-line code update Warehouse_other_receive model
I am using Laravel 5.8. I have this function in my api controller
$bill=new Bill();
$bill->msisdn =$msisdn;
$bill->trans_id =$transReference;
$bill->ext_id =$ref_id;
$bill->amount=$game_check->amount;
$bill->answer=$useroption;
$bill->game_code=$useresponse;
$bill->is_complete_transactions =1;
$bill->billing_channel="Unity-7799";
$bill->save();
I have another table user_response, the model class is User_Response. It has these fields:
id, msisdn, answer, answer_code
I want to get the last record from $bill=new Bill() where $bill->msisdn is equal to msisdn in User_Response. Then update answer in User_Response with $bill->answer.
Please how do I achieve this?
So save() method always return the recently save data in database.
if you do $bill->save()
so the last inserted record can be achive by the same object you trigger save() from.
For eg i need last inserted id from the database after insertion.
so
$bill = new Bill();
$bill->myFileds = $request->myfields;
$bill->save();
$lastInsertedId = $bill->id;
as you can see from above code. the last inserted record is $bill. you can use it for User_Repsonse
User_Response::where('msisdn',$bill->msisdn)->update(['answer'=>$bill->answer]);
Here you go
In the following code, The Users table has a related table phoneNumbers. When I retrieve a list of all users like this,
return Person::with('phoneNumbers')->get();
everything works fine. However, when I attempt to specify a list of columns to return from the Person table, the phone_number returns empty.
return Person::with('phoneNumbers')
->get(['fname','lname', 'email']);
If I add the number field or phone_number.number to the get array, then I get an error as an undefined column. What is the laravel way of handling this.
Try this:
return Person::select(['your_foreign_key', 'fname','lname', 'email'])
->with('phoneNumbers')get();
I'm trying to update additional column data in a pivot table in a many to many relationship.
I have two tables - reservation and resource linked with a pivot table. I can attach and am working with the model. However I'm struggling to update one of the additional columns in the pivot table.
I have an object: '$reservation' From that object I created another object $resources using:
$resources = $reservation->resource()->get();
I'm then iterating through $resources using a foreach loop as follows
foreach($resources as $resource ) {...}
I then want to update a column called gcal_id and am using the following:
$resource->pivot->gcal_id = "TEST";
$resource->save();
If I var_dump the model I can see the property exists to the correct value but in the database itself the entry is not being updated - so the save is not working
I have the columns listed in both sides of the relationship with this:
->withPivot('start', 'end', 'quantity', 'product_id','gcal_id')
Given I have the resource object how can I update a column correctly in the pivot table and save to database?
Thanks
After that you set the attribute on the pivot:
$resource->pivot->gcal_id = "TEST";
You seem to save the resource and not the pivot:
$resource->save();
If you want the pivot to be saved, saving the resource is not enough. Call save on the pivot instead:
$resource->pivot->gcal_id = "TEST";
$resource->pivot->save();
An alternative instead of save method, is the method Illuminate\Database\Eloquent\Relations\BelongsToMany\updateExistingPivot()
$reservation->resource()->updateExistingPivot($resource_id, ['gcal_id' => 'TEST']);
Or
$reservation->resource()->updateExistingPivot([1, 4, 5, 6], ['gcal_id' => 'TEST']);
This work for me in Laravel 4.2
How can you run a Sequel migration that updates a newly added column with a value from the row?
The Sequel documentation shows how you can update the column with a static value:
self[:artists].update(:location=>'Sacramento')
What I need to do is update the new column with the value of the ID column:
something like:
self[:artists].each |artist| do
artist.update(:location => artist[:id])
end
But the above doesn't work and I have been unable to figure out how to get it to go.
Thanks!
artist in your loop is a Hash, so you are calling Hash#update, which just updates the Hash instance, it doesn't modify the database. That's why your loop doesn't appear to do anything.
I could explain how to make the loop work (using all instead of each and updating a dataset restricted to the matching primary key value), but since you are just assigning the value of one column to the value of another column for all rows, you can just do:
self[:artists].update(:location=>:id)
if you need update all rows of a table, because it is a new column that need be populate
artists = DB[:artists]
artists.update(:column_name => 'new value')
or if you need, update only a unique row into your migration file you can:
artists = DB[:artists]
artists.where(:id => 1).update(:column_name1 => 'new value1', :column_name2 => "other")