Laravel 5从URL获取ID [英] Laravel 5 getting ID from URL

查看:85
本文介绍了Laravel 5从URL获取ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格视图,在其中可以单击按钮图标,然后重定向到另一页,其中包含已单击行的 id .

I have a table view in which I can click an button icon and redirect to another page carrying the id of the row that has been clicked.

@foreach ($patients as $patient)
    <tr>
        <td>{{ $patient->pID }}</td>
        <td>{{ $patient->pName }}</td> 
        <td>{{ $patient->pAddress }}</td>
        <td>{{ $patient->pBday }}</td>
        <td>{{ $patient->pPhone}}</td>
        <td>{{ $patient->pEcon }}</td>
        <td>{{ $patient->pDreg }}</td>
        <td></td>
        <td>
            <a href="{{ URL::to('visit/'.$patient->pID) }}">
                <img src="../images/viewvisit.png" style="width:30px; height:30px;">
            </a>
        </td>
        <td>
            <a href="{{ URL::to('addeditvisit/'.$patient->pID) }}">
                <img src="../images/visit.png" style="width:30px; height:30px;">
            </a>
        </td>
        <td>
            <a href="{{ URL::to('editpatient/'.$patient->pID) }}">
                <img src="../images/update.png" style="width:30px; height:30px;">
            </a>
        </td>
        <td>
            <a href="{{ URL::to('deletepatient/'.$patient->pID) }}">
                <img src="../images/delete.png" style="width:30px; height:30px;">
            </a>
        </td>
    </tr>
@endforeach 

我想要的是从URL中获取 id 并将其放入变量中,以便我可以在其他页面中使用它.

what I want is to get the id from the URL and put it in a variable so that I can utilize it my other page.

我目前仍在使用此控制器功能.

I'm currently stuck with this controller function.

public function index(Request $request) {   

    $doctors = Doctor::where('dStatus', 0)
        ->lists('dName', 'dID');
    $beds = Bed::where('bStatus', 0)
        ->lists('bName', 'bID');
    $patient = Patient::patient();
    // $uri = $request->path('patient');

    return View::make('pages.addeditvisit', [
        'doctors'=>$doctors,
        'beds'=>$beds,
        'patient'=>$patient->pID
    ]);
}

推荐答案

这很晚.但是为了像我这样的其他人的利益;

This is late. But for the benefit of others like me;

如果您不必按照上述答案所示的方法进行操作,则从Laravel 5.0开始(不确定以前的版本),可以执行

If you do not have to do it in a method like the answers above have shown, As of Laravel 5.0 (Not sure about previous versions), you can do

$request->route('id');

这将返回路由上的id参数的值.

That returns the value of the id parameter on the route.

这篇关于Laravel 5从URL获取ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆