0

I'm trying to add a variable to input name, like this:

{!! Form::text('material[{{$num}}]', old('material[{{$num}}]'), ['class' => 'form-control', 'placeholder'=> '']) !!}

But in html it returns me this:

<input class="form-control" placeholder="" name="material[<?php echo e($num); ?>]" type="text">

And I don't understand what is the problem.

How can I solve that?

Thank you

4 Answers 4

5

You can't nest {{ }}.

If you want to get this:

name="material[1]" 

The correct syntax will be:

{!! Form::text('material[' . $num . ']', old('material[' . $num . ']'), ['class' => 'form-control', 'placeholder'=> '']) !!}
Sign up to request clarification or add additional context in comments.

Comments

2

Try this:

 {!! Form::text('material['.$num.']', old('material['.$num.']'), ['class' => 'form-control', 'placeholder'=> '']) !!}

When you are using {{ }} or {!! !!} means that you are already in php scope and you can put any php code

Comments

0

If material is an array then it should be like

{!! Form::text('material[$num]', old('material[$num]'), ['class' => 'form-control', 'placeholder'=> '']) !!}

Comments

0

You can not use {{}} in {!! !!}

You use

{!! Form::text('material[' . $num . ']', old('material[' . $num . ']'), ['class' => 'form-control', 'placeholder'=> '']) !!}

Or

{!! Form::text('material[$num]', old('material[$num]'), ['class' => 'form-control', 'placeholder'=> '']) !!}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.