How to bind current image to update form field with Laravel?

1.5k views Asked by At

Here is my update form, but I am using it as a partial, I wanted to embed current image to the file field which is named as "thumbnail". Can any one tell me how can I take the current image if a new image is not selected to the file field. And how to include the date from database value?

{!! Form::model($article, ['method' => 'PATCH', 'files' => true, 'action' =>['ArticlesController@update', $article->id]]) !!}

<!-- Form thumbnail  Input -->
<div class="form-group">
    {!! Form::label('thumbnail', 'Thumbnail:', ['class' => 'control-label']) !!}
    @if($article->thumbnail)
        <div class="col-xs-2 thumb">
            <a class="thumbnail" href="#">
                <img class="img-responsive" src="/images/tn-{{$article->thumbnail}}"
                     alt="{{$article->titlel}}">
            </a>
        </div>
    @endif

        {!! Form::file('thumbnail', null, ['class' => 'form-control file']) !!}

</div>
<br>
<!-- Form body Input -->
<div class="form-group">
    {!! Form::label('body', 'Body:', ['class' => 'control-label']) !!}
    {!! Form::textarea('body', null, ['class' => 'form-control']) !!}
</div>

<!-- Form published_at Input -->
<div class="form-group">
    {!! Form::label('published_at', 'Published:', ['class' => 'control-label']) !!}
    {!! Form::input('date', 'published_at', date('Y-m-d'), ['class' => 'form-control']) !!}
</div>

<!-- Form Update Article  Input -->
<div class="form-group">
    {!! Form::submit($submitButtonText, ['class' => 'form-control btn btn-info pull-right']) !!}
</div>

{!! Form::close() !!}
1

There are 1 answers

1
Boris On

About the date part of the question

    {!! Form::input('date', 'published_at', $article->published_at, ['class' => 'form-control']) !!}

PS: I would recommend, if there is no other logic behind, to use the default created_at field instead of published_at.