skip to Main Content

So, in my project, a user needs to register first before logging-in. I am trying to display their first, middle and last name. But, I am having a problem since multiple data are displayed on my input field. What is the correct query? Here is my controller code

     public function get_first_name()
{
    $first_names = UserModel::all();
    $input="<input></input>";
    foreach($first_names as $first_name)
    {
        $input.="<input value={$first_name->seq_id}>{$first_name->first_name}</input>";
    }
    return $input;
}

    public function step1()
{
    $users = UserModel::all();
    $data['optStatus']=$this->get_civil_status();
    $data['displayFirstName']=$this->get_first_name();
    return view ("enrollment-steps.step1", $data);
}

Here is the blade file

    <div class="col-sm-12 col-lg-4">
     <div class="form-group row">
      <label for="firstName" class="col-sm-3 text-right control-label col-form-label">First 
       Name</label>
      <div class="col-sm-9">
      <input class="form-control" type="text" id='firstName' readonly value="{!! $displayFirstName !!}" >
      </div>
     </div>
    </div>

this is the data that it displays

2

Answers


  1. There is some confusing stuff going on there, but you probably want

    <input class="form-control" type="text" id='firstName' readonly value="{{ $data['displayFirstName'] }}" >
    

    which will display the value with the key ‘displayFirstName’ in the $data array.

    dd is your friend, use this in your blade file to see what you have in your $data variable.

    {{dd($data)}}
    
    Login or Signup to reply.
  2. In you controller bind the data’s in a single variable, then show it in the blade

    public function get_first_name()
        {
            $first_names = UserModel::all();
            $input="<input></input>";
            foreach($first_names as $first_name)
            {
                $input.="<input value={$first_name->seq_id}>{$first_name->first_name}</input>";
            }
            return $input;
        }
    

    Instead of this, do something like this:

    public function get_first_name()
        {
            $first_names = UserModel::all();
            $input="<input></input>";
            foreach($first_names as $first_name)
            {
                $displayname = $first_name->seq_id . $first_name->first_name;
                $input.="<input value="{$displayname}"</input>";
            }
            return $input;
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search