Laravel Version Cache with Laravel Mix Not Working - laravel

I'm trying use laravel mix but in browser return error 404
Laravel 5.6.4
My .env APP_URL
APP_URL=http://localhost/base-site-template/public
My mix-manifest.json
{"/js/lib/echarts.js": "/js/lib/echarts.js?id=a24928e50f4d775d9e3e",
"/js/lib/moment.js": "/js/lib/moment.js?id=a3cde5d62118f1b1ac08",
"/js/lib/axios.js": "/js/lib/axios.js?id=1129cee8012a0ec7cb58",
"/css/lib/vuetify.css": "/css/lib/vuetify.css?id=c7533b5bc8f96cca4e90",
"/css/index.css": "/css/index.css?id=d41d8cd98f00b204e980",
"/css/template.css": "/css/template.css?id=c7533b5bc8f96cca4e90",
"/js/template.js": "/js/template.js?id=3213a53c38fb71543141",
"/js/lib/vue.js": "/js/lib/vue.js?id=e41f4d0b6a918ca9213d",
"/js/lib/lodash.js": "/js/lib/lodash.js?id=98dc43a5e921b41ef214",
"/js/lib/vee-validate.js": "/js/lib/vee-validate.js?id=bfc8600a0fc91c459f0e",
"/js/lib/vuetify.js": "/js/lib/vuetify.js?id=f0c3ad550b36770ee4c9",
"/js/index.js": "/js/index.js?id=5a79665b4d1331d942d7"}
I'm trying to get css and js files using {{ mix('js/template.js') }}
Can someone help me?

Your resources are trying to be loaded from the root directory:
You're accessing the site at /base-site-template/public not /. So you'd have to access the files at /base-site-template/public/js/index.js not /js/index.js.
If you have your APP_URL set properly, you can use the asset() helper to prefix your APP_URL.
{{ asset(mix('js/template.js')) }}

Assets are placed into the public/ directory when they're compiled, e.g:
public/js/lib/echarts.js
Your browser will treat relative requests beginning with / as relative to the base path which is http://localhost/. For example when you load the page http://localhost/base-site-template/public and it references /js/lib/echarts.js the browser will make this request:
http://localhost/js/lib/echarts.js
However that is not where your assets reside, your assets reside in:
http://localhost/base-site-template/public/js/lib/echarts.js
Therefore you will need to either:
Reference the assets using an absolute URL instead of a relative path
Tell clients browsers to use a different base path
Move your application to the base path
You can reference the assets with an absolute path using the asset helper:
asset(mix('public/js/lib/echarts.js'));
You can tell the client browser to use a different base path using the base element in your documents head:
<base href="http://localhost/base-site-template/public/">

Related

How to retrieve files from S3 in Laravel Vapor

I'm having a problem loading images in my html dynamically after storing them successfully with Laravel Vapor.
I have followed this documentation provided by laravel vapor to store files, and it works like a charm. I copy my uploaded files from the tmp directory into the root of my S3 bucket and then store the path of that file in my databases images table so that later I can return the file path to my front end and display the image in my browser.
Unfortunately this is always returning a 403 status code from AWS S3.
I could fix this by making my generated S3 bucket public, but that would raise a security issue. I believe this should work out of the box, not sure where I could have gone wrong... any ideas?
I am returning the uploaded image url using the Storage facade.
use Illuminate\Support\Facades\Storage;
return Storage::url($image->path);
Where $image->path is the file path in my S3 bucket.
I'm sure that the storage facade is working correctly because it is returning the correct url with the file's path.
I got the solution to this problem. I contacted laravel vapor support and I was told to set the visibility property for my file to public when I copy it to the permanent location, as stated in Laravel's official documentation here.
So after you upload your file using the js vapor.store method you should copy it to a permanent directory, then set it's visibility to public.
Storage::copy($request->path, str_replace('tmp/', '', $request->path));
Storage::setVisibility(str_replace('tmp/', '', $request->path), 'public');
I also noticed that your can set the visibility of the file directly in the vapor.store method by passing a visibility attribute with the respective value.
vapor.store(file, { visibility: 'public-read' });
As a side note: just 'public' will return a 400 bad request, it must be set to 'public-read'.

Laravel - Change cookies directory from root to other

I have an application on Laravel 4.2. Currently, when I see the http requests sent from my application, the cookies are all stored in the root directory as path=/. I would like to store the cookies in a custom directory like another folder inside the storage directory.
Go to config/session.php,
set
'path' => other directory path (route path)

Rails 5 app. Asset pipelining and precompilation with heroku not showing up images from js.jsx files

I am almost done with upgrading my Rails3 app to Rails5; But I am facing a problem with assets pipelining and precompiling. We're using cdn as asset host.Now, What happens is that when I set config.assets.precompile to false in staging environment, the app doesn't load images from js.jsx files. At other places, the app is fetching the static assets (js,css,images) from the asset_host link that I've provided. But in some specific javascript files, The images is being pointed out to my app's domain like app.my_domain.com/assets/my_image.png,And it is giving 404 not found error.
In javascript, the code is something like
return (
<img src="/assets/my_image.png"></img>
)
Since this is a js file, I cannot use asset_path helper method here.
How to resolve this issue ?
PS: setting config.assets.precompile to true loads the image from app.my_domain.com/assets/my_image.png, but that's not what I want because of this. config.assets.compile=true in Rails production, why not?
Any help with this is highly appreciated. Thanks in advance.
I found an answer after some research. I changed the name of the file to js.jsx.erb and accordingly used asset_path helper method which rails provide.
return (
<img src = "asset_path 'my_image.png'"/>
)
It works.

Redirecting to API/Docs/index.html folder in Lumen

So i have an API created with Lumen with some documentation done with Apidoc outside of the public folder and i'd like to serve it when the user goes to the URL http://apidomain.com/docs
This is the structure of the app
ProjectRoot
->API
->Auth
->Docs
->v1
->app
->bootstrap
->database
->public
...
Is there any way to create a route that sends the user to API/Docs?
It's done, it was actually my bad, when trying to call the file via routes it actually messed up the filepath for the other files. So when i looked in the dev tools on chrome i noticed i was getting 404's on my js and css files, hence the failure to load the ApiDoc

Laravel. Add port to home url

Site use port 8080 on new server.
I need "site.com" => "site.com:8080"
How change base url in laravel for correct including css/js and redirects?
Ok, we tried many things.
It seems it's a bug or something. They have it since Laravel 4 and do not want to fix it:
https://github.com/laravel/framework/issues/1833
The only solutions I see here are:
1. To use standard port.
2. To generate URLs manually. For example:
// in controller
$baseUrl = 'http://'.$_SERVER['HTTP_HOST'].'/';
// in template
<link hre="{{ $baseUrl.'css/myStyleSheet.css' }}" ....>
Or you could set this variable in your top layout, so all inherited views have it.
I ended up adding the following line to boot() function of AppServiceProvider.php :
URL::forceRootUrl(env('APP_URL'));
You can also hardcode it there, but this way it uses the settings from .env file.
Warning: if the APP_URL is https, then I also needed to add the following line, or otherwise it would alter it to http (weird):
URL::forceScheme('https');

Resources