Php 如何删除扩展类中的父静态方法
这是我的模型Php 如何删除扩展类中的父静态方法,php,laravel,Php,Laravel,这是我的模型 <?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class Associate extends Model { // some code } 来自Laravels的 来自Php 上述示例将输出: B我不会对我的扩展类没有with方法。有可能??从中扩展的Controller类没有私有的static with方法,模型有,因此如果您要尝试后期静态绑定,您将在关
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Associate extends Model
{
// some code
}
来自Laravels的
来自Php
上述示例将输出:
B我不会对我的扩展类没有with方法。有可能??从中扩展的Controller类没有私有的static with方法,模型有,因此如果您要尝试后期静态绑定,您将在关联模型中这样做,并且您无法删除static methods这是不可能的静态方法??我从未做过,也没有看到任何示例,不过,我建议在这种情况下,您根本不必这样做,您可以创建一个自定义函数并保存自己,这非常简单和舒适。我可以将我的代码$this->associate->with()更改为其他代码,例如$this->associate->select('id',…)->with(),并可以轻松地对其进行测试。但对我来说,必须找到删除父方法的方法。我认为它可以帮助解决大量的问题。
<?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
}
}
static Builder|Model with(array|string $relations)
Being querying a model with eager loading.
<?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();
?>