这是我的模型
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Associate extends Model
{
// some code
}在控制器中,我使用这个模型,类似于
<?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的静态方法。
我的问题有办法删除父类的某些方法??
发布于 2018-06-13 12:36:04
来自拉拉维尔的文档
static Builder|Model with(array|string $relations)
Being querying a model with eager loading.来自Php 文档
<?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
https://stackoverflow.com/questions/50835879
复制相似问题