Creating an Image Input Element

Problem

You want to create an image input element in your Blade template.

Solution

Use the Form::image() method.

The only required argument, is the first one. It is the url to the image.

{{ Form::image('images/submit-button.jpg') }}

This will produce the following HTML.

<input src="http://your.url/images/submit-button.jpg" type="image">

Note: If you don't provide a complete URL to the image, your application's url will be used.

You can name the input field with the second argument.

{{ Form::image('images/submit-button.jpg', 'btnSub') }}

Notice the name attribute in the output.

<input src="http://your.url/images/submit-button.jpg"
  name="btnSub" type="image">

Additional attributes can be set by passing an array as the third argument.

{{ Form::image('images/submit-button.jpg', 'btnSub', ['class' => 'btn']) }}

Now the input tag has a class attribute.

<input class="btn" src="http://your.url/images/submit-button.jpg"
  name="btnSub" type="image">

Discussion

Nothing to discuss.

comments powered by Disqus