Snedden27 Snedden27 - 7 months ago 64
PHP Question

Storage_path returning path without slashes in laravel

I want to get the path to the Storage funtion in laravel and read it in javascript,

The way I try to do this is :

var storagePath="<?php echo storage_path(); ?>";
console.log('StoragePath ',storagePath);

But this logs out a path like this :

StoragePath C:wampwwwd3projectFirststorage

I do need the slashes but seems like 'storage_page()' trims them , not sure if this is a security thing,can I still read the path to the folder using the string above or get the slashes untrimmed?


This is because javascript thinks you want to escape something. So all you have to do, is escape the backslashes. addslashes will do the trick:

var storagePath = "<?php echo addslashes(storage_path()); ?>";
console.log('StoragePath ',storagePath);