I'm getting different time in the created_at column from laravel eloquent and raw sql. The raw sql gives the correct time while the eloquent is wrong. I've already setup the timezone properly and clear config.
Controller
public function index()
{
//returns correct time created_at: "2020-12-08 19:44:30"
$timelines = DB::select('select * from timelines where user_id = ?', [auth()->user()->id]);
//returns wrong time created_at: "2020-12-08T11:44:30.000000Z"
$timelines = Timeline::where('user_id',auth()->user()->id)->get();
return $timelines;
}
Model
class Timeline extends Model
{
use HasFactory;
protected $guarded = [];
}
Database
{
Schema::create('timelines', function (Blueprint $table) {
$table->id();
$table->integer('user_id')->unsigned()->foreign('user_id')->references("id")->on("users")->onDelete("cascade");
$table->integer('source_id');
$table->string('description');
$table->timestamps();
});
}