Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AliShahbaz's avatar

I want to display the record on my page ?

hi guys i want to display the old posts record in my blade page and view it, so how can i display the record, My index.blade.php code is this:

<div class="row">
    <div class="col-sm-7">
      <h3>Search, Sort - AJAX</h3>
    </div>
    <div class="col-sm-5">
      <div class="pull-right">
        <div class="input-group">
            <input class="form-control" id="search"
                   value="{{ request()->session()->get('search') }}"
                   onkeydown="if (event.keyCode == 13) ajaxLoad('{{url('posts')}}?search='+this.value)"
                   placeholder="Search Title" name="search"
                   type="text" id="search"/>
            <div class="input-group-btn">
                <button type="submit" class="btn btn-primary"
                        onclick="ajaxLoad('{{url('posts')}}?search='+$('#search').val())">
                        <i class="fa fa-search" aria-hidden="true"></i>
                </button>
            </div>

        </div>

      </div>
    </div>
</div>
<!-- the dropdown goes here -->

<div class="form-horizontal" style="margin-bottom: 15px;">
      <form action="{{route('searchByDate')}}" method="post">
    {{csrf_field()}}
   <!-- {{ url('date','[ $id ]') }} -->
        <div class="form-inline" style="margin-left: -20px;">
            <div class="col-md-2 col-lg-2">
                <select id="searchBy" name="searchBy" class="form-control btn btn-secondary">
         <option selected>Choose a filter</option>
                 <option id="1" value="ThisWeek" >This Week</option>
         <option id="2" value="ThisMonth"> This Month</option>
         <option id="3" value="ThisYear"> This Year</option>
         <option id="4" value="CustomPeriod"> Custom</option>
                </select>
            </div>
            <div id="CustomSearchFields" style="display:none;">
            <div class=" col-lg-3 col-md-3">
                <div class="input-group date" id='startDate'>
                    <span class="input-group-addon">From</span>
                    <input type="text" id="startDateTextBox" class="form-control" name="startDate">
                    <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                </div>
            </div>

            <div class="col-lg-3 col-md-3">
                <div class="input-group date" id='endDate'>
                    <span class="input-group-addon">To</span>
                    <input type="text" id="endDateTextBox" class="form-control" name="endDate">
                    <span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
                </div>
            </div>
        </div>
        </div>
        <div class="col-lg-1 col-md-1 adminTaskIndexSeachBtn">
            <button class="btn btn-primary" type="submit">Search <span class="glyphicon glyphicon-search"></span></button>
        </div>
    </form>
</div>
 <!-- End Drop Down Menu -->
<table class="table">
    <thead>
    <tr>

        <th width="60px">No</th>
        <th><a href="javascript:ajaxLoad('{{url('posts?field=title&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}')">Post Title</a>
            {{request()->session()->get('field')=='title'?(request()->session()->get('sort')=='asc'?'&#9652;':'&#9662;'):''}}
        </th>

        <th style="vertical-align: middle">
            <a href="javascript:ajaxLoad('{{url('posts?field=description&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}')">
                Description
            </a>
            {{request()->session()->get('field')=='description'?(request()->session()->get('sort')=='asc'?'&#9652;':'&#9662;'):''}}
        </th>

        <th style="vertical-align: middle">
            <a href="javascript:ajaxLoad('{{url('posts?field=created_at&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}')">
                Created At
            </a>
            {{request()->session()->get('field')=='created_at'?(request()->session()->get('sort')=='asc'?'&#9652;':'&#9662;'):''}}
        </th>

        <th style="vertical-align: middle">
          <a href="javascript:ajaxLoad('{{url('posts?field=updated_at&sort='.(request()->session()->get('sort')=='asc'?'desc':'asc'))}}')">
            Update At
          </a>
          {{request()->session()->get('field')=='updated_at'?(request()->session()->get('sort')=='asc'?'&#9652;':'&#9662;'):''}}
        </th>
        <th width="160px" style="vertical-align: middle">
          <a href="javascript:ajaxLoad('{{url('posts/create')}}')"
             class="btn btn-primary btn-xs"> <i class="fa fa-plus" aria-hidden="true"></i> New Post</a>
        </th>
    </tr>
    </thead>
    <tbody>
    @php
        $i=1;
    @endphp
    @foreach ($posts as $post)
      <tr>
        <th>{{$i++}}</th>
        <td>{{ $post->title }}</td>
        <td >{{ $post->description }}</td>
        <td>{{ $post->created_at }}</td>
        <td>{{ $post->updated_at }}</td>
        <td>
          <a class="btn btn-info btn-xs" title="Show"
             href="javascript:ajaxLoad('{{url('posts/show/'.$post->id)}}')">
              Show</a>
            <a class="btn btn-warning btn-xs" title="Edit"
               href="javascript:ajaxLoad('{{url('posts/update/'.$post->id)}}')">
                Edit</a>
            <input type="hidden" name="_method" value="delete"/>
            <a class="btn btn-danger btn-xs" title="Delete"
               href="javascript:if(confirm('Are you sure want to delete?')) ajaxDelete('{{url('posts/delete/'.$post->id)}}','{{csrf_token()}}')">
                Delete
            </a>
        </td>
    </tr>
    @endforeach

    </tbody>
</table>

    <ul class="pagination">
        {{ $posts->links() }}
    </ul>

and also please tell me the function that i put in the PostController.php

0 likes
0 replies

Please or to participate in this conversation.