Skip to content

Commit 521964b

Browse files
Add author info and question creation date in question item
1 parent c8b29cb commit 521964b

File tree

7 files changed

+173
-4
lines changed

7 files changed

+173
-4
lines changed

app/Http/Controllers/QuestionsController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class QuestionsController extends Controller
1414
*/
1515
public function index()
1616
{
17-
$questions = Question::latest()->paginate(5);
17+
$questions = Question::with('user')->latest()->paginate(15);
1818

1919
return view('questions.index', compact('questions'));
2020
}

app/Question.php

+10
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,14 @@ public function setTitleAttribute($value)
1818
$this->attributes['title'] = $value;
1919
$this->attributes['slug'] = str_slug($value);
2020
}
21+
22+
public function getUrlAttribute()
23+
{
24+
return route("questions.show", $this->id);
25+
}
26+
27+
public function getCreatedDateAttribute()
28+
{
29+
return $this->created_at->diffForHumans();
30+
}
2131
}

app/User.php

+6
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,10 @@ public function questions()
3131
{
3232
return $this->hasMany(Question::class);
3333
}
34+
35+
public function getCreatedDateAttribute()
36+
{
37+
// return $this->created_at->diffForHumans();
38+
return'#';
39+
}
3440
}

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
"laravel/tinker": "~1.0"
1212
},
1313
"require-dev": {
14+
"barryvdh/laravel-debugbar": "*",
1415
"filp/whoops": "~2.0",
15-
"nunomaduro/collision": "~1.1",
1616
"fzaninotto/faker": "~1.4",
1717
"mockery/mockery": "~1.0",
18+
"nunomaduro/collision": "~1.1",
1819
"phpunit/phpunit": "~7.0",
1920
"symfony/thanks": "^1.0"
2021
},

composer.lock

+146-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/views/questions/index.blade.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
@foreach ($questions as $question)
1212
<div class="media">
1313
<div class="media-body">
14-
<h3 class="mt-0">{{ $question->title }}</h3>
14+
<h3 class="mt-0"><a href="{{ $question->url }}">{{ $question->title }}</a></h3>
15+
<p class="lead">
16+
Asked by
17+
<a href="{{ $question->user->url }}">{{ $question->user->name }}</a>
18+
<small class="text-muted">{{ $question->created_date }}</small>
19+
</p>
1520
{{ str_limit($question->body, 250) }}
1621
</div>
1722
</div>

storage/debugbar/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

0 commit comments

Comments
 (0)