laravel not picking file through asset() - laravel

In my laravel project i am trying to get js file though asset('js/app.js') which is inside public folder. it is working fine on localhost but on server it is not picking file. It is working on another server. I think there is any issue with htaccess file.
I try to use url() and URL::asset() but not working. I checked source of page link is perfect but still fail to pick file
I want to access that js file.

The question has been answered in the comments, and was solved with this code:
asset('public/js/app.js')

Related

Trying to introduce CAS in a website uploaded to a shared host

I'm trying to make my Laravel project work on a shared host as well as it does in localhost but I don't get how to do that... I uploaded my project following the steps of this tutorial: https://www.youtube.com/watch?v=_0ixeeACvZE and it worked.
I think the problem is with the folders structure because following that video I change my public folder to the public_html folder, so I lose the first one. Two problems appear here: I can't upload an image because in localhost I used to use the path public/images to do that and now I've tried to change the path but it doesn't work... However I don't wanna focus on this, the biggest problem appears when I try to add my login structure throgh CAS...
Once more, it works in localhost but in the shared host, from the moment I add these lines of code:
#if (!Cas::isAuthenticated())
#include('login')
#else
#include('partials.nav')
#yield('content')
#endif
The system gets lost in the !Cas::isAuthenticated() method and this is what it shows:
Error
To install CAS in my site I used this https://codedog.net/2017/12/19/laravel-and-cas/ and as I said, it worked locally...
Please I really need this... any help is huge. If you need more details please just let me know.
Thank for your time

Laravel: Uploaded Files URL problems with Custom Public Path

In my Laravel 5.6 project, I have moved the public folder path from /public to /web to match the hosting environment. The entire project works fine without any issues.
However, the problem appears when I upload files and try to link them. I have searched all over and cannot find any solutions to this. I have used php artisan storage:link to link the storage. I should be able to access files put in the folder by http://localhost:8000/storage/test.png but the link comes up with the view provided for the route /, not the actual file itself.
It's as if all links to the files are being treated as routes and are showing the default route page instead of the file. I would really appreciate any assistance.
Screenshot:
https://i.imgur.com/IPa6JYh.png
I found the solution to the problem.
In the file core/server.php, I had this:
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
return false;
}
The public part was causing the issue. I set it to /../web to match my project's structure and the file linking started immediately afterwards.
Hope this helps someone.
Edit: the core directory is where I have moved all the Laravel files. The screenshot in the question has more details.

Laravel - how to access public folder from JS file

I am using the exact same Ajax call in multiple blade templates.
If Ajax fails, I show an error jpg located in public/images/danger.png.
When I had my JS in the blade file written inline in <script> tags, it was easily accessible as I had blade helpers to access public with:
{{asset('/images/danger.png')}}
Yet now, accessing /public with:
http://"+location.host +"/public/images/danger.png
is impossible.
It would be unDRY to put the exact same AJAX call in 12 blades, no need to elaborate why..
How do you guys counter this issue?
remove /public from your route,you can directly use /images/imgname.jpg
You can just use absolute routes in your javascript files. This will however not work if your Laravel application sits in a sub folder.
"/public/images/danger.png"
just the same as used in html (in blade)
like
$('.abc').attr("src", "{{asset('imgs/male_b.svg')}}");

Laravel File Manager dosn't load css, js files

I integrated Laravel File Manager in my laravel project and at first it worked properly, but after I remove public [ I followed this instruction remvove public from url ] from url it din't work anymore. The css file is missing and browse file also din't work. I tried to include those files**[css, js]** into head section also din't work. It still show like this
I have no idea how to fix this error. Can anyone help me please?

Laravel Router Not Allowing Javascript Files

I'm having a really crazy issue and I can't seem to figure it out. I've got an app that was working perfectly fine in Laravel 5.2, and I've since upgraded to Laravel 5.3. When I serve the standard view from routes/web.php and include a script tag, Laravel is trying to load the script tag as a route instead of including the file. Example:
If I add the folowing:
<script src="/js/lib/jquery.min.js"></script>
At the end of my welcome.blade.php (or index, or any of them really), I get the following in the console:
Console Error
And if I look into Sources in the Chrome devtools at the jquery file, it's loaded my same blade file as the JS file (like Laravel is trying to load it via the router). Does anyone have any hints on where I can look? I really don't want to go through the process of trying to reinstall or back out the an earlier version.
EDIT: To clarify, I've been working on this a bit, and it turns out that the app.js file will load just fine, but the js/lib/**.js files won't. I don't really know what the difference is.
How about that syntax?
<script type="text/javascript" src="{{ URL::asset('/js/lib/jquery.min.js') }}"></script>
Hope it helps you :)
That only happens when the file is not found. Check the file name again, the path and also remember pathname may be case sensitive.

Resources