【问题标题】:Laravel Voyager: Call to undefined method TCG\Voyager\ getCoordinates()Laravel Voyager:调用未定义的方法 TCG\Voyager\getCoordinates()
【发布时间】:2020-11-23 19:17:22
【问题描述】:

我在扩展 Voyager 模型的模型中将字段 location 定义为 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

【问题讨论】:

    标签: php laravel voyager


    【解决方案1】:

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

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

    【讨论】:

    • 这并不能解决问题。我现在只使用一条线,就像你展示的那样,但同样的错误仍然发生。我试过做一个 php artisan cache:clear 但这也没有帮助。
    • @MrEduar 从哪里你发现我们不能多次使用use
    猜你喜欢
    • 2020-01-28
    • 2020-10-07
    • 2019-01-10
    • 2020-02-09
    • 2021-12-22
    • 2020-11-13
    • 2017-08-01
    • 2018-10-25
    • 2021-05-10
    相关资源
    最近更新 更多