Answer the question
In order to leave comments, you need to log in
How to get each time new data in the template through the controller?
Hello!
There is a controller in which the code is written to get a list of files from a folder:
$path = public_path('images');
$files = File::files($path);
return view('show', ['files' => $files]);
@foreach($files as $file)
...
@endforeach
Answer the question
In order to leave comments, you need to log in
In general, I did this: I
removed the files variable from the view and moved all the code to a separate function and made an additional route for it.
public function getFiles()
{
$path = public_path('images');
$files = File::files($path);
return $files;
}
$.get( "{!! route('your_url') !!}", function( data ) {
console.log(data);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question