Browse Source

Separate user profile and user agency page

pull/1/head
Nafies Luthfi 8 years ago
parent
commit
c011725189
  1. 37
      app/Http/Controllers/Auth/ProfileController.php
  2. 13
      app/Http/Controllers/Users/AgencyController.php
  3. 5
      app/Http/Controllers/Users/ProfileController.php
  4. 1
      resources/lang/id/auth.php
  5. 4
      resources/views/layouts/partials/sidebar.blade.php
  6. 19
      resources/views/users/agency/edit.blade.php
  7. 25
      resources/views/users/agency/show.blade.php
  8. 21
      resources/views/users/profile/show.blade.php
  9. 14
      routes/web/account.php
  10. 15
      tests/Feature/Users/UserProfileTest.php

37
app/Http/Controllers/Auth/ProfileController.php

@ -1,37 +0,0 @@
<?php
namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class ProfileController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function show()
{
return view('auth.profile', ['user' => auth()->user()]);
}
public function update(Request $request)
{
$profileData = $request->validate([
'name' => 'required|max:60',
'email' => 'required|email',
]);
$user = auth()->user();
$user->name = $profileData['name'];
$user->email = $profileData['email'];
$user->save();
flash(trans('auth.profile_updated'), 'success');
return back();
}
}

13
app/Http/Controllers/Users/AgencyController.php

@ -6,6 +6,17 @@ use App\Http\Controllers\Controller;
class AgencyController extends Controller class AgencyController extends Controller
{ {
public function show()
{
$agency = auth()->user()->agency;
return view('users.agency.show', compact('agency'));
}
public function edit()
{
return view('users.agency.edit');
}
public function update() public function update()
{ {
$agency = auth()->user()->agency; $agency = auth()->user()->agency;
@ -19,6 +30,6 @@ class AgencyController extends Controller
flash(trans('agency.updated'), 'success'); flash(trans('agency.updated'), 'success');
return back();
return redirect()->route('users.agency.show');
} }
} }

5
app/Http/Controllers/Users/ProfileController.php

@ -8,7 +8,8 @@ class ProfileController extends Controller
{ {
public function show() public function show()
{ {
return view('users.profile.show');
$user = auth()->user();
return view('users.profile.show', compact('user'));
} }
public function edit() public function edit()
@ -26,6 +27,6 @@ class ProfileController extends Controller
flash(trans('auth.profile_updated'), 'success'); flash(trans('auth.profile_updated'), 'success');
return back();
return redirect()->route('users.profile.show');
} }
} }

1
resources/lang/id/auth.php

@ -6,6 +6,7 @@ return [
'profile_edit' => 'Edit Profil Saya', 'profile_edit' => 'Edit Profil Saya',
'update_profile' => 'Update Profil', 'update_profile' => 'Update Profil',
'profile_updated' => 'Profil sudah diupdate.', 'profile_updated' => 'Profil sudah diupdate.',
'agency' => 'Agensi Saya',
// Registration // Registration
'register' => 'Buat Akun Baru', 'register' => 'Buat Akun Baru',

4
resources/views/layouts/partials/sidebar.blade.php

@ -14,6 +14,10 @@
</a> </a>
<ul class="nav" id="side-menu"> <ul class="nav" id="side-menu">
<li>{!! html_link_to_route('home', 'Dashboard', [], ['icon' => 'dashboard']) !!}</li> <li>{!! html_link_to_route('home', 'Dashboard', [], ['icon' => 'dashboard']) !!}</li>
<li>{!! html_link_to_route('users.profile.show', trans('auth.profile'), [], ['icon' => 'user']) !!}</li>
@can('manage', auth()->user()->agency)
<li>{!! html_link_to_route('users.agency.show', trans('auth.agency'), [], ['icon' => 'user']) !!}</li>
@endcan
@can('add_project') @can('add_project')
<li>{!! html_link_to_route('features.index', 'On Progress Features', [], ['icon' => 'tasks']) !!}</li> <li>{!! html_link_to_route('features.index', 'On Progress Features', [], ['icon' => 'tasks']) !!}</li>
<li> <li>

19
resources/views/users/agency/edit.blade.php

@ -0,0 +1,19 @@
@extends('layouts.app')
@section('content')
<h3 class="page-header">@lang('agency.edit')</h3>
<div class="row">
<div class="col-md-6">
<?php $agency = auth()->user()->agency;?>
{{ Form::model($agency, ['route' => 'users.agency.update', 'method' => 'patch']) }}
{!! FormField::text('name') !!}
{!! FormField::email('email') !!}
{!! FormField::text('website') !!}
{!! FormField::textarea('address') !!}
{!! FormField::text('phone') !!}
{{ Form::submit(trans('agency.update'), ['class' => 'btn btn-info']) }}
{{ Form::close() }}
</div>
</div>
@endsection

25
resources/views/users/agency/show.blade.php

@ -0,0 +1,25 @@
@extends('layouts.app')
@section('title', trans('agency.agency'))
@section('content')
<ul class="breadcrumb hidden-print">
<li class="active">{{ trans('agency.agency') }}</li>
</ul>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<table class="table">
<tr><th class="col-xs-4">{{ trans('agency.name') }}</th><td>{{ $agency->name }}</td></tr>
<tr><th>{{ trans('agency.email') }}</th><td>{{ $agency->email }}</td></tr>
<tr><th>{{ trans('agency.phone') }}</th><td>{{ $agency->phone }}</td></tr>
<tr><th>{{ trans('agency.address') }}</th><td>{{ $agency->address }}</td></tr>
<tr><th>{{ trans('agency.website') }}</th><td>{{ $agency->website }}</td></tr>
</table>
<div class="panel-footer">
{{ link_to_route('users.agency.edit', trans('agency.edit'), [], ['class' => 'btn btn-info']) }}
</div>
</div>
</div>
</div>
@endsection

21
resources/views/users/profile/show.blade.php

@ -1,26 +1,19 @@
@extends('layouts.app') @extends('layouts.app')
@section('title', trans('auth.profile'))
@section('content') @section('content')
<ul class="breadcrumb hidden-print"> <ul class="breadcrumb hidden-print">
<li class="active">{{ trans('auth.profile') }}</li> <li class="active">{{ trans('auth.profile') }}</li>
</ul> </ul>
<div class="row"> <div class="row">
<div class="col-md-7">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default"> <div class="panel panel-default">
<table class="table"> <table class="table">
<tr><th>{{ trans('user.user_id') }}</th><td>{{ auth()->user()->id }}</td></tr>
<tr>
<th>{{ trans('user.name') }}</th>
<td>{{ auth()->user()->name }}</td>
</tr>
<tr>
<th>{{ trans('user.email') }}</th>
<td>{{ auth()->user()->email }}</td>
</tr>
<tr>
<th>{{ trans('user.api_token') }}</th>
<td><code>{{ auth()->user()->api_token }}</code></td>
</tr>
<tr><th class="col-xs-3">{{ trans('user.user_id') }}</th><td>{{ $user->id }}</td></tr>
<tr><th>{{ trans('user.name') }}</th><td>{{ $user->name }}</td></tr>
<tr><th>{{ trans('user.email') }}</th><td>{{ $user->email }}</td></tr>
<tr><th>{{ trans('user.api_token') }}</th><td><code>{{ $user->api_token }}</code></td></tr>
</table> </table>
<div class="panel-footer"> <div class="panel-footer">
{{ link_to_route('users.profile.edit', trans('auth.profile_edit'), [], ['class' => 'btn btn-info']) }} {{ link_to_route('users.profile.edit', trans('auth.profile_edit'), [], ['class' => 'btn btn-info']) }}

14
routes/web/account.php

@ -23,7 +23,6 @@ Route::get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm
Route::post('password/reset', 'Auth\ResetPasswordController@reset')->name('reset-password'); Route::post('password/reset', 'Auth\ResetPasswordController@reset')->name('reset-password');
// User's Profile routes // User's Profile routes
Route::get('profile', [ Route::get('profile', [
'as' => 'users.profile.show', 'as' => 'users.profile.show',
'uses' => 'Users\ProfileController@show', 'uses' => 'Users\ProfileController@show',
@ -42,6 +41,19 @@ Route::patch('profile/update', [
'middleware' => ['web', 'auth'], 'middleware' => ['web', 'auth'],
]); ]);
// User's Agency routes
Route::get('agency', [
'as' => 'users.agency.show',
'uses' => 'Users\AgencyController@show',
'middleware' => ['web', 'auth'],
]);
Route::get('agency/edit', [
'as' => 'users.agency.edit',
'uses' => 'Users\AgencyController@edit',
'middleware' => ['web', 'auth'],
]);
Route::patch('agency/update', [ Route::patch('agency/update', [
'as' => 'users.agency.update', 'as' => 'users.agency.update',
'uses' => 'Users\AgencyController@update', 'uses' => 'Users\AgencyController@update',

15
tests/Feature/Users/UserProfileTest.php

@ -35,7 +35,7 @@ class UserProfileTest extends TestCase
]); ]);
$this->see(trans('auth.profile_updated')); $this->see(trans('auth.profile_updated'));
$this->seePageIs(route('users.profile.edit'));
$this->seePageIs(route('users.profile.show'));
$this->seeInDatabase('users', [ $this->seeInDatabase('users', [
'id' => $user->id, 'id' => $user->id,
@ -45,11 +45,20 @@ class UserProfileTest extends TestCase
} }
/** @test */ /** @test */
public function a_user_can_visit_their_agency_page()
{
$user = $this->userSigningIn();
$agency = factory(Agency::class)->create(['owner_id' => $user]);
$this->visit(route('users.agency.show'));
$this->seePageIs(route('users.agency.show'));
}
/** @test */
public function a_user_can_update_their_agency_data() public function a_user_can_update_their_agency_data()
{ {
$user = $this->userSigningIn(); $user = $this->userSigningIn();
$agency = factory(Agency::class)->create(['owner_id' => $user]); $agency = factory(Agency::class)->create(['owner_id' => $user]);
$this->visit(route('users.profile.edit'));
$this->visit(route('users.agency.edit'));
$this->submitForm(trans('agency.update'), [ $this->submitForm(trans('agency.update'), [
'name' => 'Nama Agensi Saya', 'name' => 'Nama Agensi Saya',
@ -60,7 +69,7 @@ class UserProfileTest extends TestCase
]); ]);
$this->see(trans('agency.updated')); $this->see(trans('agency.updated'));
$this->seePageIs(route('users.profile.edit'));
$this->seePageIs(route('users.agency.show'));
$this->seeInDatabase('agencies', [ $this->seeInDatabase('agencies', [
'id' => $agency->id, 'id' => $agency->id,

Loading…
Cancel
Save