#Problem of recovery of an element selected in a select

6 messages · Page 1 of 1 (latest)

obsidian helm
#

Hello, I am a beginner in laravel. I want to implement a feature that I detail below:

I want to use laravel 8 and php :
1/ Select a part of the data in a table (via a select)
- how to get the id selected in the select
2/ Copy the data and insert it in another table (via an add button)
- how to recover the id present in the url of the page
3/ Display the data inserted in a table
- no problem
`

<select name="id_segment" class="form-control">

                        <?php
                        
                        $req1 = DB::select("SELECT id_segment, nom_segment FROM `segements` ");

foreach ($req1 as $re1 => $r1) {
?>
<option name="id_segment" value="{{ $r1->id_segment }}"> {{ $r1->id_segment }}
{{ $r1->nom_segment }}</option>
<?php
} ?>
</select>

                </div>
            </div>


            <div class="col-xs-12 col-sm-12 col-md-12 text-center">
                <button type="submit" class="btn btn-primary" id="AjoutSegment">Ajouter</button>
                <a class="btn btn-primary" href="{{ route('groupecampagnes.index') }}"> Back</a>
            </div>

`

I have already tried with $_POST and $_GET while making a var_dump, but I have seen that some people say that it does not work, me it gave me the display of an error with the id that I seek to recover precisely, whereas it should just display it to me on the page to see if I recover it well and truly. The var_dump is not present in the code because I removed it in the meantime. After I tried various solutions found on the net, which have me display as error for some of them that I had to do with a std class object.

verbal ice
#

You’ll need to start reading the Laravel docs. It will tell you have to do things like access request input, query string values, etc.

#

If you keep trying to just “force” solutions without an understanding of the framework or reading any of its documentation, then you’re going to have a rough time.

empty plinth
#

I also agree with @verbal ice
Please note some Laravel's architecture is MVC. However, your code's mixed up with view, controller in one spot.
You can put the code line of getting all rows of segments into the controller. Please keep using all useful features of Eloquent ORM instead of a raw sql. This way, you can produce the qualified codes.
In Laravel world, almost of all cases(tbh 100%), $_POST and $_GET are not used directly.
You can get any desired post or get param with $request->input('parameter_name');
Instead of var_dump, you can debug with dd function

obsidian helm
#

I thank you for your answer to both of you, and I apologize for answering you that now I have been quite busy. I have already tried with the eloquent orm with the help of the Nord Coders video, but I couldn't get it to work, and I had even taken the laravel 8 documentation next to it. But in view of your answers, I'll try again and I'll let you know if it works.