Is the updated_by field listed in the $fillable array in the Service model?
Updating laravel foreign keys updated_by in services table
I have created two tables that are users and services. Services table have two foreign keys as created_by and updated_by. Now when i try to update the field updated_by in services table it is not updating infact it is returning null value.
Thats the Services model specifying the relationship with users.
public function user(): BelongsTo { return $this->belongsTo(User::class, 'created_by'); }
Thats index, store and update method
public function index() { $service = Service::with('user')->latest()->get(); return view('admin.service.index', compact('service')); }
Service::insert([ 'created_by' => auth()->user()->id, 'description' => $request->description 'title' => $request->title, 'slug' => strtolower(str_replace(' ', '-',$request->title)), 'created_at' => Carbon::now(), 'image' => $save_url, ]);
Update Method
Service::findOrFail($service_id)->update([ 'updated_by' => auth()->user()->id, 'description' => $request->description, 'title' => $request->title, 'slug' => strtolower(str_replace(' ', '-',$request->title)), 'updated_at' => Carbon::now(), 'image' => $save_url, ]);
Thats the table in Index.blade.php
Please or to participate in this conversation.