dtjzpg5313
2019-03-08 03:50
浏览 105
已采纳

将值从表传递到Laravel中的另一个页面

I have a table with data showed from the MySQL database.

Here is my controller:

function getData() {
        $data['data'] = DB::table('act_hi_procinst')->get();

        if(count($data) > 0) {
            return view('datatracking', $data);
        } else {
            return view('datatracking');
        }
}

Here is my view:

@foreach($data as $data)
    <tr>
        <td><a href= "{{ url('/') }}"> {{ $data -> ID_ }}</a></td>
        <td>{{ $data -> PROC_INST_ID_ }}</td>
        <td>{{ $data -> BUSINESS_KEY_ }}</td>
        <td>{{ $data -> PROC_DEF_ID_ }}</td>
        <td>{{ $data -> START_TIME_ }}</td>
        <td>{{ $data -> END_TIME_ }}</td>
        <td>{{ $data -> DURATION_ }}</td>
        <td>{{ $data -> START_USER_ID_ }}</td>
        <td>{{ $data -> START_ACT_ID_ }}</td>
        <td>{{ $data -> END_ACT_ID_ }}</td>
        <td>{{ $data -> SUPER_PROCESS_INSTANCE_ID_ }}</td>
        <td>{{ $data -> DELETE_REASON_ }}</td>
        <td>{{ $data -> TENANT_ID_ }}</td>
        <td>{{ $data -> NAME_ }}</td>
    </tr>
@endforeach

I use href tag to make my first column into a link. I want when I click it, it will go to other page and passing the ID_ value to that page. I have no idea how to write it in Laravel.

图片转代码服务由CSDN问答提供 功能建议

我有一个表格,其中包含来自MySQL数据库的数据。

这里 是我的控制器:

  function getData(){
 $ data ['data'] = DB :: table('act_hi_procinst') - &gt; get(); \  n 
 if(count($ data)&gt; 0){
返回视图('datatracking',$ data); 
} else {
返回视图('datatracking'); 
} 
} 
  n   
 
 

以下是我的观点:

  @foreach($ data as $ data)
&lt; tr&gt;  
&lt; td&gt;&lt; a href =“{{url('/')}}”&gt;  {{$ data  - &gt;  ID_}}&lt; / a&gt;&lt; / td&gt; 
&lt; td&gt; {{$ data  - &gt;  PROC_INST_ID_}}&lt; / td&gt; 
&lt; td&gt; {{$ data  - &gt;  BUSINESS_KEY_}}&lt; / td&gt; 
&lt; td&gt; {{$ data  - &gt;  PROC_DEF_ID_}}&lt; / td&gt; 
&lt; td&gt; {{$ data  - &gt;  START_TIME_}}&lt; / td&gt; 
&lt; td&gt; {{$ data  - &gt;  END_TIME_}}&lt; / td&gt; 
&lt; td&gt; {{$ data  - &gt;  DURATION_}}&lt; / td&gt; 
&lt; td&gt; {{$ data  - &gt;  START_USER_ID_}}&lt; / td&gt; 
&lt; td&gt; {{$ data  - &gt;  START_ACT_ID_}}&lt; / td&gt; 
&lt; td&gt; {{$ data  - &gt;  END_ACT_ID_}}&lt; / td&gt; 
&lt; td&gt; {{$ data  - &gt;  SUPER_PROCESS_INSTANCE_ID_}}&lt; / td&gt; 
&lt; td&gt; {{$ data  - &gt;  DELETE_REASON_}}&lt; / td&gt; 
&lt; td&gt; {{$ data  - &gt;  TENANT_ID_}}&lt; / td&gt; 
&lt; td&gt; {{$ data  - &gt;  NAME_}}&lt; / td&gt; 
&lt; / tr&gt; 
 @ endforeach 
   
 
 

我使用 href 标签来制作我的 第一列成链接。 我希望当我点击它时,它会转到其他页面并将 ID_ value 传递给该页面。 我不知道如何在Laravel中编写它。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dph6308 2019-03-08 03:56
    已采纳

    You can add it's value into URL and can get it through a query string

    @foreach($data as $data)
         <tr>
             <td><a href= "{{ url('/') }}?id={{ $data -> ID_ }}"> {{ $data -> ID_ }}</a></td>
             <td>{{ $data -> PROC_INST_ID_ }}</td>
             <td>{{ $data -> BUSINESS_KEY_ }}</td>
             <td>{{ $data -> PROC_DEF_ID_ }}</td>
             <td>{{ $data -> START_TIME_ }}</td>
             <td>{{ $data -> END_TIME_ }}</td>
             <td>{{ $data -> DURATION_ }}</td>
             <td>{{ $data -> START_USER_ID_ }}</td>
             <td>{{ $data -> START_ACT_ID_ }}</td>
             <td>{{ $data -> END_ACT_ID_ }}</td>
             <td>{{ $data -> SUPER_PROCESS_INSTANCE_ID_ }}</td>
             <td>{{ $data -> DELETE_REASON_ }}</td>
             <td>{{ $data -> TENANT_ID_ }}</td>
             <td>{{ $data -> NAME_ }}</td>
         </tr>
    @endforeach
    

    In your controller, you can get value like:

    public function yourfuncName(Request $request)
    { 
        $id =  $request->get('id');
    }
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • dot_0620 2019-03-08 05:53

    Try this inside Your forloop

    <td><a href="{{ url('/gotoPage/'.$data->ID_) }}">GoTo</a></td>
    

    And My Suggestion

    While iterating the array

    Correct Way

    foreach ($data as $dataValue)
    {
       $dataValue->id;
    }
    

    WrongWay

    foreach ($data as $data)
    {
        $data->id;
    }
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题