Issue
I have a model Driver
which have columns: name
, branch
, status_id
, etc.
.Updating is actually fine and working, my problem is how can I return the updated one?
Here's what I tried so far, but it returns a boolean
, resulting of returning an error in my console:
The Response content must be a string or object implementing __toString(), "boolean" given.
public function updateStatus(Driver $driver)
{
return $driver->update($this->validateStatus());
}
public function validateStatus()
{
return $this->validate(request(), [
'status_id' => 'required|min:1|max:3'
]);
}
I expect it should return the all the columns of a driver.
I've been to this link but it doesn't helped. Someone knows how to do this?
Solution
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'
]);
}
Answered By - Jignesh Joisar Answer Checked By - Timothy Miller (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.