laravel 传递给 Illuminate\\Support\\Collection::__construct() 的参数 1 必须是数组类型,给定的对象

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16905220/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 07:52:28  来源:igfitidea点击:

Argument 1 passed to Illuminate\\Support\\Collection::__construct() must be of the type array, object given

laravellaravel-4

提问by Cheycron Blaine

The Route:

路线:

Route::get('test', array('before' => 'auth', 'as' => 'asd', function()
{
$user = User::find('1');               //Auth::user();
$user->Persona->last_name = 'Blaine';
$user->push();
print_r($user->Persona);
exit;
}));

The User Model:

用户模型:

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {

    protected   $table          = 'ucpm_users';
    public function Persona()
    {
        return $this->belongsTo('Persona','persona');
    }

The Persona Model:

人物模型:

class Persona extends Eloquent 
{

protected   $table          = 'metadata_personas';

public function User()
{
    return $this->hasOne('User', 'persona');
}

public function Telefonos()
{
    return $this->hasMany('Telefonos', 'persona');
}

}

When i Push() the entry model, Laravel trow a ErrorException:

当我 Push() 入口模型时,Laravel 会抛出一个 ErrorException:

Argument 1 passed to Illuminate\Support\Collection::__construct() must be of the type array, object given, called in /var/www/laravel/vendor/laravel/framework/src/Illuminate/Support/Collection.php on line 41 and defined

传递给 Illuminate\Support\Collection::__construct() 的参数 1 必须是数组类型,给定的对象,在 /var/www/laravel/vendor/laravel/framework/src/Illuminate/Support/Collection.php 中调用41 并定义

The entry script (models and Route) are fully working under laravel3, i dont know why this dont work under Laravel4. Any help?

入口脚本(模型和路由)在 Laravel3 下完全有效,我不知道为什么这在 Laravel4 下不起作用。有什么帮助吗?

采纳答案by John

Yeah as I was alluding to in my comment, it was a bug with Laravel. Fortunately Taylor just posted a fix to it on github. Here is the commit:

是的,正如我在评论中所暗示的,这是 Laravel 的一个错误。幸运的是,Taylor 刚刚在 github 上发布了一个修复程序。这是提交:

https://github.com/laravel/framework/commit/f41b86018cd3dc09dd5b216e98c3bfabf0653954

https://github.com/laravel/framework/commit/f41b86018cd3dc09dd5b216e98c3bfabf0653954

Essentially you just need to change line 41 in \vendor\laravel\framework\src\Illuminate\Support\Collection.php to say

本质上,您只需要更改 \vendor\laravel\framework\src\Illuminate\Support\Collection.php 中的第 41 行即可

    return new static(is_array($items) ? $items : array($items));

That should do it :)

那应该这样做:)

回答by Sasha

After experiencing this issue myself I found that the answer give by John works, but requires files created by composerto be modified, which I don't think is an final solution.

在自己经历过这个问题后,我发现 John 给出的答案有效,但需要composer修改由创建的文件,我认为这不是最终的解决方案。

Garbeesuggested that what's actually required is to copy the configfolder within vendor/laralve/lumen-frameworkinto the root folder

Garbee建议实际上需要的是将其中的config文件夹复制vendor/laralve/lumen-framework到根文件夹中

You have to create the folder in the app and copy any configs you need to modify from the framework package into it.

您必须在应用程序中创建文件夹并将您需要修改的任何配置从框架包复制到其中。

Doing this resolved my issues.

这样做解决了我的问题。