How to pass variables by link and GET method with resource routes Laravel

0

I have a question, I am working on a project and I need to send a variable that contains an ID to my create method or that simply passes me the url, for that I am using resource type routes:

Route::resource('encuestaspy/participar', 'Users\RespuestaController');

This is my view

@foreach ($preguntas as $pregunta)
        @if($pregunta->user_id == $empresa->id)
            @if($pregunta->estado == 1 )

                <div class="col-sm-3 col-xs-6">
                    <div style="padding: 10px;"></div>
                      //qui es donde quiero mandar mi variable con cierto ID.
                    <a href="{{url('encuestaspy/participar/create'.$pregunta->pregunta_id)}}">
                        @if(empty($pregunta->foto))
                            <img class="img-responsive portfolio-item" width="300" src="http://placehold.it/500x300" alt="">
                        @else
                            <img id="imagen" class="img-responsive portfolio-item" src="{{asset('imagenes/encuestas/'.$pregunta->foto)}}" width="300" alt="">
                        @endif
                    </a>
                    <p class="text-center">{{$pregunta->titulo}}</p>
                    @if ($dt->format('Y-m-d H:i:s') > $pregunta->fecha_finalizacion)
                        <p style="color:#FF0000"; class="text-center">Encuesta finalizada</p>
                    @endif
                    <p class="text-center"><b>Culmina el:</b>{{$pregunta->fecha_finalizacion}}</p>
                </div>
            @endif
        @endif
    @endforeach

This is the method of my controller, which for now only returns a view because I still do not write anything because I need the id to start

public function create()
{
    //
    return view('welcome');
}

EYE: I know that the variables I need can be sent by GET routes, but I need them to be with routes of RESOURCE types by order of my boss: (

    
asked by Hernan Chaparro 04.09.2018 в 21:51
source

1 answer

1

So I see the resource already has pre-established routes and I do not think you can use encuestaspy/participar/create/{id} . What you can do is pass the GET method the identifier in your view {{ url('encuestaspy/participar/create?id'.$pregunta->pregunta_id) }} in such a way that you can receive the following form in your controller.

public function create(Request $request)
{
    $id = $request->id;
    //
}
    
answered by 04.09.2018 в 23:09