Luthermilla Ecole
Luthermilla Ecole

Reputation: 786

Laravel: How can I pass a single ID in route

I am building a system so the user can request for multiple things, and I want to be able to visualize the details about each request (individually) made in the system. The current method gives me everything at once, and not separated.

Here is the part of the code

The controller

 public function verDetalhesKeys($id)
{  
    $detalhes = DB::table('keysRequest')  
    ->where('keysRequest.id','=', $id)
    ->select('keysRequest.*')
    ->get();

    return view('Admin.keysRequestDetails',compact('detalhes'));
}

The route

Route::get('/detalhesK/{id}', 'AdminController@verDetalhesKeys') -> name('detalhesK');

The button to Visualize the details

<table class="table table-striped">
    <thead>
        <tr>
            <th>Name</th>
            <th>Email</th>
            <th>Department</th>
            <th>Site</th>
            <th>Pourpose</th>
            <th>From</th>
            <th>To</th>
        </tr>
    </thead>
    <tbody>
        @foreach($keys as $s)
        <tr>
            <td>{{$s->name}}</td>
            <td>{{$s->email}}</td>
            <td>{{$s->department}}</td>
            <td>{{$s->site}}</td>
            <td>{{$s->purpose}}</td>
            <td>{{$s->till}}</td>
            <td>{{$s->until}}</td>
            <td style="display:none;">{{$s->id}}</td>
            <td><a class="btn btn-info btn-md" href="{{ route('detalhesK',['id' => $s->id])}}" style="background-color:#00a3b3;"><i class="fa fa-eye" aria-hidden="true"></i></a></td>
        </tr>
        @endforeach
    </tbody>
</table>

The page of the details

   <div class="container">
   <div class="row justify-content-center">
    <div class="col-16 col-md-12 col-lg-12 pb-7">
                <!--Form with header-->
                <form  method="post">
                    @foreach($detalhes as $d)
                    <div class="card border-primary rounded-0">
                        <div class="card-header p-0">
                            <div class="bg-info text-white text-center py-2">
                                <h3>Requisição de Chaves Detalhes || Keys Request Details</h3>
                            </div>
                        </div>
                        <div class="card-body p-3">

                            <!--Body-->
                            <div class="form-group">
                                  <label>Nome || Name</label>
                                    <input type="text" class="form-control" placeholder="{{$d->name}}" readonly>
                            </div>

                            <div class="form-group">
                                   <label>Email</label>
                                    <input type="email" class="form-control"  placeholder="{{$d->email}}" readonly>
                            </div>

                            <div class="form-group">
                                   <label>Departamento || Department</label>
                                    <textarea class="form-control" placeholder="{{$d->department}}" readonly></textarea>
                            </div>

                            <div class="form-group">
                                <div class="input-group mb-2">
                                   <label>Local || Site</label>
                                    <textarea class="form-control" placeholder="{{$d->site}}" readonly></textarea>
                            </div>

                             <br>

                            <div class="form-group">
                                   <label>Finalidade || Purpose</label>
                                    <input type="Quantidade" class="form-control"  placeholder="{{$d->purpose}}" readonly>
                            </div>


                            <div class="form-group">                                   
                                   <label>Período de uso das chaves || Period of use of the keys</label>
                                    <textarea class="form-control" placeholder="{{$d->till}} - {{$d->until}}" readonly></textarea>
                            </div>
                            <div class="text-center">
                                <a class="btn btn-danger" href=""><font color="white"> Rejeitar || Refuse </font></a>
                                 <a class="btn btn-success" href=""><font color="white"> Validar || Validate </font></a>
                            </div>
                        </div>
                    @endforeach
                    </div>
                </form>
                <!--Form with header-->

            </div>

Upvotes: 0

Views: 176

Answers (1)

Emmanuel Fore
Emmanuel Fore

Reputation: 44

first of all is 'id' the column to primary key in your database table, you need to make sure it is so you wont have dublicate products.Edit your query to $detalhes = DB::table('keysRequest')->find(id);. After doing that, wont need to use a loop to ouput your result since its only 1 item. just use {{$detalhes->something}}

Upvotes: 1

Related Questions