chikenare's avatar

How do you make the correct query?

How can I get a user's shared files but not everything together (parents and children) only the parents like in a file explorer

it should only bring folder1, image,jpg, anotherfolder

  • images
    • img1.png
    • img2.png
  • simplefile.pdf
  • anotherfolder
    • demo.apk
private  function  getSharedWithMe($user) {
 
    $user  =  Auth::user();

      $files  =  File::join('shared_files', 'files.id', '=', 'shared_files.file_id')

      ->where('shared_files.user_id', $user->id)

      ->cursorPaginate(30);



      return  $files;

}
0 likes
3 replies
arifhossen's avatar

Could you please provide your shared_files table structure and your file storage folder structure where you are saving your uploaded files?

1 like
Tray2's avatar

I'm guessing you have a directory column in your table, so just make a distinct query on that. If you don't you would have to substring the directory from the filename, or why not just use the DirectoryIterator class.

amitsolanki24_'s avatar

$user = Auth::user();

  $files  =  File::with('shared_files'=>function($query) use($user) {
                      $query->where('shared_files.user_id', $user->id);
                    })-get()

Please or to participate in this conversation.