How to get the next record in a Table using Laravel?

Ryan Sacks :

I have a Table in my database called job_seeker_profiles, where I store the profiles of those seeking a job. I have a controller called AdminEmployerSearchController, where Employers can view the profiles of the job seekers, with this show method:

public function show()
    {
        $jobSeekerProfiles = JobSeekerProfile::limit(1)->get();

        return view('admin.employer.search.show', compact('jobSeekerProfiles'));
    }

It's showing me the first record in the Table, which is what I want, to show one record at a time. I have a button in my view called 'Skip', where when clicked, I want it to show the next record in the database, right now its showing me record 1, so when clicked it would go to record 2, then record 3, then record 4 etc. It's like a Prev and Next functionality.

show.blade.php file:

@extends('layouts.admin')

@section('content')

    @if($jobSeekerProfiles)

        @foreach($jobSeekerProfiles as $jobSeekerProfile)

            <div class="row">
                <div class="col-md-12">
                    <video width="100%" height="100%" controls>
                        <source src="{{ asset('videos/1583095973A man DJing an event.mp4') }}" type="video/mp4">
                        Your browser does not support the video tag.
                    </video>
                </div>
                <div class="col-md-6">
                    <br>
                    <h1 class="h1-admin">{{$jobSeekerProfile->first_name}} {{$jobSeekerProfile->last_name}}</h1>
                </div>
                <div class="col-md-6 text-right">
                    <br>
                    <video width="100" height="auto" controls>
                        <source src="{{ asset('videos/1583095973Man Doing Rap Music.mp4') }}" type="video/mp4">
                        Your browser does not support the video tag.
                    </video>
                    <video width="100" height="auto" controls>
                        <source src="{{ asset('videos/1583095973Tractor Cutting Grass In The Field.mp4') }}" type="video/mp4">
                        Your browser does not support the video tag.
                    </video>
                </div>
                <div class="col-md-12">
                    <h3>Experience:</h3>
                    <p>{{$jobSeekerProfile->experience}}</p>
                    <h3>Additional Skills:</h3>
                    <p>{{$jobSeekerProfile->additional_skills}}</p>
                </div>
                <div class="col-md-6">
                    <button type="button" class="btn btn-lg btn-block btn-danger">Skip</button>
                </div>
                <div class="col-md-6">
                    <button type="button" class="btn btn-lg btn-block btn-success">Interview</button>
                </div>
                <div class="col-md-12">
                    <br><br>
                    <hr><br><br>
                </div>
            </div>

        @endforeach

    @endif

@stop

I thought that I would have to find the id in the Table and then work with that, but I can't seem to get it working. Below is a screenshot of the page, you'll see what I mean. enter image description here

S K R :

You should use ->skip() or ->offset() method to define the starting point, and ->take() method to get number of data

JobSeekerProfile::get()->offset(2)->take(1);

Will return 3rd result skipping first 2 records.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=170790&siteId=1