Laravel无法复制Directory或moveDirectory [英] Laravel, unable to copyDirectory or moveDirectory

查看:1172
本文介绍了Laravel无法复制Directory或moveDirectory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 目前我在Laravel的问题无法使用moveDirectory和copyDirectory,但是makeDirectory或deleteDirectory工作正常。 <?php 

namespace App \Http\Controllers\Backend;

使用App \Http\Controllers\Controller;
使用Illuminate \Http\Request;
使用Illuminate\Support\Facades\Auth;
使用Illuminate\Support\Facades\Storage;

使用App \Http\Requests;

使用App \Property;

使用干预;

class PropertyController extends Controller {

public function update($ request $ b $)$ property $ property $ find $ find $ fr $
$ oldName = $ property-> name;

$ property-> fill($ request-> all());
if($ request-> name ==''){
$ property-> name = str_slug($ request-> title);
}
$ property-> updated_by = Auth :: user() - > username;
$ b $ if($ oldName!== $ property-> name){
Storage :: disk('public') - > moveDirectory('images /'.$ oldName,'图像/'.$财产而>名称);
}
$ property-> save();

show_feedback('info','Property successfully updated');

return redirect(route('property-management.index'));


$ / code $ / pre

带有错误:

  PluggableTrait.php中的BadMethodCallException行85:
调用未定义的方法League \Flysystem\Filesystem :: moveDirectory


解决方案

我想 moveDirectory 不可用在存储下。尝试使用下面的代码



先导入文件系统

 使用Illuminate \\Filesystem\Filesystem; 

之后,创建一个新的实例并移动目录。路径是相对于index.php我猜。

  $ file = new Filesystem(); 
$ file-> moveDirectory('../ storage / app / public / old_folder','../storage/app/public/new_folder');

已编辑

与方法注入

pre $公共函数更新(请求$请求,文件系统$文件,$ id)


Currently I having problem with Laravel cannot use moveDirectory and copyDirectory however makeDirectory or deleteDirectory works fine, the code as follow:

<?php

namespace App\Http\Controllers\Backend;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;

use App\Http\Requests;

use App\Property;

use Intervention;

class PropertyController extends Controller {

    public function update(Request $request, $id) {
        $property = Property::findOrFail($id);
        $oldName  = $property->name;

        $property->fill($request->all());
        if ($request->name == '') {
            $property->name = str_slug($request->title);
        }
        $property->updated_by = Auth::user()->username;

        if ($oldName !== $property->name) {
            Storage::disk('public')->moveDirectory('images/'.$oldName, 'images/'.$property->name);
        }
        $property->save();

        show_feedback('info', 'Property successfully updated');

        return redirect(route('property-management.index'));
    }
}

with error:

BadMethodCallException in PluggableTrait.php line 85:
Call to undefined method League\Flysystem\Filesystem::moveDirectory

解决方案

I guess moveDirectory is not available under Storage. Try with below code

import file system first

use Illuminate\Filesystem\Filesystem;

after that create a new instance and move directory. Path is relative to index.php I guess.

$file = new Filesystem();
$file->moveDirectory('../storage/app/public/old_folder', '../storage/app/public/new_folder');

Edited

You can bypass instance creation with method injection

public function update(Request $request,Filesystem $file, $id)

这篇关于Laravel无法复制Directory或moveDirectory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆