2017-09-01 241 views
0

我保存的下一个路由文件: /resources/views/projects/nameproject.blade.phpLaravel:重命名文件

我有,我把项目的新名称的表格,我想建立一个名为创建的文件的重命名项目,例如:

我有一个名为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

你能用正确的语法回答吗?我在开始时没有/尝试,并尝试使用public_path()。 –

+0

这取决于您的设置,但例如'app_path('resources/views/projects/lluistestantes.blade.php')'或类似的。 –

回答

1

试试下面的代码:

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