Laravel:重命名文件

时间:2017-09-01 14:19:27

标签: php laravel laravel-5

我在下一条路线中保存了文件: /resources/views/projects/nameproject.blade.php

我有一个表单,我在其中放置项目的新名称,我想重命名使用项目名称创建的文件,例如:

我有一个名为lluistestbefore的项目,她的路线是这样的: /resources/views/projects/lluistestbefore.blade.php

当我提交表格时,我会给出一个名为lluistestafter的新值,路线应为:

/resources/views/projects/lluistestafter.blade.php

控制器功能如下:

public function updateProject(Request $request, $id) //Update the project info 
        { 
           $project = Project::find($id); //Find which project is

                $oldSlug = $project->slug; //save the old value into the variable

                $project->order = $request->input('order'); //it's not important
                $project->public = $request->input('public'); //it's not important

                if (strcmp($oldSlug, $request->input('slug')) !== 0) { //If slug change enter to the if

                Storage::disk('projects')->move($project->slug, $request->input('slug')); //it's not important

                $project->slug = $request->input('slug'); //get the value of the new slug

                $project->pathheader = $request->input('slug').'/header.jpg'; //it's not important

                $project->pathhome = $request->input('slug').'/home.jpg';  //it's not important

                File::move('/resources/views/projects/'.$oldSlug.'.blade.php','/resources/views/projects/'.$project->slug.'.blade.php'); //Function which is not working correctly and give me the error.
            }
        }

错误是这样的: rename(/resources/views/projects/lluistestantes.blade.php,/resources/views/projects/lluistestdespues.blade.php): No such file or directory

1 个答案:

答案 0 :(得分:1)

请尝试以下代码:

File::move(resource_path('views/projects/'.$oldSlug.'.blade.php'),resource_path('views/projects/'.$project->slug.'.blade.php'));