S
S
supercoder6662021-04-11 14:54:52
Laravel
supercoder666, 2021-04-11 14:54:52

Why is the variable not being passed to the controller from the form?

The variable is not passed from the form to the controller. dd() shows that the variable is not receiving anything.

Template code:

<form action="{{ route('setTopic'}}" method="post" enctype="multipart/form-data">   
@csrf            
<div class="select-box">
<label for="select-box1" class="label select-box1"><span class="label-desc">Choose topic</span></label><button type="submit" class="btn btn-outline-success">Save</button>
<select id="select-box1" class="select" name="selectSetTopic">
@foreach($dataCategories  as $topic)
<option value="{{$topic->id}}">{{ $topic->name }}</option>
@endforeach
</select>
</div>
</form>

Code from controller:
public function setTopic(Request $selectSetTopic) {
dd($selectSetTopic);
return redirect()->route('post')->with('success', 'Ok!');
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey delphinpro, 2021-04-11
@supercoder666

Why name variables like that? Why not leave the default name. Moreover, it accurately displays the entity (I'm talking about $request).

public function setTopic(Request $request) {
  $selectSetTopic = $request->input('selectSetTopic');
  dd($selectSetTopic);
  return redirect()->route('post')->with('success', 'Ok!');
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question