0

Into my edit.blade.php, i can display the value into my input like this for prepare my update:

<div>
     <x-label for="name" value="name" />
     <x-input id="name" name="name" :value="$user->name" />
     <x-label for="email" value="email" />
     <x-input id="email" value="email" :value="$user->email" />
</div>

This works but that code not :

  <label name="name" id="name" class="bg-white text-gray-600 px-1">Name</label>
  <input name="name" id="name" {{ $user->name }} autocomplete="false" tabindex="0" type="text" class="py-1 px-1 text-gray-900 outline-none block h-full w-full">

I want just to use input and not x-input.

What are the differents ?

How can i display my value into my input ?

I found that but for 9 years it has to evolve, no ?

How to Set Variables in a Laravel Blade Template

Fradé
  • 195
  • 1
  • 2
  • 9

4 Answers4

2

Here how it will work Laravel blade.

 <label name="name" id="name" class="bg-white text-gray-600 px-1">Name</label>
 <input name="name" id="name" value="{{ $user->name }}" autocomplete="false" tabindex="0" type="text" class="py-1 px-1 text-gray-900 outline-none block h-full w-full">
Usman
  • 339
  • 3
  • 15
2

Solution

<label name="name" id="name" class="bg-white text-gray-600 px-1">Name</label>
<input name="name" id="name" value="{{ $user->name }}" type="text" >
1

1: create component

php artisan make:component InputComponent

2: InputComponent

<?php

namespace App\View\Components\Form;

use Illuminate\View\Component;

class InputComponent extends Component
{

public $name;
public $title;
public $value;
public $type;

public function __construct($name,$title,$value=null,$type = null)
{
    $this->name = $name;
    $this->title = $title;
    $this->value = $value;
    $this->type = $type;
}

public function render()
{
    return view('components.form.input-component');
}
}

3: in input-component.blade.php

<div class="form-group my-2">
   <label class="py-2" for="{{$name}}">{{$title}}</label>
   <input type="{{$type ?? 'text'}}" class="form-control" name="{{$name}}"      id="{{$name}}" @isset($value) value="{{$value}}" @endisset>
   <small class="form-text text-danger">{{$errors->first($name)}}</small>
</div>

4: in AppServiceProvider and boot method

Blade::component('form.input-component', InputComponent::class);

5: use in blades:

<x-form.input-component name="title" value="{{old('title')}}" title="title"/>
0

This should work.

<label name="name" id="name" class="bg-white text-gray-600 px-1">Name</label>
<input name="name" id="name" value="{{ isset($user->name) ? $user->name : '' }}" autocomplete="false" tabindex="0" type="text" class="py-1 px-1 text-gray-900 outline-none block h-full w-full">