Unable to display one database item per page without pagination
Hello all,
I am working on a project in order to get a better handle of Laravel 5.2 . The project is a simple app which takes a quote from the SQL database and displays it to the user. The user has an input field where he inputs his answer. If the user's input matches the author name, he gets a notification and his score increments by one, and the the next question is displayed. If the answer is incorrect, he is shown the correct answer and the next question is displayed.
Here is the relevant code from the Controller:
if (!$request->session()->has('index')) {
$index = 0;
$request->session()->set('index', $index);
} else {
$index = $request->session()->get('index');
$index = $index + 1;
}
$request->session()->set('index', $index);
When I use the above code in my view I get this error:
Trying to get property of non-object (View: ...),
relating to this bit:
<h2 class="text-center">Who said this famous quote? </h2>
<h3 class="text-center">" {{$quotes[Session::get('index')]->quote}} " </h3>
{{$currentId = $quotes[Session::get('index')]->author_id}}
The index is basically serving the same purpose as a for loop,( $quotes[1]->$quote) <-- this works, but if I set $index to 1, as opposed to $index + 1, it is not working. If I display the $index value by itself, as in (<h3>Session::get('index')</h3>), this is also working.
Additional code will be provided upon request.
Thank you in advance! (:
Please or to participate in this conversation.