Laravel pintruminate class中的覆盖方法
我想在Laravel的Illuminate \ Foundation \ vite
类中覆盖以下方法:
/**
* Generate a script tag for the given URL.
*
* @param string $url
* @return string
*/
protected function makeScriptTag($url)
{
return sprintf('<script type="module" src="%s"></script>', $url);
}
...通过在脚本标签中添加“ defer”属性。我该怎么做,因为这是一个受保护的功能?
I'd like to override the following method in Laravel's Illuminate\Foundation\Vite
class:
/**
* Generate a script tag for the given URL.
*
* @param string $url
* @return string
*/
protected function makeScriptTag($url)
{
return sprintf('<script type="module" src="%s"></script>', $url);
}
...by adding a "defer" attribute to the script tag. How would I go about doing this, as this is a protected function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能是这样的:
在调用“ vite”的控制器中,更改
:
May be like that :
In the controller(s) which call "Vite", change :
by
如果您在应用程序中的另一个位置使用该方法,则SVGTA是正确的。
但是,如果您只想更改该特定的行为,而不是在其他地方使用它,则可以重写原始类,并通过绑定将类替换为
app/providers/appserviceprovider
:另一个可以帮助的帖子:< href =“ https://stackoverflow.com/questions/60841930/laravel-6-7-7-how-can-can-i--i------------- change-a-a- vendor-class”> laravel 6-7我如何覆盖/更改供应商班级?
The svgta is right, if you use that method in another place in your app.
But, if you want to change only that particular behavior, and not to use it in other places, then you can rewrite the original class and replace it by binding changed class to the app in
app/Providers/AppServiceProvider
:Another post that can help: Laravel 6-7 How Can I Override/Change a Vendor Class?