我有一个班级class DashBoardController extends Controller
{
public $str;
public function __construct($str)
{
$this->str = $str;
echo $this->str;
}
public function dashboard(Request $request)
{
$obj = new DashBoardController("hello");
die;
}
}
为
{{1}}
它给我的例外是
类App \ Modules \ User \ Controllers \ DashBoardController中无法解析的依赖项解析[参数#0 [$ str]]
这里有什么错误?
答案 0 :(得分:1)
如果在加载时没有注入依赖项,则需要传递默认值。
class DashBoardController extends Controller
{
public $str;
public function __construct($str='')
{
$this->str = $str;
echo $this->str;
}
public function dashboard(Request $request)
{
$obj = new DashBoardController("hello");
die;
}
}