11.08.2017 Views

codebright

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Forms 165<br />

1 <br />

2<br />

3 {{ Form::open(array(<br />

4 'url' => 'my/route',<br />

5 'files' => true<br />

6 )) }}<br />

7 {{ Form::label('avatar', 'Avatar') }}<br />

8 {{ Form::file('avatar') }}<br />

9 {{ Form::close() }}<br />

The first parameter for the Form::file() method is the name attribute of the file upload element,<br />

however, in order for the upload to work, we need to ensure that the form is opened with the files<br />

option to include the multipart encoding type.<br />

Here’s the generate page source.<br />

1 <br />

2<br />

3 <br />

7 <br />

9 Avatar<br />

10 <br />

11 <br />

Hidden Fields<br />

Sometimes our fields aren’t meant to capture input. We can use hidden fields to supply extra data<br />

along with our forms. Let’s take a look at how hidden fields can be generated.<br />

1 <br />

2<br />

3 {{ Form::open(array('url' => 'my/route')) }}<br />

4 {{ Form::hidden('panda', 'luishi') }}<br />

5 {{ Form::close() }}<br />

The first parameter to the Form::hidden() method is the name attribute, I bet you didn’t see that<br />

coming? The second parameter is of course the value.<br />

This is how the generated page source looks.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!