Laravel获取列名错误

时间:2018-06-26 08:32:12

标签: php laravel schema

我正在尝试获取数据库表中的所有列名,但我总是会遇到此错误,enter image description here

我的控制器:

public function gettable()
{
    $points = new Point;
    $columns=$points->getTableColumns('points');


    dd($columns->all());
}

我的模型

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Point extends Model
{
    protected $guarded = ['id', 'name']; 

    public function getTableColumns($table)
    {
        return Schema::getColumnListing($table);
    }

}

任何人都可以为我指出适当的解决方案。.

1 个答案:

答案 0 :(得分:1)

存在语法错误

您需要使用单引号'或双引号"而不是撇号 将此行替换为 来自

protected $guarded = [‘id’, ‘name’];

收件人

protected $guarded = ['id', 'name'];