i'm new to laravel. And I have the website up now with forge. The only issue is that I cannot see or store the photos. Do I have to write the storagelink command somewhere, and if then, where exactly? I changed the file system driver to public on the env file as well
you can do that by creating the symbolic link using the facade Artisan
basically you will need to create a new route at web.php as bellow :
Route::get('/linkstorage', function () {
Artisan::call('storage:link');
});
and , of course , don't forget to import the class at the very top of the file like so :
use Illuminate\Support\Facades\Artisan;
make sure you update the hosted file as changed .
and simply , to create your symlink , you will need to navigate to /linkstorage and that's it !
Related
On my Laravel website I'm using symlink to store and show the images from storage.
With
php artisan storage:link
I had created the symlink and everytime when I upload a new news article, the image is uploaded in the main Storage and with symlink it's setup to the public folder and I'm displaying the image properly.
So far so good, but when I've created a copy of the website, a problem appears...
When I've created a copy of the website with cPanels File Manager, and move to a new location, the storage symlink in the public directory has become a folder, not a symlink.
After that when I try to upload a new news article, I can see it's uploaded in the main Storage folder, but not in the public/storage, so as a result the image is not displaying. That's because it's not a symlink anymore, but now it's a folder.
I've deleted the storage folder from the public directory, with SSH I've used the command again
php artisan storage:link
and I've created a new news article and the image is displaying properly, but now all other images are gone.
Is there any command that will regenerate the paths, so all other images will be display again?
I'm using Laravel 5.5
You can solve it in another way to create a symlinkexample.php file
into your public folder and run the file path into browser.
Then Storage folder will be created into public folder. Folder path
will be public/storage with linked to your public folder.
Code below for symlinkexample.php :
<?php
$targetFolder = $_SERVER['DOCUMENT_ROOT'].'/storage/app/public';
$linkFolder = $_SERVER['DOCUMENT_ROOT'].'/public/storage';
symlink($targetFolder,$linkFolder);
echo 'Symlink process successfully completed';
?>
Try this:
In route/web.php add the following code:
Route::get('/storage', function(){
\Artisan::call('storage:link');
return "Se han vinculado las imágenes";
});
If for some reason you are using different file structure and for some reason don't have terminal access, \Artisan::call('storage:link') will fail since it won't find public path.
Route::get('cmd', function(){
$process = new Process(['ln', '[symlink-here]','[target-folder]' ]);
$process->run();
// executes after the command finishes
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
echo $process->getOutput();
});
read about Process class here
Currently running into issues on my server with links to files in my Laravel application.
I currently have a images folder in storage/app/public and I linked the storage/app/public folder to public with php artisan storage:link.
Now i have a image.jpg in the images folder.
On my local system while using valet I can see the image with the tow following links:
/images/image.jpg
/storage/images/image.jpg
On my server only the second one works (which I assume is correct as there is no images folder directly in the public-directory.
Problem is, I often run into issues when deploying as customers can't see images online (as the link is not working). This wouldn't be an issue if I could not see images local while testing the UI.
Anyone also has this issue and can lead me to some kind of solution?
The issue is that the LaravelValetDriver has a fallback test; if the file doesn't exist in the public directory then it will check the public storage directory.
You can find that here:
if ($this->isActualFile($storagePath = $sitePath.'/storage/app/public'.$storageUri)) {
return $storagePath;
}
You can prevent this behaviour by creating your own Valet Driver that extends the LaravelValetDriver and overrides the isStaticFile method, e.g:
class NoStorageFallbackLaravelValetDriver extends LaravelValetDriver
{
public function isStaticFile($sitePath, $siteName, $uri)
{
if (file_exists($staticFilePath = $sitePath. '/public' . $uri)
&& is_file($staticFilePath)) {
return $staticFilePath;
}
return false;
}
}
Using the public disk is straight forward and should work without problems out of the box.
The public disk uses the 'local' driver which by default uses the storage/app directory.
The command:
php artisan storage:link
will create a symbolic link 'storage' inside your public folder that links to the non-public folder storage/app/public.
When the link is working, you can use the following command:
Storage::disk('local')->put('public/file.txt', 'Contents');
This will store file.txt to
storage/app/public/file.txt
You won't be accessing the file at storage/app/public.file.txt instead you will be accessing it using the symlink public/storage...
Therefore your saved file will publicly accessible at
public/storage/file.txt
Use the asset helper you can get the location of the file:
echo asset('file.txt');
I've renamed my app folder to aplicativo and changed the namespace to aplicativo. Everything works but artisan make commands.
I changed namespace through composer.json
"psr-4": {
"aplicativo\\": "aplicativo/",
}
Plus command:
artisan app:name aplicativo
You won't get this to work. You can rename the namespace (as you did with the command), but you can't rename the directory because it's hardcoded as app.
You can see the source here.
Then... if your using composer try this command
composer dump-autoload
The good news is that Laravel has now added support for custom App path. You can override the App path by adding the following code in bootstrap/app.php (or provider).
/*...*/
$app = new Illuminate\Foundation\Application(
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);
// override the app path since we move the app folder to somewhere else
$app->useAppPath($app->basePath('src'));
Similarly, you can change other paths (database, language, storage, etc.). You can find all the available methods here.
I have no idea on how to create symbolic link or symlink.
I am working on File system in laravel 5.2.
The document says that i need to create a symbolic link from public/storage to storage/app/public to keep the publicly accessible files in one directory.
How to create that symlink or symbolic link?
Which file or directory should I place that code?
App::make('files')->link(storage_path('app/public'), public_path('storage'));
And don't forget to use App after namespace.
Run this command:
php artisan storage:link
In a Windows environment, you can:
cmd with Run as administrator
Run the mklink command:
mklink /D "C:\xampp\htdocs\xxxx\yyy\public\storage\"
"C:\xampp\htdocs\xxxx\xxx\storage\public\"
On Shared Server, where one doesn't have ssh access to run
php artisan storage:link this helps me run that from a controller, the if block code section can also be placed in a Service Provider as well as suggested by #shìpu-ahamed
public function displayForm()
{
if(!file_exists(public_path('storage'))) {
\App::make('files')->link(storage_path('app/public'), public_path('storage'));
}
return view('admin.index');
}
Added same code but still getting issue.
Method link does not exist.
currently i am adding link in my controller constructor.
here is code:
public function index()
{
$shots=[];
App::make('files')->link(storage_path('app\public'), public_path('..\public\storage'));
return View::make('adminpages.index',['shots'=>$shots]);
}
I am using Laravel 5.2. I need to get RSS feeds using SimplePie, so I install the library through composer.json and now my vendor folder contains simplepie but when i run the following code this error shows:
ErrorException in SimplePie.php line 1379: ./cache is not writeable.
Make sure you've set the correct relative or absolute path, and that
the location is server-writable.
My code in route:
Route::get('feed', function () {
$feed = new SimplePie();
$feed->set_feed_url(array(
'http://www.thenews.com.pk/rss/2/16' //it has no images
));
$feed->init();
$itemCount=$feed->get_item_quantity();
return $itemCount;
});
Create a writeable cache folder for simplepie in the /storage/ folder (I called mine simplepie_cache).
Set the path in your feed object:
$feed->set_cache_location(storage_path() . '/simplepie_cache');
That should do the trick.
check what is saying ./cache is not writeable can't write to cache folder check permissions to this folder or try a L5 wrapper for SimplePie https://github.com/willvincent/feeds