I have a set of text files inside public/storage/
and I need to search their content, I tried to tailor this answer to work in Laravel but with no success
public function search($query)
{
$dir = new \DirectoryIterator(public_path('public'));
foreach ($dir as $file) {
return $file;
$content = file_get_contents(public_path($file));
if (strpos($content, $query) !== false) {
return 'yes';
} else {
return 'no';
}
}
}
I believe the problem with the code is that I don't know how Laravel accesses paths.
File structure in Laravel:
project
│
└───public
│
└───storage
│
│ file1.txt
│ file2.txt
│ ...
└───