I have a function where I pass some data, slug, order, public, and two images.
If I have on request 'slug' I want to delete the folder called with the last project->slug and create the new one.
Something like that:
if ($request->has('slug'))
{
\Storage::disk('projects')->deleteDirectory($project->slug);
\Storage::disk('projects')->makeDirectory($project->slug);
}
And save inside the image, and if I don't select a new image, save the last image that project Have, with something like this:
if($request->hasFile('pathheader')){
$project->pathheader = $request->file('pathheader');
\Storage::disk('projects')->putFileAs($project->slug,$project->pathheader,'header.jpg');
}
$project->pathheader = Project::find($id)->pathheader;
if($request->hasFile('pathhome')){
$project->pathhome = $request->file('pathhome');
\Storage::disk('projects')->putFileAs($project->slug,$project->pathhome,'home.jpg');
}
$project->pathhome = Project::find($id)->pathhome;
$project->save();
How can I do it? I'm stocked with this..
I will really appreciate any help.
Thanks a lot.
DELETE FOLDER DONE Just change some lines, now code looks like here:
if ($request->has('slug')){
\Storage::disk('projects')->deleteDirectory($project->slug);
}
$project->slug = $request->input('slug');
\Storage::disk('projects')->makeDirectory($project->slug);