Ad
PHP Function Updating All Title Fields For Every Task In Whole Table
I am trying to update the title as a single database task entry. My function currently updates the titles of all the tasks in the table.
public function update(User $user, Task $task, Request $request) {
$data = $this->validate($request, [
'title' => 'required|string|max:255',
]);
Auth::user()->tasks()->update([
'title' => $data['title'],
'is_complete' => 0,
'updated_at' => '2020-01-30 10:39:33',
'created_at' => '2020-01-30 10:39:33'
]);
session()->flash('status', 'Task Completed!');
return redirect('/profile/' . auth()->user()->id);
}
Ad
Answer
Try this
public function update(User $user, Task $task, Request $request)
{
$data = $this->validate($request, [
'title' => 'required|string|max:255',
]);
Auth::user()->tasks()->find($task->id)->update([
'title' => $data['title'],
'is_complete' => 0,
'updated_at' => '2020-01-30 10:39:33',
'created_at' => '2020-01-30 10:39:33',
]);
session()->flash('status', 'Task Completed!');
return redirect('/profile/' . auth()->user()->id);
}
add find($task->id)
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad