JS vendor published files are not working - laravel

I am using laravel filemanager:
https://unisharp.github.io/laravel-filemanager/installation
When I publish public from vendor everything works except JS files.
It still uses js files from vendor instead from public.
I tried:
Run composer dumpautoload
Clear all cache after any code changes, both in laravel and browser.
Deleting js files from public directory does nothing but when I delete
them from vendor folder it says they are missing even when they are in
public directory..

Well I found out that only one js/script was not used from public but vendor directory.
Inside vendor views directory => index.blade.php I found:
<script>{!! \File::get(base_path('vendor/unisharp/laravel-filemanager/public/js/script.js')) !!}</script>
{{-- Use the line below instead of the above if you need to cache the script. --}}
{{-- <script src="{{ asset('vendor/laravel-filemanager/js/script.js') }}"></script> --}}
And commented vendor script and uncommented public one.
Now it works.

Related

How to use laravel-jsvalidation under laravel-modules?

In Laravel 6/nwidart/laravel-modules 7 app I installed proengsoft/laravel-jsvalidation
in the directory of my module but I got errors that
Class 'JsValidator' not found
When I used proengsoft/laravel-jsvalidation for all app and in blade file I had :
<script src="{{ asset('vendor/jsvalidation/js/jsvalidation.js')}}"></script>
{!! JsValidator::formRequest('\Modules\Pages\Http\Requests\PageTypeRequest', '#form_page_type_edit'); !!}
But after I removed proengsoft/laravel-jsvalidation in root app and installed under my module
I found the file at path Project/Modules/Pages/vendor/proengsoft/laravel-jsvalidation/public/js/jsvalidation.js
and tried :
<script src="{{ asset('Modules/Pages/vendor/proengsoft/laravel-jsvalidation/public/js/jsvalidation.js')}}"></script>
But still the same error.
I tried
composer dump-autoload
both in app root and in package dir and failed.
Which way is correct ?
Thanks!

Laravel 5.8 how to display image from storage? My Git added

https://github.com/Loctarogar/Admipanel-to-manage-companies/tree/master/storage/app My git.
I linked storage to public directory with
php artisan storage:link,
but i can't show images from there. If i use
<img src="{{ asset ('storage/app/avatars/LOW6Fc2TBH8UoexcXLntQkzncXSDN6OsIt7KLbiG.jpeg') }}">
image doesn't shows. What i am do wrong?
That creates a symlink from public/storage to storage/app/public for you and that's all there is to it. Now any file in /storage/app/public can be accessed via a link like:
http://somedomain.com/storage/image.jpg
OR
One option would be to create a symbolic link between a subfolder in your storage directory and public directory.
For example
ln -s /path/to/laravel/storage/avatars /path/to/laravel/public/avatars
You forgot to enter in the public folder that storage:link creates...
Change
<img src="{{ asset ('storage/app/avatars/LOW6Fc2TBH8UoexcXLntQkzncXSDN6OsIt7KLbiG.jpeg') }}">
to:
<img src="{{ asset ('storage/app/public/app/avatars/LOW6Fc2TBH8UoexcXLntQkzncXSDN6OsIt7KLbiG.jpeg')}}">

Laravel - link to a file saved in storage folder

When we do something like this:
Storage::disk('local')->put('file.txt', 'Contents');
How do you make a link to that file in a view? Something like this:
Download File
there are so many things in documentation and yet not even one example how to create a link to that file
Try this command on your terminal : php artisan storage:link, then laravel storage become public access.
Download File
UPDATE:
According to laravel docs, You can get the URL to the file like this:
use Illuminate\Support\Facades\Storage;
$url = Storage::url('file1.jpg');
Remember, if you are using the local driver, all files that should be
publicly accessible should be placed in the storage/app/public
directory. Furthermore, you should create a symbolic link at
public/storage which points to the storage/app/public directory.
Hope this helps!
Scenario--(working from a fresh Laravel 5.6 project install for reference):
With the existing default paths being /public and /storage/app/public and you want to physically store your logo.png image in the /storage folder and render it on your Welcome page, the process would go something like this:
In your terminal, navigate to your Laravel project folder.
Run command php artisan storage:link
Now create the folder /images in your /storage/app/public folder which gives you /storage/app/public/images.
Look in your /public folder and you will see the (shortcut) subfolders /storage/images
Copy a test image named logo.png into the /storage/app/public/images folder.
In your project's welcome.blade.php under /resources/views paste the
following code over the existing code:
<div class="content">
<div class="title m-b-md">
Laravel
<div>
<a href="/">
<img src="{{url('/storage/images/logo.png')}}" alt="Logo Image"/>
</a>
</div>
</div>
</div>
Save and open your project in your browser and you should see the logo image.
Having said all of that, later on you need a pdf folder to store uploaded pdf
files. Easy, just create a new folder in /storage/app/public called /pdf and
automatically the shortcut will appear in the /public folder. It is a once and "for all" solution.

Image not displaying in view. Laravel

In my Laravel project I'm trying to load an image into my view using blade but it displays as a broken link. I inspect it with firebug and the src is pointing to the image but nothing is displaying.
My image is located in my project's public/images/users/3/profilePictures/
Here is my <img> in the view.blade.php
<img class="com-profile-picture" src="images/users/{{ $follower->id }}/profilePictures/50thumb-{{ $follower->profilePicture->url }}" alt="{{ $follower->first_name }} {{ $follower->last_name }} Profile" width="50" height="50">
However I get this when I load the page:
When I inspect the image with firebug I see this:
That is the correct src and the image does exist in my public/images/users/3/profilePictures/ directory
Anyone know why this is happening?
This may be caused you are in a route which does not represent the base URL. You should generate the URL for your assets relative to the public/ folder. Use URL::asset('path/to/asset') to generate the URL.
{{ URL::asset("images/users/{$follower->id}/profilePictures/50thumb-{$follower->profilePicture->url}") }}
Or as #lukasgeiter mentioned you can simply use asset('path/to/asset') helper.
You can try with the
php artisan storage:link
else you can use this
A simple fix for the issue (linked broken error)
in .env file
APP_URL=http://localhost
this replace with the
APP_URL=http://localhost:8000
then the issue will be fixed.
delete already generated symlink and then run this command
php artisan storage:link
if you are using laravel, consider excluding public folder or any folder where your public files are store in .htacccess from folders that laravel control.
Do it like this in .htaccess
# Exclude directory from rewriting RewriteRule ^(public/) - [L]
Storage location before (Not Working) :
<img src="{{asset('storage/app/public/media/productImages/'.$list->image)}}" alt="" srcset="">
Working storage location :
<img src="{{asset('storage/media/productImages/'.$list->image)}}" alt="" srcset="">
Else try :
Deleting all the linked/shortcut folders created in public folder
Then recreating the link by running :
php artisan storage:link

Laravel assets url

I have installed Laravel and began trying to write an app. I made some directories for my assets in the same directory as /app. But when I try to visit an image in my localhost for example: http://localhost/assets/images/image.png
I've also tried it on: http://localhost/app/assets/images/image.png
I ran into the problem when I was trying to set a background image in a view, and it kept going to 404.
This is what my app looks like under app/
->app
->assets
->commands
->config
->controllers
->database
->lang
->models
->start
->storage
->tests
->views
app.txt
routes.php
filters.php
But I get errors about requests. I have double checked that the url is correct.
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
You have to put all your assets in app/public folder, and to access them from your views you can use asset() helper method.
Ex. you can retrieve assets/images/image.png in your view as following:
<img src="{{asset('assets/images/image.png')}}">
You have to do two steps:
Put all your files (css,js,html code, etc.) into the public folder.
Use url({{ URL::asset('images/slides/2.jpg') }}) where images/slides/2.jpg is path of your content.
Similarly you can call js, css etc.
Besides put all your assets in the public folder, you can use the HTML::image() Method, and only needs an argument which is the path to the image, relative on the public folder, as well:
{{ HTML::image('imgs/picture.jpg') }}
Which generates the follow HTML code:
<img src="http://localhost:8000/imgs/picture.jpg">
The link to other elements of HTML::image() Method: http://laravel-recipes.com/recipes/185/generating-an-html-image-element
{{ asset('js/jquery.min.js') }}
//Full Path http://127.0.0.1:8000/images/slides/2.jpg
Do Not Add Public folder name

Resources