简体   繁体   English

如何从具有 controller 的页面获取 id 到具有不同 controller 的另一个页面

[英]How get id from page with a controller to another page with different controller

I have 3 tables: courriersEntrees, traitements, users我有 3 个表:courriersEntrees、traitements、users

I have to create a traitement when the user clicks button 'affecter traitement' in index page that presents a list of courriers.当用户在显示快递员列表的索引页面中单击按钮“affecter traitement”时,我必须创建一个 traitement。

How can I get the id of the courrier clicked to the create function?如何获取点击创建function的快递员id?

my index.blade.php of courriersEntreeController:我的 index.blade.php 的 courriersEntreeController:

  <table class="table">
        <head>
            <tr>
                <th>emetteur</th>
                <th>sujet</th>
                <th>date recu</th>
                <th>type</th>
                

            </tr>
        </head>
        <body>
            @foreach($courriers as $courrier)
            <tr>
                <td>{{ $courrier->emetteur}}</td>
                <td>{{$courrier->sujet}}</td>
                
                <td>{{$courrier->date_recus}}</td>
                <td>{{$courrier->type}}</td>
                <td>
                   


                    <form action="{{url('courriers/'.$courrier->id) }}" method="post">

                        {{csrf_field()}}
                        {{method_field('DELETE')}}

                         <a href="" class="btn btn-primary"> detail </a>
                    <a href="{{url('courriers/'.$courrier->id.'/edit')}}" class="btn btn-primary"> editer </a>
                     <a href="{{url('traitements/create/')}}" class="btn btn-primary"> Affecter Traitement</a>
                    <button type="submit" class="btn btn-primary"> supprimer </button>
            </form>  
             </td>
            </tr>
            @endforeach
        </body>
    </table>

My traitementController我的特征控制器

 public function create()
    {    $courrier= courriersEntree::find($id);
        return view('traitement.create');
    }

My traitement table:我的特征表: 在此处输入图像描述

you have to pass the id from your view to the controller:您必须将视图中的 ID 传递给 controller:

<a href="{{ route('your route name',$courrier->id)}}" class="btn btn-primary"> Affecter Traitement</a>

Or with url like:或者像 url 这样:

<a href="{{url('traitements/create/'.$courrier->id)}}" class="btn btn-primary"> Affecter Traitement</a>

your controller seems to be:您的 controller 似乎是:

public function create($courrier_id)
    {    $courrier= courriersEntree::find($courrier_id);
        return view('traitement.create');
    }

If you logged with any user, You can get logged user id using \Auth::user()->id .如果您使用任何用户登录,您可以使用\Auth::user()->id获取登录的用户 ID。 If you just want to forward object id you can sent it in route <a href="{{route('routename',['id'=$id])}} . May this will helpful for you.如果您只想转发 object id,您可以在路线<a href="{{route('routename',['id'=$id])}}中发送它。希望这对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM