如何获取模型的字符串名称?

时间:2018-10-24 11:02:08

标签: laravel laravel-5 eloquent

一些Laravel插件会继续引用这样的模型:

App\Vote

当模型定义为app / Vote.php时:

<?php

namespace App;

use DB;
use App\MyAppModel;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
use Cviebrock\EloquentSluggable\Sluggable;
use Illuminate\Validation\Rule;

class Vote extends MyAppModel
{
    use funcsTrait;
    use Sluggable;
    use HasTags;


    protected $table = 'votes';
    protected $primaryKey = 'id';
    public $timestamps = false;
}

我想知道如何从此模型中获取“ App \ Vote”字符串?

Laravel 5.7。

谢谢!

1 个答案:

答案 0 :(得分:1)

您可以这样获得fully qualified class name

\App\Vote::class;

use App\Vote;

Vote::class;