Search code examples
phplaravellaravelcollective

Pass data from LaravelCollective View Form to Controller


I build a view with a variable which I get from a Controller called {{$groupids}} but I don't get it in the Controller function.

<div class="panel-body">
                {{!! Form::open(array('route' => array('groupcreate_submit_test', $groupids))) !!}}
                    <div class="form-group">
                        Wollen Sie der Gruppe {{$groupids}} beitreten?
                    </div>
                        @if(@count(errors > 0))
                        @foreach($errors->all() as $error)
                            <div class="alert alert-danger">
                                {{$error}}
                            </div>
                        @endforeach
                        @endif
                    <div>
                        {{Form::submit('Ja',['class' => 'btn btn-primary'])}}
                        <a class="btn btn-default btn-close" href="{{ route('home') }}">Nein</a>
                    </div>
                {!! Form::close() !!} 
            </div>

Here is my route

Route::post('/home/grouprequest', 'GroupController@submit_Test')->name('groupcreate_submit_test');

Sees someone where my mistake is?

Thanks


Solution

  • Your variable $groupids implies ids as multiple ids. However the way you are using it in your route it seems like a single id. If you want to pass the $groupid to your controller as a route parameter specific it inside your route.

    Route::post('/home/grouprequest/{groupid}', 'GroupController@submit_Test')->name('groupcreate_submit_test');
    

    Then inside your controller add the parameter.

    public function submit_Test($groupid)
    

    Alternative use a hidden variable in your form.