dongzichan2886
2018-12-03 11:32
浏览 112
已采纳

Laravel - 选择要在表格中显示的数据

I want to ask if ever I can limit my data in table. I want to remove one data out of my 6 data.

here is my table

Now I want to remove number 3 row which is SESSION_VALIDITY how can I remove that data and make it just 5 data in my table? I want to limit my data coz' I dont need to view SESSION_VALIDITY. help thanks

my Index

 @foreach ($settings as $setting)
                <tr>
                    <td>{{ $setting->settings_code }}</td>
                    <td>{{ $setting->subject}}</td>
                    <td>{{ $setting->description }}</td>

                    <td><a href="/admin/settings/{{ $setting->id }}/edit" class="fa fa-edit btn btn-info"></a></td>
                </tr>      
                @endforeach

my Controller

 public function index()
{
    $settings = Setting::all();
    return view('admin.settings.index', compact('settings'));
}
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • doulao2029 2018-12-03 11:38
    已采纳

    If you just want to not show that row in your $settings data, you can exclude it using your query like this.

    public function index()
    {
        $settings = Setting::where('settings_code', '<>', 'SESSION_VALIDITY')->get();
        return view('admin.settings.index', compact('settings'));
    }
    

    If you want to delete it entirely, you can run a one-time function to delete that row from the table.

    public function deleteSessionValidity()
    {
        $setting = Setting::where('settings_code', 'SESSION_VALIDITY')->first();
        $setting->delete();
    }
    
    已采纳该答案
    打赏 评论
  • duan1933 2018-12-03 11:37

    You should filter your query in the controller.

    Instead of Setting::all(), you should use:

    $settings = Setting::where('settings_code', '!=', 'SESSION_VALIDITY')->get();
    
    打赏 评论
  • dtutlamjasblef7982 2018-12-03 11:40

    You should try this:

    public function index()
    {
        $settings = Setting::where('settings_code', '!=', 'SESSION_VALIDITY')->get();
        return view('admin.settings.index', compact('settings'));
    }
    

    OR

     @foreach ($settings as $setting)
                    <tr>
                     @if($setting->settings_code != "SESSION_VALIDITY")
                        <td>{{ $setting->settings_code }}</td>
                        <td>{{ $setting->subject}}</td>
                        <td>{{ $setting->description }}</td>
    
                        <td><a href="/admin/settings/{{ $setting->id }}/edit" class="fa fa-edit btn btn-info"></a></td>
                     @endif
                    </tr>      
                    @endforeach
    
    打赏 评论
  • doushifen4060 2018-12-03 11:40

    inside foreach put if statement

    like:

    @foreach ($settings as $setting)
        @if ($setting->settings_code != "SESSION_VALIDITY")
    
         your <td> here
    
        @endif
    @endforeach
    
    打赏 评论

相关推荐 更多相似问题