2 years ago

Foreach loop in HTML Form Builder form

Posted 2 years ago by JokersMild85

I wish I could more eloquently explain what I am trying to accomplish here but I am still quite new to Laravel so please forgive if I misuse any terminology in my explanation.

I am trying to apply a foreach loop to my form that I built using the Laravel Collective HTML Form Builder (...correct?) and apply the values I pull from the database to the value fields of the form.

The output it is giving me is what is literally typed in my code. I know its because of the single quotation marks but if I remove them I get a syntax error for not including them.

Here is my code below as it will probably explain what I am trying to do better than how I am describing it.

The controller create function:

public function create()
    $exercise_types = ExerciseType::all();
    return view('workouts.create', ['exercise_types' => $exercise_types]);

The create view:



Create New Workout

{!! Form::open(['url' => 'workouts']) !!}

@include ('workouts.form', ['submitButtonText' => 'Create Workout'])

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


The form view itself:

@foreach($exercise_types as $exercise_type)

{!! Form::label('exercise_type', '{{ $exercise_type->exercise_type }}:') !!}
@foreach($exercise_type->exercises as $exercise)

    {!! Form::checkbox( '{{ $exercise->exercise_name }}', '{{ $exercise->id }}-{{ $exercise->exercise_type_id }}-{{ $exercise->exercise_name }}') !!}



{!! Form::submit($submitButtonText, ['class' => 'btn btn-primary form-control']) !!}

Any guidance would be appreciated.

Please sign in or create an account to participate in this conversation.