Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用eloquent laravel连接具有数组id的表 我之所以将常量数据存储到config中,是因为我听到一些人说,它比将其添加到表中并加入它们要快_Php_Laravel - Fatal编程技术网

Php 如何使用eloquent laravel连接具有数组id的表 我之所以将常量数据存储到config中,是因为我听到一些人说,它比将其添加到表中并加入它们要快

Php 如何使用eloquent laravel连接具有数组id的表 我之所以将常量数据存储到config中,是因为我听到一些人说,它比将其添加到表中并加入它们要快,php,laravel,Php,Laravel,在my config/products.php中 return [ [ 'id' => 1, 'title' => 'test1', 'name' => 'name1' ], [ 'id' => 2, 'title' => 'test2', 'name' => 'name2' ], [ 'id' => 3

在my config/products.php中

return [
    [
        'id' => 1,
        'title' => 'test1',
        'name' => 'name1'
    ],
    [
        'id' => 2,
        'title' => 'test2',
        'name' => 'name2'
    ],
    [
        'id' => 3,
        'title' => "test3",
        'name' => 'name3'
    ]
];
在我的模型中

class Products extends Model
{
    protected $table = 'products';

    public function getNameType()
    {
        return collect(config('products'))->where('id', $this->type)->first();
    }
}
下面是我的示例表产品

id  name   type
1    pro1   1
如何在控制器中执行类似操作

  $value = collect(config('products'));
  $products = Products::leftJoin($value)->where('products.type', '=', $value.id);
我想加入像这样的团队

id  name   type  title    pro.name
1    pro1   1    test1  name1

您需要将此配置数组添加到一个表中,并将该表与products表连接。我知道我可以将其添加到表中,但如果他们有任何方法可以这样连接数据?是的,通过一些额外的技巧,它可以作为输出,但这不是正确的方法,所以我将常量数据存储到配置中的原因是,我听到一些人说它将比将其添加到表中并加入它们更快,这是真的吗?是的,有些人这样说,但这是针对数组的,而不是针对数组和加入等