bump.
Nov 20, 2017
5
Level 13
use timestamp as primary key
For some kind of realtime chat I only need to store the last 5 messages in mySQL. I'm using this kind of table layout:
https://puu.sh/yq5yz/2f1c8f192b.png
My model:
protected $fillable = [
'id',
'user_id',
'message',
];
protected $dates = [
'id',
];
public $timestamps = false;
Inserting a new chat messages works fine using:
$new_chat = new Chat();
$new_chat->user_id = 1;
$new_chat->message = $request->message;
$new_chat->save();
but when I try to get the timestamp from this new created entry it returns:
Log::info($new_chat->id); -> 0
Log::info(Carbon::create($new_chat->id)->timestamp); -> -62139158388
Inside the database itself, the timestamps are stored correctly (see: https://puu.sh/yq5Ho/265154d13f.png ). I just need to get the timestamp of them for some websockets stuff.
Please or to participate in this conversation.