vendredi 31 août 2018

Copy entire contents of a directory to another using Laravel 5.6

I'm trying to create a controller function where form data is used as a request to copy an existing directory full of files and sub derectories to another location.

So far I've tried,

// Vendor repositoreis path
$vrepo = storage_path('app/public/repositories/vendor/laravel/');
$lnrepo = storage_path('app/public/repositories/');

// Check if directory with similar name exists
if(!File::exists($lnrepo . str_slug($request->name))) {
  // Copy repository from vendor directory
  if(File::copyDirectory($vrepo, $lnrepo)) {
    // Rename copied repository
    rename($lnrepo . 'laravel', $lnrepo . str_slug($request->name));
  } else {
    return back()->with('error', 'No such file or directory.');
  }
} else {
  // Return error message if directory with similar name exists
  return back()->with('error', 'Repository with the same name already exists.');
}

As a result I get an error saying,

 ErrorException (E_WARNING) rename(/Applications/MAMP/htdocs/storage/app/public/repositories/laravel, /Applications/MAMP/htdocs/storage/app/public/repositories/hui): No such file or directory

It's either this or I need to figure out a way to run,

exec('composer create-project --prefer-dist laravel/laravel ' . $request->name);  



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire