Skip to content

Commit f7f2216

Browse files
authored
Merge pull request #27 from laravelcm/user-dashboard
User dashboard
2 parents 3a3da41 + 1444614 commit f7f2216

29 files changed

+600
-41
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\User;
4+
5+
use App\Http\Controllers\Controller;
6+
use Illuminate\Support\Facades\Auth;
7+
8+
class DashboardController extends Controller
9+
{
10+
public function dashboard()
11+
{
12+
return view('user.dashboard', [
13+
'user' => $user = Auth::user(),
14+
'articles' => $user->articles()
15+
->orderByDesc('submitted_at')
16+
->orderByDesc('created_at')
17+
->paginate(5),
18+
]);
19+
}
20+
21+
public function threads()
22+
{
23+
return view('user.threads', [
24+
'user' => $user = Auth::user(),
25+
'threads' => $user->threads()
26+
->recent()
27+
->paginate(5),
28+
]);
29+
}
30+
31+
public function discussions()
32+
{
33+
return view('user.discussions', [
34+
'user' => $user = Auth::user(),
35+
'discussions' => $user->discussions()
36+
->orderByDesc('created_at')
37+
->paginate(5),
38+
]);
39+
}
40+
}

app/Http/Controllers/User/SettingController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function update(UpdateProfileRequest $request)
3434
'bio' => trim(strip_tags($request->bio)),
3535
'twitter_profile' => $request->twitter_profile,
3636
'github_profile' => $request->github_profile,
37+
'linkedin_profile' => $request->linkedin_profile,
3738
'phone_number' => $request->phone_number,
3839
'location' => $request->location,
3940
'website' => $request->website,

app/Http/Livewire/Articles/Create.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ public function store()
7070

7171
if ($this->submitted) {
7272
// Envoi du mail a l'admin pour la validation de l'article
73-
session()->flash('success', 'Merci d\'avoir soumis votre article. Vous aurez des nouvelles que lorsque nous accepterons votre article.');
73+
session()->flash('status', 'Merci d\'avoir soumis votre article. Vous aurez des nouvelles que lorsque nous accepterons votre article.');
7474
}
7575

7676
$user->hasRole('user') ?
77-
$this->redirect('/articles/me') :
77+
$this->redirectRoute('dashboard') :
7878
$this->redirectRoute('articles.show', $article);
7979
}
8080

app/Models/Discussion.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ public function excerpt(int $limit = 110): string
121121

122122
public function isPinned(): bool
123123
{
124-
return (bool) $this->is_pinned;
124+
return $this->is_pinned;
125125
}
126126

127127
public function isLocked(): bool
128128
{
129-
return (bool) $this->locked;
129+
return $this->locked;
130130
}
131131

132132
public function getCountAllRepliesWithChildAttribute(): int

app/Models/User.php

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Illuminate\Foundation\Auth\User as Authenticatable;
1313
use Illuminate\Notifications\Notifiable;
1414
use Illuminate\Support\Facades\Auth;
15+
use Illuminate\Support\Facades\Cache;
1516
use Spatie\MediaLibrary\HasMedia;
1617
use Spatie\MediaLibrary\InteractsWithMedia;
1718
use Spatie\Permission\Traits\HasRoles;
@@ -42,6 +43,7 @@ class User extends Authenticatable implements MustVerifyEmail, HasMedia
4243
'phone_number',
4344
'github_profile',
4445
'twitter_profile',
46+
'linkedin_profile',
4547
'website',
4648
'last_login_at',
4749
'last_login_ip',
@@ -219,6 +221,16 @@ public function twitter(): ?string
219221
return $this->twitter_profile;
220222
}
221223

224+
public function hasTwitterAccount(): bool
225+
{
226+
return ! empty($this->twitter());
227+
}
228+
229+
public function linkedin(): ?string
230+
{
231+
return $this->linkedin_profile;
232+
}
233+
222234
public function scopeModerators(Builder $query): Builder
223235
{
224236
return $query->whereHas('roles', function ($query) {
@@ -286,19 +298,34 @@ public function routeNotificationForSlack($notification): string
286298
return env('SLACK_WEBHOOK_URL', '');
287299
}
288300

289-
public function countReplies(): int
301+
public function replies(): Collection
290302
{
291-
return $this->replyAble()->count();
303+
return $this->replyAble;
292304
}
293305

294-
public function replies(): Collection
306+
public function countReplies(): int
295307
{
296-
return $this->replyAble;
308+
return Cache::remember('replies_count', now()->addHours(2), fn () => $this->replyAble()->count());
297309
}
298310

299311
public function countSolutions(): int
300312
{
301-
return $this->replyAble()->isSolution()->count();
313+
return Cache::remember('solutions_count', now()->addHours(2), fn () => $this->replyAble()->isSolution()->count());
314+
}
315+
316+
public function countArticles(): int
317+
{
318+
return Cache::remember('articles_count', now()->addHours(2), fn () => $this->articles()->approved()->count());
319+
}
320+
321+
public function countDiscussions(): int
322+
{
323+
return Cache::remember('discussions_count', now()->addHours(2), fn () => $this->discussions()->count());
324+
}
325+
326+
public function countThreads(): int
327+
{
328+
return Cache::remember('threads_count', now()->addHours(2), fn () => $this->threads()->count());
302329
}
303330

304331
public function scopeMostSolutions(Builder $query, int $inLastDays = null)
@@ -339,6 +366,7 @@ public function scopeMostSubmissionsInLastDays(Builder $query, int $days)
339366
public function scopeWithCounts(Builder $query)
340367
{
341368
return $query->withCount([
369+
'articles as articles_count',
342370
'threads as threads_count',
343371
'replyAble as replies_count',
344372
'replyAble as solutions_count' => function (Builder $query) {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class AddLinkedinProfileColumnToUsersTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('users', function (Blueprint $table) {
17+
$table->string('linkedin_profile')
18+
->after('twitter_profile')
19+
->nullable();
20+
});
21+
}
22+
23+
/**
24+
* Reverse the migrations.
25+
*
26+
* @return void
27+
*/
28+
public function down()
29+
{
30+
Schema::table('users', function (Blueprint $table) {
31+
$table->dropColumn('linkedin_profile');
32+
});
33+
}
34+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"prettier-standard": "^16.4.1"
2525
},
2626
"dependencies": {
27+
"@alpinejs/intersect": "^3.6.1",
2728
"@headlessui/react": "^1.4.2",
2829
"@heroicons/react": "^1.0.5",
2930
"@tailwindcss/aspect-ratio": "^0.2.0",

public/css/app.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/app.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/mix-manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"/js/app.js": "/js/app.js?id=6e9d959a77c0ed56a844",
3-
"/css/app.css": "/css/app.css?id=a4b94cf149d9afd5d3e5"
2+
"/js/app.js": "/js/app.js?id=7d557689434ab2f122d8",
3+
"/css/app.css": "/css/app.css?id=fe258fa62dce97e1cd59"
44
}

0 commit comments

Comments
 (0)