0

laravel version 6.18.8

i used this line to make a directory but it say Method Illuminate\Filesystem\Filesystem::mkdir does not exist.

$newDirectory = public_path() . 'img/reviews/' . Str::slug($request->title,'-');
File::mkdir($newDirectory);

i also used makeDirectory() that was also not working..

please help to make a directory using laravel

tariqul anik
  • 314
  • 6
  • 24

1 Answers1

0

You may use php mkdir function

$dirPath = public_path('img/reviews/' . Str::slug($request->title,'-')); 
if (!file_exists($dirPath)) {
    mkdir($dirPath, 0777, true);
}

See How to create directory if not exists in Laravel 7.x and 6.x?

Foued MOUSSI
  • 4,643
  • 3
  • 19
  • 39
  • well this would work but will not fix the OP's problem – Anuj Shrestha Apr 26 '20 at 15:19
  • Well, behind the scenes Laravel also uses php native functions. right ? – Foued MOUSSI Apr 26 '20 at 15:20
  • Yes it does uses this behind the scene but Laravel offers way too much feature through `Filesystem` if that is broken then the whole app might break. – Anuj Shrestha Apr 26 '20 at 15:22
  • 1
    I guess the OP mis-typed or imported the `File` Facade – Foued MOUSSI Apr 26 '20 at 15:28
  • can you please help me with another topic? I used this code for single upload. **if (request()->has('image')) { $photo = request()->file('image'); $image = Image::make($request->image); $image->save(public_path('../../img/galleries/gallery-images/' . DB::getPdo()->lastInsertId() . '.png')); DB::table('galleries') ->where('id', '=', DB::getPdo()->lastInsertId()) ->update([ 'image' => DB::getPdo()->lastInsertId() . '.png', ]); }** but how can i use it in multiple upload – tariqul anik Apr 26 '20 at 15:39