Laravel: Rename a file located in / resources

0

I have files saved in the following path: /resources/views/projects/nombreproyecto.blade.php

So, I have a form that I ask for the new name of the project and what I want to do is rename the file, for example:

I have a project called lluistestantes, because the path to the file would be the following: /resources/views/projects/lluistestantes.blade.php

Then I fill in the form, and I put the name of lluistestdespues, the path to the file should be the following: /resources/views/projects/lluistestdespues.blade.php

The controller that makes the function looks like this:

public function updateProject(Request $request, $id) //Actualizar la informacion de un proyecto 
    { 
       $project = Project::find($id); //Encuentro que proyecto es

            $oldSlug = $project->slug; //guardo el valor ANTIGUO en la variable

            $project->order = $request->input('order'); //no es importante
            $project->public = $request->input('public'); //no es importante

            if (strcmp($oldSlug, $request->input('slug')) !== 0) { //Si el slug cambia, entra en el IF

            Storage::disk('projects')->move($project->slug, $request->input('slug')); //Se renombra la carpeta project, no darle atención a esta linea porque es independiente a la funcionalidad que busco ahora, ademas que es para archivos situados en Storage.

            $project->slug = $request->input('slug'); //se pilla el valor del slug NUEVO

            $project->pathheader = $request->input('slug').'/header.jpg'; //se guarda el path en la bbdd, no darle atención a esta linea porque es independiente a la funcionalidad que busco ahora.

            $project->pathhome = $request->input('slug').'/home.jpg';  //se guarda el path en la bdd, no darle atención a esta linea porque es independiente a la funcionalidad que busco ahora,

            File::move('/resources/views/projects/'.$oldSlug.'.blade.php','/resources/views/projects/'.$project->slug.'.blade.php'); //FUNCIÓN REALMENTE IMPORTANTE, pillo la blade antigua y la intento machacar con el nuevo valor.
        }
    }

The error he gives me is this:

rename(/resources/views/projects/lluistestantes.blade.php,/resources/views/projects/lluistestdespues.blade.php): No such file or directory

    
asked by Lluís Puig Ferrer 01.09.2017 в 14:47
source

1 answer

1

You can not find the file because you are not passing the entire path where the file is located. To solve that you can use the helper resoure_path() or base_path('resources')
Modify the last line of the method

File::move(resource_path('views/projects/').$oldSlug.'.blade.php',resource_path('views/projects/').$project->slug.'.blade.php');
    
answered by 03.09.2017 / 01:34
source