Browse Source

Add agency logo upload

Add appLogoImageHelper
Add new validation rule file_extension:ext1,ext2,...
Add default logo image
Restructure agency edit and detail page
pull/1/head
Nafies Luthfi 8 years ago
parent
commit
0edff8d5a3
  1. 18
      app/Http/Controllers/Users/AgencyController.php
  2. 3
      app/Providers/AppServiceProvider.php
  3. 7
      app/helpers.php
  4. BIN
      public/assets/imgs/default-logo.png
  5. 3
      resources/lang/id/agency.php
  6. 1
      resources/lang/id/contact.php
  7. 2
      resources/views/layouts/partials/sidebar.blade.php
  8. 26
      resources/views/users/agency/edit.blade.php
  9. 27
      resources/views/users/agency/show.blade.php
  10. 6
      routes/web/account.php
  11. 2
      tests/Feature/Auth/ChangePasswordTest.php
  12. 2
      tests/Feature/Auth/LoginTest.php
  13. 2
      tests/Feature/Auth/RegistrationTest.php
  14. 20
      tests/Feature/Users/UserProfileTest.php

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

@ -33,4 +33,22 @@ class AgencyController extends Controller
return redirect()->route('users.agency.show');
}
public function logoUpload()
{
$file = request()->validate([
'logo' => 'required|max:100|file_extension:png,jpg',
]);
\File::delete(public_path('assets/imgs/'.Option::get('agency_logo_path')));
$filename = $file['logo']->getClientOriginalName();
$file['logo']->move(public_path('assets/imgs'), $filename);
Option::set('agency_logo_path', $filename);
flash(trans('agency.updated'), 'success');
return redirect()->route('users.agency.show');
}
}

3
app/Providers/AppServiceProvider.php

@ -14,6 +14,9 @@ class AppServiceProvider extends ServiceProvider
public function boot()
{
require_once app_path().'/helpers.php';
\Validator::extend('file_extension', function ($attribute, $value, $parameters, $validator) {
return in_array($value->getClientOriginalExtension(), $parameters);
});
}
/**

7
app/helpers.php

@ -234,3 +234,10 @@ function paymentTypes($paymentTypeId = null)
return null;
}
function appLogoImage()
{
$logoString = '<img style="display: block;text-align: center;margin: 0 auto;width: 100%;max-width: 200px"';
$logoString .= 'src="'.asset('assets/imgs/'.Option::get('agency_logo_path', 'default-logo.png')).'">';
return $logoString;
}

BIN
public/assets/imgs/default-logo.png

After

Width: 400  |  Height: 400  |  Size: 58 KiB

3
resources/lang/id/agency.php

@ -10,6 +10,8 @@ return [
'edit' => 'Edit Agensi',
'update' => 'Update Agensi',
'updated' => 'Update data Agensi telah berhasil.',
'logo_change' => 'Ganti Logo Agensi',
'logo_upload' => 'Upload Logo Agensi',
// Attributes
'name' => 'Nama Agensi',
@ -18,4 +20,5 @@ return [
'website' => 'Website Agensi',
'address' => 'Alamat Agensi',
'phone' => 'Telp. Agensi',
'logo' => 'Logo Agensi',
];

1
resources/lang/id/contact.php

@ -6,4 +6,5 @@ return [
'phone_abb' => 'Telp.',
'cellphone' => 'Telepon Selular',
'email' => 'Email',
'website' => 'Website',
];

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

@ -10,7 +10,7 @@
<div class="navbar-default sidebar hidden-print" role="navigation">
<div class="sidebar-nav navbar-collapse">
<a class="navbar-brand text-center" title="Home | {{ Option::get('agency_tagline', 'Laravel app description') }}" href="{{ route('home') }}">
{!! Html::image(url('assets/imgs/logo.png'), 'Logo '.Option::get('agency_name','Laravel'), ['class' => 'sidebar-logo']) !!}
{!! Html::image(asset('assets/imgs/'.Option::get('agency_logo_path', 'default-logo.png')), 'Logo '.Option::get('agency_name','Laravel'), ['class' => 'sidebar-logo']) !!}
<div class="small" style="margin-top:10px">{{ Option::get('app_name','Laravel') }}</div>
</a>
<ul class="nav" id="side-menu">

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

@ -4,16 +4,32 @@
@section('content-dashboard')
<div class="row">
<div class="col-md-6 col-lg-offset-2">
{{ Form::open(['route' => 'users.agency.update', 'method' => 'patch']) }}
<div class="col-md-4">
<legend>{{ trans('agency.detail') }}</legend>
{!! FormField::text('name', ['value' => Option::get('agency_name')]) !!}
{!! FormField::text('tagline', ['value' => Option::get('agency_tagline')]) !!}
{!! FormField::email('email', ['value' => Option::get('agency_email')]) !!}
{!! FormField::text('website', ['value' => Option::get('agency_phone')]) !!}
{!! FormField::textarea('address', ['value' => Option::get('agency_address')]) !!}
{!! FormField::text('phone', ['value' => Option::get('agency_website')]) !!}
{{ Form::submit(trans('agency.update'), ['class' => 'btn btn-info']) }}
{{ link_to_route('users.agency.show', trans('app.cancel'), [], ['class' => 'btn btn-default']) }}
<br>
<br>
</div>
<div class="col-md-5">
<legend>{{ trans('contact.contact') }}</legend>
<div class="row">
<div class="col-md-6">{!! FormField::email('email', ['value' => Option::get('agency_email')]) !!}</div>
<div class="col-md-6">{!! FormField::text('phone', ['value' => Option::get('agency_phone')]) !!}</div>
</div>
{!! FormField::textarea('address', ['value' => Option::get('agency_address')]) !!}
{!! FormField::text('website', ['value' => Option::get('agency_website')]) !!}
</div>
{{ Form::close() }}
<div class="col-md-3">
{{ Form::open(['route' => 'users.agency.logo-upload', 'method' => 'patch', 'files' => true]) }}
<legend>{{ trans('agency.logo') }}</legend>
<p>{!! appLogoImage() !!}</p>
{!! FormField::file('logo', ['label' => trans('agency.logo_change')]) !!}
{{ Form::submit(trans('agency.logo_upload'), ['class' => 'btn btn-default']) }}
{{ Form::close() }}
</div>
</div>

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

@ -4,19 +4,28 @@
@section('content-dashboard')
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="col-md-4 text-center">
<p>{!! appLogoImage() !!}</p>
<h3 class="text-primary">{{ Option::get('agency_name') }}</h3>
<p>{{ Option::get('agency_tagline') }}</p>
<br>
{{ link_to_route('users.agency.edit', trans('agency.edit'), [], ['class' => 'btn btn-info']) }}
</div>
<div class="col-md-8">
<legend style="border-bottom: none;margin-bottom: 10px; margin-left: 6px;">
{{ trans('agency.detail') }}
</legend>
<div class="panel panel-default">
<table class="table">
<tr><th class="col-xs-4">{{ trans('agency.name') }}</th><td>{{ Option::get('agency_name') }}</td></tr>
<tr><th>{{ trans('agency.name') }}</th><td>{{ Option::get('agency_name') }}</td></tr>
<tr><th>{{ trans('agency.tagline') }}</th><td>{{ Option::get('agency_tagline') }}</td></tr>
<tr><th>{{ trans('agency.email') }}</th><td>{{ Option::get('agency_email') }}</td></tr>
<tr><th>{{ trans('agency.phone') }}</th><td>{{ Option::get('agency_phone') }}</td></tr>
<tr><th>{{ trans('agency.address') }}</th><td>{!! nl2br(Option::get('agency_address')) !!}</td></tr>
<tr><th>{{ trans('agency.website') }}</th><td>{{ Option::get('agency_website') }}</td></tr>
<tr><th>{{ trans('contact.email') }}</th><td>{{ Option::get('agency_email') }}</td></tr>
<tr><th>{{ trans('contact.phone') }}</th><td>{{ Option::get('agency_phone') }}</td></tr>
<tr><th>{{ trans('address.address') }}</th><td>{!! nl2br(Option::get('agency_address')) !!}</td></tr>
<tr><th>{{ trans('contact.website') }}</th><td>{{ Option::get('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>

6
routes/web/account.php

@ -59,3 +59,9 @@ Route::patch('agency/update', [
'uses' => 'Users\AgencyController@update',
'middleware' => ['web', 'auth'],
]);
Route::patch('agency/logo-upload', [
'as' => 'users.agency.logo-upload',
'uses' => 'Users\AgencyController@logoUpload',
'middleware' => ['web', 'auth'],
]);

2
tests/Feature/Auth/MemberChangePasswordTest.php → tests/Feature/Auth/ChangePasswordTest.php

@ -4,7 +4,7 @@ namespace Tests\Feature\Auth;
use Tests\TestCase;
class MemberChangePasswordTest extends TestCase
class ChangePasswordTest extends TestCase
{
/** @test */
public function member_can_change_password()

2
tests/Feature/Auth/MemberLoginTest.php → tests/Feature/Auth/LoginTest.php

@ -5,7 +5,7 @@ namespace Tests\Feature\Auth;
use App\Entities\Users\User;
use Tests\TestCase;
class MemberLoginTest extends TestCase
class LoginTest extends TestCase
{
/** @test */
public function user_can_login_and_logout()

2
tests/Feature/Auth/MemberRegistrationTest.php → tests/Feature/Auth/RegistrationTest.php

@ -5,7 +5,7 @@ namespace Tests\Feature\Auth;
use App\Entities\Users\User;
use Tests\TestCase;
class MemberRegistrationTest extends TestCase
class RegistrationTest extends TestCase
{
/** @test */
public function registration_validation()

20
tests/Feature/Users/UserProfileTest.php

@ -93,4 +93,24 @@ class UserProfileTest extends TestCase
'value' => 'Tagline agensi saya',
]);
}
/** @test */
public function admin_user_can_update_agency_logo_image()
{
$user = $this->adminUserSigningIn();
$this->visit(route('users.agency.edit'));
$this->attach(storage_path('app/guitar-640.jpg'), 'logo');
$this->press(trans('agency.logo_upload'));
$this->see(trans('agency.updated'));
$this->seePageIs(route('users.agency.show'));
$this->seeInDatabase('site_options', [
'key' => 'agency_logo_path',
'value' => 'guitar-640.jpg',
]);
$this->assertFileExistsThenDelete(public_path('assets/imgs/guitar-640.jpg'));
}
}
Loading…
Cancel
Save