I am trying to create a relationship in laravel with timestamps. I have this app that allows customers to request a job to a marketplace. When a freelancer on the marketplace finds a job their interested in they propose to complete the job and a new row is queried into the freelancer table.
Here is the code creating the relation:
$marketplace->freelancers()->create([
'request_id' => $id,
'user_id' => $user->id
]);
Here is the Marketplace Model relationship code:
/**
* A request may have multiple freelancers
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function freelancers()
{
return $this->hasMany('App\Models\MainFreelancers')->withTimestamps();
}
Here is the Freelancer Model relationship code:
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function mainMarketplace()
{
return $this->belongsTo('App\Models\MainMarketplace');
}
When trying to run the very first code block I keep getting this Laravel Error:
BadMethodCallException
Call to undefined method Illuminate\Database\Eloquent\Relations\HasMany::withTimestamps()
In the short term, I just manually added a strtotime()
but I'd prefer to utilize what Laravel offers. Does anyone have suggestions?
Note I have reference a previous stackoverflow question here: Timestamps are not updating while attaching data in pivot table But unfortunately it didn't help.