Laravel save() method returning true but not updating records
This line in the Opportunity model fixed the issue.
Protected $primaryKey = "opportunityID";
Although it is difficult to understand why it was still possible to retrieve the data and create a new record.
Laravel Model save() & update() Not Saving
You can try any of the following:
Try using static
update
function insteadPatronCoupons::update([
// updates here
]);Remove your
vendor
folder andcomposer.lock
file. Then runcomposer install
to refresh your vendor file
PHP Laravel save() does not update record
Try to get an object instead of collection:
$pet = pets::find($pet['pet_id']);
if (!is_null($pet)) {
$update_pet->pet_breed_id = $pet_new['pet_breed_id'];
$update_pet->save();
}
Also, make sure you're getting the right object by putting dd($pet);
right after the first line of the code.
How to return an updated data after updating in Laravel Model?
return as object instead of boolean type
public function updateStatus(Driver $driver)
{
$driver->update($this->validateStatus());
return $driver;// first way
// return tap($driver)->update($this->validateStatus()); //second way
}
public function validateStatus()
{
return $this->validate(request(), [
'status_id' => 'required|min:1|max:3'
]);
}
Laravel Model-save() returns false but no error
To get the insert queries when $user->save();
error, you can try to catch the exception like this:
try{
$user = new User;
$user->fields = 'example';
$user->save(); // returns false
}
catch(\Exception $e){
// do task when error
echo $e->getMessage(); // insert query
}
Hope this helps :)
laravel database not being updated
You are updating the key used to find the record so it will now use this new key in the query which isn't the current key in the database. You need to use the original keys so it can find the record, then it can update the record with new values.
You would need to do something like this:
protected function setKeysForSaveQuery(Builder $query)
{
$number = $this->original['number'] ?? $this->getAttribute('number');
$type = $this->original['type'] ?? $this->getAttribute('type');
$query->where('number', '=', $number)
->where('type', '=', $type);
return $query;
}
This uses the original values for those keys if they exist and if not uses the current attribute value.
Related Topics
Calculate Size in Bytes of Json Payload Including It in the Json Payload in PHP
General Error: 1364 Field 'User_Id' Doesn't Have a Default Value
How to Prevent a User from Directly Accessing My HTML Page by Writing Url
How to Throw an Error Message If Username Is Already Registered
Update Database After Select Option Change
How to Get the Path to the Laravel Storage Folder
Open Modal from Another Page Laravel
Fatal Error: Call to Undefined Function Sqlsrv_Connect()
How to Change Value of Select Options Based on Another Select Option Selected
Removing Specific Elements from Json Encoded Array by Use of PHP
Get Selected Option in PHP Without Pressing Submit
Dompdf Table Fixed Column Width and Break Long Text
Laravel 5.6 Class App\Http\Controllers\Postcontroller Does Not Exist
What Is the Regular Expression to Validate a Comma Delimited List But Ending With '&' and a Word