首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何删除扩展类中的父静态方法

问如何删除扩展类中的父静态方法
EN

Stack Overflow用户
提问于 2018-06-13 11:17:22
回答 1查看 55关注 0票数 0

这是我的模型

代码语言:javascript
复制
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Associate extends Model
{
   // some code       
}

在控制器中,我使用这个模型,类似于

代码语言:javascript
复制
<?php

namespace App\Http\Controllers;

use App\Models\Associate;
use Illuminate\Http\Request;

class AssociatesController extends Controller
{
    protected $associate;

    public function __construct(Associate $associate)
    {
        $this->associate = $associate;
    }

    public function edit(Request $request, $id)
    {
        $associate = $this->associate->with('some-relation')->find($id);
        // other part of code
    }
}

当我习惯于在控制器edit方法中使用phpunit进行测试时,我不能模仿with方法,因为它是Illuminate\Database\Eloquent\Model的静态方法。

我的问题有办法删除父类的某些方法??

EN

回答 1

Stack Overflow用户

发布于 2018-06-13 12:36:04

来自拉拉维尔的文档

代码语言:javascript
复制
static Builder|Model with(array|string $relations)
Being querying a model with eager loading.

来自Php 文档

代码语言:javascript
复制
<?php
class A {
    public static function who() {
        echo __CLASS__;
    }
    public static function test() {
        static::who(); // Here comes Late Static Bindings
    }
}

class B extends A {
    public static function who() {
        echo __CLASS__;
    }
}

B::test();
?>

上面的示例将输出:

B

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50835879

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档