Creating a File Input Field

Problem

You want to create an file input field for file uploads.

You know you could use the <input type="file"...> format but you want to do it the Laravel way.

Solution

Use the Form::file() method.

Usually, this is used in Blade templates.

The simplest form of this method is to only pass the name.

{{ Form::file('thefile') }}

This creates a very simple element which looks like the following.

<input name="thefile" type="file">

To add other attributes, pass a second argument to the method. This second argument must be an array.

{{ Form::file('thefile', ['class' => 'field']) }}

Now the input has a class attribute.

<input class="field" name="thefile" type="file">

Discussion

This method wraps the Form::input() method, passing "file" as the type.

comments powered by Disqus