Merge pull request #85 from shikorism/feature/profile
プロフィール設定機能の強化 (自己紹介文, URL)
This commit is contained in:
		@@ -17,9 +17,13 @@ class SettingController extends Controller
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        $inputs = $request->all();
 | 
					        $inputs = $request->all();
 | 
				
			||||||
        $validator = Validator::make($inputs, [
 | 
					        $validator = Validator::make($inputs, [
 | 
				
			||||||
            'display_name' => 'required|string|max:20'
 | 
					            'display_name' => 'required|string|max:20',
 | 
				
			||||||
 | 
					            'bio' => 'nullable|string|max:160',
 | 
				
			||||||
 | 
					            'url' => 'nullable|url|max:2000'
 | 
				
			||||||
        ], [], [
 | 
					        ], [], [
 | 
				
			||||||
            'display_name' => '名前'
 | 
					            'display_name' => '名前',
 | 
				
			||||||
 | 
					            'bio' => '自己紹介',
 | 
				
			||||||
 | 
					            'url' => 'URL'
 | 
				
			||||||
        ]);
 | 
					        ]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ($validator->fails()) {
 | 
					        if ($validator->fails()) {
 | 
				
			||||||
@@ -28,6 +32,8 @@ class SettingController extends Controller
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        $user = Auth::user();
 | 
					        $user = Auth::user();
 | 
				
			||||||
        $user->display_name = $inputs['display_name'];
 | 
					        $user->display_name = $inputs['display_name'];
 | 
				
			||||||
 | 
					        $user->bio = $inputs['bio'] ?? '';
 | 
				
			||||||
 | 
					        $user->url = $inputs['url'] ?? '';
 | 
				
			||||||
        $user->save();
 | 
					        $user->save();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return redirect()->route('setting')->with('status', 'プロフィールを更新しました。');
 | 
					        return redirect()->route('setting')->with('status', 'プロフィールを更新しました。');
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,7 +7,7 @@ use Carbon\Carbon;
 | 
				
			|||||||
use Illuminate\Support\Facades\DB;
 | 
					use Illuminate\Support\Facades\DB;
 | 
				
			||||||
use Illuminate\View\View;
 | 
					use Illuminate\View\View;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ProfileComposer
 | 
					class ProfileStatsComposer
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public function __construct()
 | 
					    public function __construct()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@@ -2,7 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace App\Providers;
 | 
					namespace App\Providers;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use App\Http\ViewComposers\ProfileComposer;
 | 
					use App\Http\ViewComposers\ProfileStatsComposer;
 | 
				
			||||||
use Illuminate\Support\Facades\View;
 | 
					use Illuminate\Support\Facades\View;
 | 
				
			||||||
use Illuminate\Support\ServiceProvider;
 | 
					use Illuminate\Support\ServiceProvider;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -15,7 +15,7 @@ class ViewComposerServiceProvider extends ServiceProvider
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function boot()
 | 
					    public function boot()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        View::composer('components.profile', ProfileComposer::class);
 | 
					        View::composer('components.profile-stats', ProfileStatsComposer::class);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,34 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use Illuminate\Support\Facades\Schema;
 | 
				
			||||||
 | 
					use Illuminate\Database\Schema\Blueprint;
 | 
				
			||||||
 | 
					use Illuminate\Database\Migrations\Migration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class AddBioAndUrlToUsers extends Migration
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Run the migrations.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return void
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function up()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        Schema::table('users', function (Blueprint $table) {
 | 
				
			||||||
 | 
					            $table->string('bio', 160)->default('');
 | 
				
			||||||
 | 
					            $table->text('url')->default('');
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Reverse the migrations.
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @return void
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    public function down()
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        Schema::table('users', function (Blueprint $table) {
 | 
				
			||||||
 | 
					            $table->dropColumn('bio');
 | 
				
			||||||
 | 
					            $table->dropColumn('url');
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										15
									
								
								resources/views/components/profile-stats.blade.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								resources/views/components/profile-stats.blade.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
				
			|||||||
 | 
					<h6 class="font-weight-bold"><span class="oi oi-timer"></span> 現在のセッション</h6>
 | 
				
			||||||
 | 
					@if (isset($currentSession))
 | 
				
			||||||
 | 
					    <p class="card-text mb-0">{{ $currentSession }}経過</p>
 | 
				
			||||||
 | 
					    <p class="card-text">({{ $latestEjaculation->ejaculated_date->format('Y/m/d H:i') }} にリセット)</p>
 | 
				
			||||||
 | 
					@else
 | 
				
			||||||
 | 
					    <p class="card-text mb-0">計測がまだ始まっていません</p>
 | 
				
			||||||
 | 
					    <p class="card-text">(一度チェックインすると始まります)</p>
 | 
				
			||||||
 | 
					@endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<h6 class="font-weight-bold"><span class="oi oi-graph"></span> 概況</h6>
 | 
				
			||||||
 | 
					<p class="card-text mb-0">平均記録: {{ Formatter::formatInterval($summary[0]->average) }}</p>
 | 
				
			||||||
 | 
					<p class="card-text mb-0">最長記録: {{ Formatter::formatInterval($summary[0]->longest) }}</p>
 | 
				
			||||||
 | 
					<p class="card-text mb-0">最短記録: {{ Formatter::formatInterval($summary[0]->shortest) }}</p>
 | 
				
			||||||
 | 
					<p class="card-text mb-0">合計時間: {{ Formatter::formatInterval($summary[0]->total_times) }}</p>
 | 
				
			||||||
 | 
					<p class="card-text">通算回数: {{ $summary[0]->total_checkins }}回</p>
 | 
				
			||||||
@@ -1,36 +1,38 @@
 | 
				
			|||||||
<div class="card mb-4">
 | 
					<div class="card mb-4">
 | 
				
			||||||
    <div class="card-body">
 | 
					    <div class="card-body">
 | 
				
			||||||
        <div class="d-flex flex-row align-items-end">
 | 
					        <img src="{{ $user->getProfileImageUrl(128) }}" class="rounded mb-1">
 | 
				
			||||||
            <img src="{{ $user->getProfileImageUrl(64) }}" class="rounded mr-2">
 | 
					        <h4 class="card-title">
 | 
				
			||||||
            <div class="d-flex flex-column overflow-hidden">
 | 
					            <a class="text-dark" href="{{ route('user.profile', ['name' => $user->name]) }}">{{ $user->display_name }}</a>
 | 
				
			||||||
                <h4 class="card-title @if (Route::currentRouteName() === 'home') text-truncate @endif">
 | 
					        </h4>
 | 
				
			||||||
                    <a class="text-dark" href="{{ route('user.profile', ['name' => $user->name]) }}">{{ $user->display_name }}</a>
 | 
					        <h6 class="card-subtitle">
 | 
				
			||||||
                </h4>
 | 
					            <a class="text-muted" href="{{ route('user.profile', ['name' => $user->name]) }}">@{{ $user->name }}</a>
 | 
				
			||||||
                <h6 class="card-subtitle">
 | 
					            @if ($user->is_protected)
 | 
				
			||||||
                    <a class="text-muted" href="{{ route('user.profile', ['name' => $user->name]) }}">@{{ $user->name }}</a>
 | 
					                <span class="oi oi-lock-locked text-muted"></span>
 | 
				
			||||||
                    @if ($user->is_protected)
 | 
					 | 
				
			||||||
                        <span class="oi oi-lock-locked text-muted"></span>
 | 
					 | 
				
			||||||
                    @endif
 | 
					 | 
				
			||||||
                </h6>
 | 
					 | 
				
			||||||
            </div>
 | 
					 | 
				
			||||||
        </div>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        @if (!$user->is_protected || $user->isMe())
 | 
					 | 
				
			||||||
            <h6 class="font-weight-bold mt-4"><span class="oi oi-timer"></span> 現在のセッション</h6>
 | 
					 | 
				
			||||||
            @if (isset($currentSession))
 | 
					 | 
				
			||||||
                <p class="card-text mb-0">{{ $currentSession }}経過</p>
 | 
					 | 
				
			||||||
                <p class="card-text">({{ $latestEjaculation->ejaculated_date->format('Y/m/d H:i') }} にリセット)</p>
 | 
					 | 
				
			||||||
            @else
 | 
					 | 
				
			||||||
                <p class="card-text mb-0">計測がまだ始まっていません</p>
 | 
					 | 
				
			||||||
                <p class="card-text">(一度チェックインすると始まります)</p>
 | 
					 | 
				
			||||||
            @endif
 | 
					            @endif
 | 
				
			||||||
 | 
					        </h6>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            <h6 class="font-weight-bold"><span class="oi oi-graph"></span> 概況</h6>
 | 
					        {{-- Bio --}}
 | 
				
			||||||
            <p class="card-text mb-0">平均記録: {{ Formatter::formatInterval($summary[0]->average) }}</p>
 | 
					        @if (!empty($user->bio))
 | 
				
			||||||
            <p class="card-text mb-0">最長記録: {{ Formatter::formatInterval($summary[0]->longest) }}</p>
 | 
					            <p class="card-text mt-3 mb-0">
 | 
				
			||||||
            <p class="card-text mb-0">最短記録: {{ Formatter::formatInterval($summary[0]->shortest) }}</p>
 | 
					                {!! Formatter::linkify(nl2br(e($user->bio))) !!}
 | 
				
			||||||
            <p class="card-text mb-0">合計時間: {{ Formatter::formatInterval($summary[0]->total_times) }}</p>
 | 
					            </p>
 | 
				
			||||||
            <p class="card-text">通算回数: {{ $summary[0]->total_checkins }}回</p>
 | 
					        @endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        {{-- URL --}}
 | 
				
			||||||
 | 
					        @if (!empty($user->url))
 | 
				
			||||||
 | 
					            <p class="card-text d-flex mt-3">
 | 
				
			||||||
 | 
					                <span class="oi oi-link-intact mr-1 mt-1"></span>
 | 
				
			||||||
 | 
					                <a href="{{ $user->url }}" rel="me nofollow noopener" target="_blank" class="text-truncate">{{ preg_replace('~\Ahttps?://~', '', $user->url) }}</a>
 | 
				
			||||||
 | 
					            </p>
 | 
				
			||||||
        @endif
 | 
					        @endif
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@if (!$user->is_protected || $user->isMe())
 | 
				
			||||||
 | 
					    <div class="card mb-4">
 | 
				
			||||||
 | 
					        <div class="card-body">
 | 
				
			||||||
 | 
					            @component('components.profile-stats', ['user' => $user])
 | 
				
			||||||
 | 
					            @endcomponent
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					@endif
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,8 +7,26 @@
 | 
				
			|||||||
<div class="container">
 | 
					<div class="container">
 | 
				
			||||||
    <div class="row">
 | 
					    <div class="row">
 | 
				
			||||||
        <div class="col-lg-4">
 | 
					        <div class="col-lg-4">
 | 
				
			||||||
            @component('components.profile', ['user' => Auth::user()])
 | 
					            <div class="card mb-4">
 | 
				
			||||||
            @endcomponent
 | 
					                <div class="card-body">
 | 
				
			||||||
 | 
					                    <div class="d-flex flex-row align-items-end mb-4">
 | 
				
			||||||
 | 
					                        <img src="{{ Auth::user()->getProfileImageUrl(48) }}" class="rounded mr-2">
 | 
				
			||||||
 | 
					                        <div class="d-flex flex-column overflow-hidden">
 | 
				
			||||||
 | 
					                            <h5 class="card-title text-truncate">
 | 
				
			||||||
 | 
					                                <a class="text-dark" href="{{ route('user.profile', ['name' => Auth::user()->name]) }}">{{ Auth::user()->display_name }}</a>
 | 
				
			||||||
 | 
					                            </h5>
 | 
				
			||||||
 | 
					                            <h6 class="card-subtitle">
 | 
				
			||||||
 | 
					                                <a class="text-muted" href="{{ route('user.profile', ['name' => Auth::user()->name]) }}">@{{ Auth::user()->name }}</a>
 | 
				
			||||||
 | 
					                                @if (Auth::user()->is_protected)
 | 
				
			||||||
 | 
					                                    <span class="oi oi-lock-locked text-muted"></span>
 | 
				
			||||||
 | 
					                                @endif
 | 
				
			||||||
 | 
					                            </h6>
 | 
				
			||||||
 | 
					                        </div>
 | 
				
			||||||
 | 
					                    </div>
 | 
				
			||||||
 | 
					                    @component('components.profile-stats', ['user' => Auth::user()])
 | 
				
			||||||
 | 
					                    @endcomponent
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
        <div class="col-lg-8">
 | 
					        <div class="col-lg-8">
 | 
				
			||||||
            <div class="card mb-4">
 | 
					            <div class="card mb-4">
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,7 +16,7 @@
 | 
				
			|||||||
                <div class="invalid-feedback">{{ $errors->first('display_name') }}</div>
 | 
					                <div class="invalid-feedback">{{ $errors->first('display_name') }}</div>
 | 
				
			||||||
            @endif
 | 
					            @endif
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
        <div class="from-group mt-2">
 | 
					        <div class="from-group mt-3">
 | 
				
			||||||
            <label for="name">ユーザー名</label>
 | 
					            <label for="name">ユーザー名</label>
 | 
				
			||||||
            <div class="input-group">
 | 
					            <div class="input-group">
 | 
				
			||||||
                <div class="input-group-prepend">
 | 
					                <div class="input-group-prepend">
 | 
				
			||||||
@@ -26,6 +26,24 @@
 | 
				
			|||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
            <small class="form-text text-muted">現在は変更できません。</small>
 | 
					            <small class="form-text text-muted">現在は変更できません。</small>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
 | 
					        <div class="form-group mt-3">
 | 
				
			||||||
 | 
					            <label for="bio">自己紹介</label>
 | 
				
			||||||
 | 
					            <textarea id="bio" name="bio" rows="3" class="form-control {{ $errors->has('bio') ? ' is-invalid' : '' }}">{{ old('bio') ?? Auth::user()->bio }}</textarea>
 | 
				
			||||||
 | 
					            <small class="form-text text-muted">最大 160 文字</small>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            @if ($errors->has('bio'))
 | 
				
			||||||
 | 
					                <div class="invalid-feedback">{{ $errors->first('bio') }}</div>
 | 
				
			||||||
 | 
					            @endif
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					        <div class="form-group mt-3">
 | 
				
			||||||
 | 
					            <label for="url">URL</label>
 | 
				
			||||||
 | 
					            <input id="url" name="url" type="url" class="form-control {{ $errors->has('url') ? ' is-invalid' : '' }}"
 | 
				
			||||||
 | 
					                   value="{{ old('url') ?? Auth::user()->url }}" autocomplete="off">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            @if ($errors->has('url'))
 | 
				
			||||||
 | 
					                <div class="invalid-feedback">{{ $errors->first('url') }}</div>
 | 
				
			||||||
 | 
					            @endif
 | 
				
			||||||
 | 
					        </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <button type="submit" class="btn btn-primary mt-4">更新</button>
 | 
					        <button type="submit" class="btn btn-primary mt-4">更新</button>
 | 
				
			||||||
    </form>
 | 
					    </form>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user