Ansjovis86
Ansjovis86

Reputation: 1545

How to use variable in value attribute of textarea in Laravel - Blade?

I've got the following blade file. I'm passing in a project object with a title and description and I want to populate the value attributes. The description variable works inside the p-tag, but not in the textarea-tag. The $title variable works fine also. Why doesn't it work in the textarea?

@extends('layout')

@section('content')

    <h1 class="display-4">Edit Project</h1>


    <p>{{ $project->description }}</p>


    <form>

      <div class="form-group">
        <label for="title">Title</label>
        <input type="text" class="form-control" name="title" placeholder="Title" value="{{ $project->title }}">
      </div>

      <div class="form-group">
        <label for="description">Description</label>
        <textarea type="text" class="form-control" name="description" value="{{ $project->description }}"></textarea>
      </div>


      <button type="submit" class="btn btn-primary">Update Project</button>
    </form>
@endsection

Upvotes: 1

Views: 8255

Answers (2)

tohasanali
tohasanali

Reputation: 934

It should be like

<textarea type="text" class="form-control" name="description" >{{ $project->description }}</textarea>

Upvotes: 1

Rouhollah Mazarei
Rouhollah Mazarei

Reputation: 4153

There is no value attribute in textarea tag. Instead, put the value between open and close tag:

<textarea type="text" class="form-control" name="description">{{ $project->description }}</textarea>

See this link for more information.

Upvotes: 7

Related Questions