简体   繁体   English

Laravel Tinker展示了收藏中的旧价值

[英]Laravel Tinker shows old values from the collection

I have a Laravel model named Campaigns (made using a jenssegers mongodb extension). 我有一个名为Campaigns的Laravel模型(使用jenssegers mongodb扩展名制作)。 When I echo this function: 当我回显此功能时:

$campaigns = Campaigns::all();
echo($campaigns);

I get correct values. 我得到正确的值。 But whenever I try the same from a Command in a schedule or through Artisan Tinker, I get old, non-existing values used before in testing on my local machine. 但是,每当我从日程表中的Command或通过Artisan Tinker尝试进行相同操作时,在本地计算机上进行测试之前,都会得到旧的,不存在的值。 I tried clearing cache and all the config, but it didn't work. 我尝试清除缓存和所有配置,但是没有用。 Any help would be appreciated. 任何帮助,将不胜感激。

Found the answer. 找到了答案。 For anyone with a similar problem: If you run MongoDB on Homestead it creates its own instance on the virtual server and logs in without using any credentials. 对于有类似问题的任何人:如果您在Homestead上运行MongoDB,它将在虚拟服务器上创建自己的实例,并在不使用任何凭据的情况下登录。 Get the ID of your running Vagrant process by typing vagrant global-status and ssh into it by vagrant ssh 1a2b3c . 通过输入vagrant global-status并通过vagrant ssh 1a2b3c ssh来获取正在运行的Vagrant进程的ID。 Then just run Mongo on the virtual server and compare your values. 然后,只需在虚拟服务器上运行Mongo并比较您的值即可。

Because echo print the only variable not the array and $campaigns = Campaigns::all(); 因为echo只输出变量而不是数组,所以$ campaigns = Campaigns :: all(); gives the array. 给出数组。 You should try below way to show the data. 您应该尝试按以下方式显示数据。

$campaigns = Campaigns::all();
print_r($campaigns);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM