I am trying to edit a Projects table but at the moment there is a problem with "default values", I @dd() my $project (after my validateProjects()) inside the controller's edit() and I get this:
App\Models\Project {#1005 ▼
#fillable: array:5 [▶]
#connection: null
#table: null
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: false
+wasRecentlyCreated: false
#escapeWhenCastingToString: false
#attributes: array:1 [▼
"user_id" => 2
]
#original: []
#changes: []
#casts: []
#classCastCache: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#guarded: array:1 [▶]
}
All it seems to gather is the user_id but the rest of the fields seems to be "gone", I get this error:
General error: 1364 Field 'title' doesn't have a default value
Project.php
protected $fillable = [
'user_id',
'title',
'description',
'display_date',
'url'
];
public function update(Project $project, Request $request)
{
$project['user_id'] = auth()->id();
$project->update($this->validateProject($request));
dd($project);
$project->save();
return redirect('/projects')->with('edit_project', 'Project edited, cool!');
}
protected function validateProject($request)
{
return $request->validate([
'title' => ['required'],
'description' => ['required'],
'display_date' => ['required'],
'url' => ['url'],
]);
}