samedi 30 avril 2016

Laravel 5: Dynamically Generate Links (Routes) to Uploades Files

I have a simple form where users can upload files. Files are uploaded to public/uploads directory.

Below the form there is a list of all the files in public/uploads directory.

So, here is my controller method:

public function store(Request $request)
{
    if ($request->hasFile('file_upload')) {
        if ($request->file('file_upload')->isValid()) {
            $request->file('file_upload')->move(public_path().'/uploads/', $request->file('file_upload')->getClientOriginalName());
        }
    }

    $list_of_files = \File::allFiles(public_path().'/uploads/');

    return view('foo', compact('list_of_files'));
}

and here is the View file that displays the list of files:

<ul>
    @foreach($list_of_files as $file)
        <li><a href="#"></a></li>
    @endforeach
</ul>

What should I put in href=" " to have links to those files (and what routes do I need to have so these links work)?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire