问一下数据模型中调用数据表字段的方法,谢谢~

class Video extends Model
{
    //use SoftDeletes; //软删除
    protected $fillable = ['id', 'doid', 'vid','video_url','video_cover','video_width','video_height','video_size']; //白名单

    protected $table = 'pre_home_doing_video';

    protected $primaryKey = 'doid';

在 Video 模型中,要调用数据表里边的字段 vid
就是在下边代码里边, $videoId = 要等于 vid 字段的数据,要怎么写?测试了几次都有问题,麻烦大家啦。

    public function getPlayUrlAttribute(){

        //使用
        $access_key_id = "XXX";
        $access_key_secret = "XXX";
        $region_id = "cn-shanghai";

        try{
            $profile = DefaultProfile::getProfile($region_id,$access_key_id,$access_key_secret);
            $client = new DefaultAcsClient($profile);

            $videoId = " ";
            $req = new GetPlayInfoRequest();
            $req->setVideoId($videoId);
            $req->setAcceptFormat("JSON");
            $response = $client->getAcsResponse($req);

            $list = collect($response->PlayInfoList->PlayInfo)->keyBy('Format');
        }catch (Exception $e){
            exit($e);
        }

        return $list;

    }
什么时候开始都不晚,学到老
《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 1

原来是 模型访问器 并不是…

public function getPlayUrlAttribute()
{
         dd($this->vid);
}


// 需要确保这个数据查询得到
Video::first()->getPlayUrlAttribute();
4年前 评论