vendredi 1 septembre 2017

Laravel: Rename a file

I have files saved in the next route: /resources/views/projects/nameproject.blade.php

I have a form where I put the new name of the project and I want to make a rename of the file created with the name of project, for example:

I have a project called lluistestbefore, her route it's this: /resources/views/projects/lluistestbefore.blade.php

When I submit the Form I give a new value called: lluistestafter, the route should be:

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

The controller function looks like:

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.
            }
        }

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



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire