首页 > 解决方案 > Laravel Voyager:调用未定义的方法 TCG\Voyager\ getCoordinates()

问题描述

location在扩展 Voyager 模型的模型中将字段定义为 Spatial。但我一直得到一个BadMethodCallException Call to undefined method TCG\Voyager\Models\User::getCoordinates()

当我尝试访问 BREAD 时。

这是模型:

<?php

namespace App;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use TCG\Voyager\Traits\Spatial;

class User extends \TCG\Voyager\Models\User
{
    use Notifiable;
    use Spatial;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

    /**
     * Map Coordinate fields
     */
    protected $spatial = [
        'location'
    ];
}

我还尝试将位置列设置为在模式中键入 GEOMETRY 和 POINT。但我怀疑这与此无关。

我正在使用 Laravel 7 和 Voyager 1.4

标签: phplaravelvoyager

解决方案


你不能有两行use. 这应该可以解决问题。

class User extends \TCG\Voyager\Models\User
{
    use Notifiable, Spatial;
    ...

推荐阅读