Skip to content

Commit c8b29cb

Browse files
Display all questions
1 parent 0fbd56d commit c8b29cb

File tree

8 files changed

+285
-1
lines changed

8 files changed

+285
-1
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Question;
6+
use Illuminate\Http\Request;
7+
8+
class QuestionsController extends Controller
9+
{
10+
/**
11+
* Display a listing of the resource.
12+
*
13+
* @return \Illuminate\Http\Response
14+
*/
15+
public function index()
16+
{
17+
$questions = Question::latest()->paginate(5);
18+
19+
return view('questions.index', compact('questions'));
20+
}
21+
22+
/**
23+
* Show the form for creating a new resource.
24+
*
25+
* @return \Illuminate\Http\Response
26+
*/
27+
public function create()
28+
{
29+
//
30+
}
31+
32+
/**
33+
* Store a newly created resource in storage.
34+
*
35+
* @param \Illuminate\Http\Request $request
36+
* @return \Illuminate\Http\Response
37+
*/
38+
public function store(Request $request)
39+
{
40+
//
41+
}
42+
43+
/**
44+
* Display the specified resource.
45+
*
46+
* @param \App\Question $question
47+
* @return \Illuminate\Http\Response
48+
*/
49+
public function show(Question $question)
50+
{
51+
//
52+
}
53+
54+
/**
55+
* Show the form for editing the specified resource.
56+
*
57+
* @param \App\Question $question
58+
* @return \Illuminate\Http\Response
59+
*/
60+
public function edit(Question $question)
61+
{
62+
//
63+
}
64+
65+
/**
66+
* Update the specified resource in storage.
67+
*
68+
* @param \Illuminate\Http\Request $request
69+
* @param \App\Question $question
70+
* @return \Illuminate\Http\Response
71+
*/
72+
public function update(Request $request, Question $question)
73+
{
74+
//
75+
}
76+
77+
/**
78+
* Remove the specified resource from storage.
79+
*
80+
* @param \App\Question $question
81+
* @return \Illuminate\Http\Response
82+
*/
83+
public function destroy(Question $question)
84+
{
85+
//
86+
}
87+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@extends('layouts.app')
2+
3+
@section('content')
4+
<div class="container">
5+
<div class="row justify-content-center">
6+
<div class="col-md-12">
7+
<div class="card">
8+
<div class="card-header">All Questions</div>
9+
10+
<div class="card-body">
11+
@foreach ($questions as $question)
12+
<div class="media">
13+
<div class="media-body">
14+
<h3 class="mt-0">{{ $question->title }}</h3>
15+
{{ str_limit($question->body, 250) }}
16+
</div>
17+
</div>
18+
<hr>
19+
@endforeach
20+
21+
<div class="mx-auto">
22+
{{ $questions->links() }}
23+
</div>
24+
</div>
25+
</div>
26+
</div>
27+
</div>
28+
</div>
29+
@endsection
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
@if ($paginator->hasPages())
2+
<ul class="pagination justify-content-center" role="navigation">
3+
{{-- Previous Page Link --}}
4+
@if ($paginator->onFirstPage())
5+
<li class="page-item disabled" aria-disabled="true" aria-label="@lang('pagination.previous')">
6+
<span class="page-link" aria-hidden="true">&lsaquo;</span>
7+
</li>
8+
@else
9+
<li class="page-item">
10+
<a class="page-link" href="{{ $paginator->previousPageUrl() }}" rel="prev" aria-label="@lang('pagination.previous')">&lsaquo;</a>
11+
</li>
12+
@endif
13+
14+
{{-- Pagination Elements --}}
15+
@foreach ($elements as $element)
16+
{{-- "Three Dots" Separator --}}
17+
@if (is_string($element))
18+
<li class="page-item disabled" aria-disabled="true"><span class="page-link">{{ $element }}</span></li>
19+
@endif
20+
21+
{{-- Array Of Links --}}
22+
@if (is_array($element))
23+
@foreach ($element as $page => $url)
24+
@if ($page == $paginator->currentPage())
25+
<li class="page-item active" aria-current="page"><span class="page-link">{{ $page }}</span></li>
26+
@else
27+
<li class="page-item"><a class="page-link" href="{{ $url }}">{{ $page }}</a></li>
28+
@endif
29+
@endforeach
30+
@endif
31+
@endforeach
32+
33+
{{-- Next Page Link --}}
34+
@if ($paginator->hasMorePages())
35+
<li class="page-item">
36+
<a class="page-link" href="{{ $paginator->nextPageUrl() }}" rel="next" aria-label="@lang('pagination.next')">&rsaquo;</a>
37+
</li>
38+
@else
39+
<li class="page-item disabled" aria-disabled="true" aria-label="@lang('pagination.next')">
40+
<span class="page-link" aria-hidden="true">&rsaquo;</span>
41+
</li>
42+
@endif
43+
</ul>
44+
@endif
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
@if ($paginator->hasPages())
2+
<ul class="pagination" role="navigation">
3+
{{-- Previous Page Link --}}
4+
@if ($paginator->onFirstPage())
5+
<li class="disabled" aria-disabled="true" aria-label="@lang('pagination.previous')">
6+
<span aria-hidden="true">&lsaquo;</span>
7+
</li>
8+
@else
9+
<li>
10+
<a href="{{ $paginator->previousPageUrl() }}" rel="prev" aria-label="@lang('pagination.previous')">&lsaquo;</a>
11+
</li>
12+
@endif
13+
14+
{{-- Pagination Elements --}}
15+
@foreach ($elements as $element)
16+
{{-- "Three Dots" Separator --}}
17+
@if (is_string($element))
18+
<li class="disabled" aria-disabled="true"><span>{{ $element }}</span></li>
19+
@endif
20+
21+
{{-- Array Of Links --}}
22+
@if (is_array($element))
23+
@foreach ($element as $page => $url)
24+
@if ($page == $paginator->currentPage())
25+
<li class="active" aria-current="page"><span>{{ $page }}</span></li>
26+
@else
27+
<li><a href="{{ $url }}">{{ $page }}</a></li>
28+
@endif
29+
@endforeach
30+
@endif
31+
@endforeach
32+
33+
{{-- Next Page Link --}}
34+
@if ($paginator->hasMorePages())
35+
<li>
36+
<a href="{{ $paginator->nextPageUrl() }}" rel="next" aria-label="@lang('pagination.next')">&rsaquo;</a>
37+
</li>
38+
@else
39+
<li class="disabled" aria-disabled="true" aria-label="@lang('pagination.next')">
40+
<span aria-hidden="true">&rsaquo;</span>
41+
</li>
42+
@endif
43+
</ul>
44+
@endif
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@if ($paginator->hasPages())
2+
<div class="ui pagination menu" role="navigation">
3+
{{-- Previous Page Link --}}
4+
@if ($paginator->onFirstPage())
5+
<a class="icon item disabled" aria-disabled="true" aria-label="@lang('pagination.previous')"> <i class="left chevron icon"></i> </a>
6+
@else
7+
<a class="icon item" href="{{ $paginator->previousPageUrl() }}" rel="prev" aria-label="@lang('pagination.previous')"> <i class="left chevron icon"></i> </a>
8+
@endif
9+
10+
{{-- Pagination Elements --}}
11+
@foreach ($elements as $element)
12+
{{-- "Three Dots" Separator --}}
13+
@if (is_string($element))
14+
<a class="icon item disabled" aria-disabled="true">{{ $element }}</a>
15+
@endif
16+
17+
{{-- Array Of Links --}}
18+
@if (is_array($element))
19+
@foreach ($element as $page => $url)
20+
@if ($page == $paginator->currentPage())
21+
<a class="item active" href="{{ $url }}" aria-current="page">{{ $page }}</a>
22+
@else
23+
<a class="item" href="{{ $url }}">{{ $page }}</a>
24+
@endif
25+
@endforeach
26+
@endif
27+
@endforeach
28+
29+
{{-- Next Page Link --}}
30+
@if ($paginator->hasMorePages())
31+
<a class="icon item" href="{{ $paginator->nextPageUrl() }}" rel="next" aria-label="@lang('pagination.next')"> <i class="right chevron icon"></i> </a>
32+
@else
33+
<a class="icon item disabled" aria-disabled="true" aria-label="@lang('pagination.next')"> <i class="right chevron icon"></i> </a>
34+
@endif
35+
</div>
36+
@endif
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@if ($paginator->hasPages())
2+
<ul class="pagination" role="navigation">
3+
{{-- Previous Page Link --}}
4+
@if ($paginator->onFirstPage())
5+
<li class="page-item disabled" aria-disabled="true">
6+
<span class="page-link">@lang('pagination.previous')</span>
7+
</li>
8+
@else
9+
<li class="page-item">
10+
<a class="page-link" href="{{ $paginator->previousPageUrl() }}" rel="prev">@lang('pagination.previous')</a>
11+
</li>
12+
@endif
13+
14+
{{-- Next Page Link --}}
15+
@if ($paginator->hasMorePages())
16+
<li class="page-item">
17+
<a class="page-link" href="{{ $paginator->nextPageUrl() }}" rel="next">@lang('pagination.next')</a>
18+
</li>
19+
@else
20+
<li class="page-item disabled" aria-disabled="true">
21+
<span class="page-link">@lang('pagination.next')</span>
22+
</li>
23+
@endif
24+
</ul>
25+
@endif
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@if ($paginator->hasPages())
2+
<ul class="pagination" role="navigation">
3+
{{-- Previous Page Link --}}
4+
@if ($paginator->onFirstPage())
5+
<li class="disabled" aria-disabled="true"><span>@lang('pagination.previous')</span></li>
6+
@else
7+
<li><a href="{{ $paginator->previousPageUrl() }}" rel="prev">@lang('pagination.previous')</a></li>
8+
@endif
9+
10+
{{-- Next Page Link --}}
11+
@if ($paginator->hasMorePages())
12+
<li><a href="{{ $paginator->nextPageUrl() }}" rel="next">@lang('pagination.next')</a></li>
13+
@else
14+
<li class="disabled" aria-disabled="true"><span>@lang('pagination.next')</span></li>
15+
@endif
16+
</ul>
17+
@endif

routes/web.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
|--------------------------------------------------------------------------
77
|
88
| Here is where you can register web routes for your application. These
9-
| routes are loaded by the RouteServiceProvider within a group which
9+
| routes are loaded by the RouteServi`ceProvider within a group which
1010
| contains the "web" middleware group. Now create something great!
1111
|
1212
*/
@@ -18,3 +18,5 @@
1818
Auth::routes();
1919

2020
Route::get('/home', 'HomeController@index')->name('home');
21+
22+
Route::resource('questions', 'QuestionsController');

0 commit comments

Comments
 (0)