13 changed files with 255 additions and 17 deletions
-
5app/Entities/Agencies/Agency.php
-
5app/Entities/Users/User.php
-
24app/Http/Controllers/Users/AgencyController.php
-
31app/Http/Controllers/Users/ProfileController.php
-
15database/factories/AgencyFactory.php
-
26resources/views/users/profile/edit.blade.php
-
38routes/web/account.php
-
6routes/web/pages.php
-
2tests/Feature/Users/ManageUsersTest.php
-
74tests/Feature/Users/UserProfileTest.php
-
8tests/TestCase.php
-
17tests/Unit/Models/AgencyTest.php
-
21tests/Unit/Models/UserTest.php
@ -0,0 +1,24 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Http\Controllers\Users; |
||||
|
|
||||
|
use App\Http\Controllers\Controller; |
||||
|
|
||||
|
class AgencyController extends Controller |
||||
|
{ |
||||
|
public function update() |
||||
|
{ |
||||
|
$agency = auth()->user()->agency; |
||||
|
|
||||
|
$agency->name = request('name'); |
||||
|
$agency->email = request('email'); |
||||
|
$agency->website = request('website'); |
||||
|
$agency->address = request('address'); |
||||
|
$agency->phone = request('phone'); |
||||
|
$agency->save(); |
||||
|
|
||||
|
flash(trans('agency.updated'), 'success'); |
||||
|
|
||||
|
return back(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,31 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Http\Controllers\Users; |
||||
|
|
||||
|
use App\Http\Controllers\Controller; |
||||
|
|
||||
|
class ProfileController extends Controller |
||||
|
{ |
||||
|
public function show() |
||||
|
{ |
||||
|
return auth()->user(); |
||||
|
} |
||||
|
|
||||
|
public function edit() |
||||
|
{ |
||||
|
return view('users.profile.edit'); |
||||
|
} |
||||
|
|
||||
|
public function update() |
||||
|
{ |
||||
|
$user = auth()->user(); |
||||
|
|
||||
|
$user->name = request('name'); |
||||
|
$user->email = request('email'); |
||||
|
$user->save(); |
||||
|
|
||||
|
flash(trans('auth.profile_updated'), 'success'); |
||||
|
|
||||
|
return back(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
<?php |
||||
|
|
||||
|
use App\Entities\Agencies\Agency; |
||||
|
use App\Entities\Users\User; |
||||
|
use Faker\Generator as Faker; |
||||
|
|
||||
|
$factory->define(Agency::class, function (Faker $faker) { |
||||
|
return [ |
||||
|
'name' => $faker->company, |
||||
|
'email' => $faker->safeEmail, |
||||
|
'owner_id' => function () { |
||||
|
return factory(User::class)->create()->id; |
||||
|
}, |
||||
|
]; |
||||
|
}); |
||||
@ -0,0 +1,26 @@ |
|||||
|
@extends('layouts.app') |
||||
|
|
||||
|
@section('content') |
||||
|
<h3 class="page-header">@lang('auth.profile_edit')</h3> |
||||
|
<div class="row"> |
||||
|
<div class="col-md-6"> |
||||
|
{{ Form::model(auth()->user(), ['route' => 'users.profile.update', 'method' => 'patch']) }} |
||||
|
{!! FormField::text('name') !!} |
||||
|
{!! FormField::email('email') !!} |
||||
|
{{ Form::submit(trans('auth.update_profile'), ['class' => 'btn btn-info']) }} |
||||
|
{{ Form::close() }} |
||||
|
</div> |
||||
|
<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 |
||||
@ -1,6 +1,6 @@ |
|||||
<?php |
<?php |
||||
|
|
||||
namespace Tests\Feature; |
|
||||
|
namespace Tests\Feature\Users; |
||||
|
|
||||
use App\Entities\Users\User; |
use App\Entities\Users\User; |
||||
use Tests\TestCase; |
use Tests\TestCase; |
||||
@ -0,0 +1,74 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Tests\Feature\Users; |
||||
|
|
||||
|
use App\Entities\Agencies\Agency; |
||||
|
use Tests\TestCase; |
||||
|
|
||||
|
class UserProfileTest extends TestCase |
||||
|
{ |
||||
|
/** @test */ |
||||
|
public function a_user_can_visit_their_profile_page() |
||||
|
{ |
||||
|
$user = $this->userSigningIn(); |
||||
|
$this->visit(route('users.profile.show')); |
||||
|
$this->seePageIs(route('users.profile.show')); |
||||
|
} |
||||
|
|
||||
|
/** @test */ |
||||
|
public function a_user_can_visit_their_profile_edit_page() |
||||
|
{ |
||||
|
$user = $this->userSigningIn(); |
||||
|
$this->visit(route('users.profile.edit')); |
||||
|
$this->seePageIs(route('users.profile.edit')); |
||||
|
} |
||||
|
|
||||
|
/** @test */ |
||||
|
public function a_user_can_update_their_profile() |
||||
|
{ |
||||
|
$user = $this->userSigningIn(); |
||||
|
$this->visit(route('users.profile.edit')); |
||||
|
|
||||
|
$this->submitForm(trans('auth.update_profile'), [ |
||||
|
'name' => 'Nama Saya', |
||||
|
'email' => 'me@domain.com', |
||||
|
]); |
||||
|
|
||||
|
$this->see(trans('auth.profile_updated')); |
||||
|
$this->seePageIs(route('users.profile.edit')); |
||||
|
|
||||
|
$this->seeInDatabase('users', [ |
||||
|
'id' => $user->id, |
||||
|
'name' => 'Nama Saya', |
||||
|
'email' => 'me@domain.com', |
||||
|
]); |
||||
|
} |
||||
|
|
||||
|
/** @test */ |
||||
|
public function a_user_can_update_their_agency_data() |
||||
|
{ |
||||
|
$user = $this->userSigningIn(); |
||||
|
$agency = factory(Agency::class)->create(['owner_id' => $user]); |
||||
|
$this->visit(route('users.profile.edit')); |
||||
|
|
||||
|
$this->submitForm(trans('agency.update'), [ |
||||
|
'name' => 'Nama Agensi Saya', |
||||
|
'email' => 'nama_agensi@domain.com', |
||||
|
'address' => 'Jln. Kalimantan, No. 20, Kota', |
||||
|
'phone' => '081234567890', |
||||
|
'website' => 'https://example.com', |
||||
|
]); |
||||
|
|
||||
|
$this->see(trans('agency.updated')); |
||||
|
$this->seePageIs(route('users.profile.edit')); |
||||
|
|
||||
|
$this->seeInDatabase('agencies', [ |
||||
|
'id' => $agency->id, |
||||
|
'name' => 'Nama Agensi Saya', |
||||
|
'email' => 'nama_agensi@domain.com', |
||||
|
'address' => 'Jln. Kalimantan, No. 20, Kota', |
||||
|
'phone' => '081234567890', |
||||
|
'website' => 'https://example.com', |
||||
|
]); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,17 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Tests\Unit\Models; |
||||
|
|
||||
|
use App\Entities\Agencies\Agency; |
||||
|
use App\Entities\Users\User; |
||||
|
use Tests\TestCase; |
||||
|
|
||||
|
class AgencyTest extends TestCase |
||||
|
{ |
||||
|
/** @test */ |
||||
|
public function agency_has_an_owner() |
||||
|
{ |
||||
|
$agency = factory(Agency::class)->create(); |
||||
|
$this->assertTrue($agency->owner instanceof User); |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue