Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

princeoo7's avatar

how to access time stamp in api controller for pivot table

As the title for the question says, How can i access the timestamp for a pivot table.

My model for user:

public function histories() {
        return $this->belongsToMany(UserFeed::class, 'histories')->withTimestamps();
    }

API Call controller :

$records = Auth::user()
            	->histories()
		->latest()
		->paginate(config("app.rec_limit"));

But I cannot either see the pivot table nor the timestamp data for the records been fetched !

what I get is only history records and nothing else.

0 likes
2 replies
princeoo7's avatar

I clearly said I need it in api controller so the data needs to be part of api json output

anyways the issue is solved.

Please or to participate in this conversation.