admin管理员组文章数量:1333211
I am trying to load my app.js
file inside my wele.blade.php
but I get the following error:
Call to undefined function asset()
This is the instruction I used <script type="text/javascript" src="{{ asset('public/js/app.js') }}"></script>
What can be the problem? I also tried to run the same line without asset()
and it does not work. My .js file is in the location I specified.
Thank you so much!
I am trying to load my app.js
file inside my wele.blade.php
but I get the following error:
Call to undefined function asset()
This is the instruction I used <script type="text/javascript" src="{{ asset('public/js/app.js') }}"></script>
What can be the problem? I also tried to run the same line without asset()
and it does not work. My .js file is in the location I specified.
Thank you so much!
Share Improve this question asked Jun 16, 2018 at 7:37 JoeJoe 2452 gold badges5 silver badges13 bronze badges 3- Have you been modifying which files get loaded by the poser autoloader in any way? – J. Arbet Commented Jun 16, 2018 at 10:37
-
I do not think so. Actually I tried to load it with blade:
{ { Html::script('public/js/app.js') }}
and it seems like it does not recognize the Blade syntax either. – Joe Commented Jun 16, 2018 at 11:30 -
Can you try using
asset('public/app.js')
fromphp artisan tinker
and say if it works? – J. Arbet Commented Jun 16, 2018 at 16:04
3 Answers
Reset to default 1Process:
I am using Laravel 5.5 and had the same problem recently so I did a bit of debugging. Here are the steps:
Since the error was
Call to undefined function asset()
I checked thehelpers.php
in the Laravel repo to see if it existed. https://github./laravel/framework/blob/5.5/src/Illuminate/Foundation/helpers.php#L127 and it did.if (! function_exists('asset')) { /** * Generate an asset path for the application. * * @param string $path * @param bool $secure * @return string */ function asset($path, $secure = null) { return app('url')->asset($path, $secure); } }
I looked on my local copy of Laravel and see if that same line existed, it did.
However my local copy was different than what was on the repo. This is how it looked:
if (! function_exists('asset')) { /** * Generate an asset path for the application. * * @param string $path * @param bool $secure * @return string */ function mixasset($path, $secure = null) { return app('url')->asset($path, $secure); } }
At some point, Laravel Mix seems to have changed
asset()
tomixasset()
.
Result:
Try using mixasset()
as opposed to asset()
. Otherwise delete your vendors
folder and rebuild it by running poser install
. This should get you the latest copy of your Laravel version with the correct asset()
helper method.
The asset()
is already point to your public folder so, don't specify the public in your asset()
Change your asset('public/js/app.js')
to asset('js/app.js')
My Err: Call to undefined function set_active()...., when I move some functions in Laravel 5.2 to Laravel 6.x ... My solution: 1. Added below in poser.json "autoload": { "classmap": [ "database" ], "psr-4": { "App\": "app/" }, "files": [ "app/helpers.php" . => New added ] } 2.run poser install it works for me.
本文标签: javascriptCall to undefined function asset() in Laravel projectStack Overflow
版权声明:本文标题:javascript - Call to undefined function asset() in Laravel project - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742281225a2446126.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论