How to create symlink from public/storage to storage/app/public in laravel?

旧街凉风 提交于 2019-12-22 08:26:26

问题


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?


回答1:


App::make('files')->link(storage_path('app/public'), public_path('storage'));

And don't forget to use App after namespace.




回答2:


Run this command:

php artisan storage:link



回答3:


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');
}



回答4:


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]);
   }



来源:https://stackoverflow.com/questions/38045119/how-to-create-symlink-from-public-storage-to-storage-app-public-in-laravel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!