Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-adminpanel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
laravel-adminpanel
Commits
9fed1f49
Commit
9fed1f49
authored
Dec 29, 2017
by
bvipul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Settings and Page Tests
parent
21af3cb7
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
433 additions
and
253 deletions
+433
-253
SettingsController.php
app/Http/Controllers/Backend/Settings/SettingsController.php
+1
-19
SettingsLogoController.php
...p/Controllers/Backend/Settings/SettingsLogoController.php
+41
-0
BlogsRepository.php
app/Repositories/Backend/Blogs/BlogsRepository.php
+1
-1
SettingsRepository.php
app/Repositories/Backend/Settings/SettingsRepository.php
+56
-54
labels.php
resources/lang/en/labels.php
+1
-1
edit.blade.php
resources/views/backend/settings/edit.blade.php
+249
-177
Settings.php
routes/Backend/Settings.php
+1
-1
ManageSettingsTest.php
tests/Feature/Backend/ManageSettingsTest.php
+83
-0
No files found.
app/Http/Controllers/Backend/Settings/SettingsController.php
View file @
9fed1f49
...
...
@@ -45,27 +45,9 @@ class SettingsController extends Controller
public
function
update
(
Setting
$setting
,
UpdateSettingsRequest
$request
)
{
$this
->
settings
->
update
(
$setting
,
$request
->
except
([
'_token'
,
'_method'
]));
return
redirect
()
->
route
(
'admin.settings.edit'
,
$setting
->
id
)
->
with
(
'flash_success'
,
trans
(
'alerts.backend.settings.updated'
));
}
/**
* @param Setting $setting
* @param Request $request
* Remove logo or favicon icon
*
* @return mixed
*/
public
function
removeIcon
(
Request
$request
)
{
$this
->
settings
->
removeicon
(
$request
->
data
);
return
json_encode
(
[
'status'
=>
true
,
]
);
}
}
app/Http/Controllers/Backend/Settings/SettingsLogoController.php
0 → 100644
View file @
9fed1f49
<?php
namespace
App\Http\Controllers\Backend\Settings
;
use
App\Http\Controllers\Controller
;
use
App\Models\Settings\Setting
;
use
App\Repositories\Backend\Settings\SettingsRepository
;
use
Illuminate\Http\Request
;
/**
* Class SettingsLogoController.
*/
class
SettingsLogoController
extends
Controller
{
protected
$settings
;
/**
* @param \App\Repositories\Backend\Settings\SettingsRepository $settings
*/
public
function
__construct
(
SettingsRepository
$settings
)
{
$this
->
settings
=
$settings
;
}
/**
* Remove logo or favicon icon
*
* @param \App\Models\Settings\Setting $setting
* @param \Illuminate\Http\Request $request
*
* @return mixed
*/
public
function
destroy
(
Setting
$setting
,
Request
$request
)
{
$this
->
settings
->
removeLogo
(
$setting
,
$request
->
data
);
return
json_encode
([
'status'
=>
true
]);
}
}
app/Repositories/Backend/Blogs/BlogsRepository.php
View file @
9fed1f49
...
...
@@ -132,7 +132,7 @@ class BlogsRepository extends BaseRepository
/**
* Creating Tags.
*
* @param Array
($tags)
* @param Array
$tags
*
* @return array
*/
...
...
app/Repositories/Backend/Settings/SettingsRepository.php
View file @
9fed1f49
...
...
@@ -2,9 +2,10 @@
namespace
App\Repositories\Backend\Settings
;
use
App\Exceptions\GeneralException
;
use
App\Models\Settings\Setting
;
use
App\Exceptions\GeneralException
;
use
App\Repositories\BaseRepository
;
use
Illuminate\Support\Facades\Storage
;
/**
* Class SettingsRepository.
...
...
@@ -16,29 +17,61 @@ class SettingsRepository extends BaseRepository
*/
const
MODEL
=
Setting
::
class
;
/**
* Site Logo Path
*
* @var string
*/
protected
$site_logo_path
;
/**
* Favicon path
*
* @var string
*/
protected
$favicon_path
;
/**
* Storage Class Object
*
* @var \Illuminate\Support\Facades\Storage
*/
protected
$storage
;
/**
* Constructor
*/
public
function
__construct
()
{
$this
->
site_logo_path
=
'img'
.
DIRECTORY_SEPARATOR
.
'logo'
.
DIRECTORY_SEPARATOR
;
$this
->
favicon_path
=
'img'
.
DIRECTORY_SEPARATOR
.
'favicon'
.
DIRECTORY_SEPARATOR
;
$this
->
storage
=
Storage
::
disk
(
'public'
);
}
/**
* @param \App\Models\Settings\Setting $setting
* @param $input
* @param
Array
$input
*
* @throws \App\Exceptions\GeneralException
*
* return bool
*
@
return bool
*/
public
function
update
(
Setting
$setting
,
array
$input
)
{
if
(
isset
(
$input
[
'logo'
]))
{
$image_upload
=
$this
->
uploadlogoimage
(
$setting
,
$input
[
'logo'
]);
$input
[
'logo'
]
=
$image_upload
;
if
(
!
empty
(
$input
[
'logo'
]))
{
$this
->
removeLogo
(
$setting
,
'logo'
);
$input
[
'logo'
]
=
$this
->
uploadLogo
(
$setting
,
$input
[
'logo'
],
'logo'
);
}
if
(
isset
(
$input
[
'favicon'
]))
{
$image_upload
=
$this
->
uploadfaviconimage
(
$setting
,
$input
[
'favicon'
]);
$input
[
'favicon'
]
=
$image_upload
;
if
(
!
empty
(
$input
[
'favicon'
]))
{
$this
->
removeLogo
(
$setting
,
'favicon'
);
$input
[
'favicon'
]
=
$this
->
uploadLogo
(
$setting
,
$input
[
'favicon'
],
'favicon'
);
}
if
(
$setting
->
update
(
$input
))
{
if
(
$setting
->
update
(
$input
))
return
true
;
}
throw
new
GeneralException
(
trans
(
'exceptions.backend.settings.update_error'
));
}
...
...
@@ -46,63 +79,32 @@ class SettingsRepository extends BaseRepository
/*
* Upload logo image
*/
public
function
upload
logoimage
(
$setting
,
$logo
)
public
function
upload
Logo
(
$setting
,
$logo
,
$type
)
{
$
image_name_ex
=
$logo
->
getClientOriginalExtension
()
;
$
path
=
$type
==
"logo"
?
$this
->
site_logo_path
:
$this
->
favicon_path
;
if
(
$setting
->
logo
)
{
if
(
file_exists
(
public_path
()
.
'/img/site_logo/'
.
$setting
->
logo
))
{
unlink
(
'img/site_logo/'
.
$setting
->
logo
);
}
}
$image_name
=
time
()
.
$logo
->
getClientOriginalName
();
$image_name
=
time
()
.
$logo
->
getClientOriginalName
();
$destinationPath
=
public_path
(
'img/site_logo'
);
$logo
->
move
(
$destinationPath
,
$image_name
);
$this
->
storage
->
put
(
$path
.
$image_name
,
file_get_contents
(
$logo
->
getRealPath
()));
return
$image_name
;
}
/*
*
Upload favicon icon image
*
remove logo or favicon icon
*/
public
function
uploadfaviconimage
(
$setting
,
$logo
)
public
function
removeLogo
(
Setting
$setting
,
$type
)
{
$
image_name_ex
=
$logo
->
getClientOriginalExtension
()
;
$
path
=
$type
==
"logo"
?
$this
->
site_logo_path
:
$this
->
favicon_path
;
if
(
$setting
->
favicon
)
{
if
(
file_exists
(
public_path
()
.
'/img/favicon_icon/'
.
$setting
->
favicon
))
{
unlink
(
'img/favicon_icon/'
.
$setting
->
favicon
);
}
if
(
$setting
->
$type
&&
$this
->
storage
->
exists
(
$path
.
$setting
->
$type
))
{
$this
->
storage
->
delete
(
$path
.
$setting
->
$type
);
}
$image_name
=
time
()
.
$logo
->
getClientOriginalName
();
$destinationPath
=
public_path
(
'/img/favicon_icon'
);
$logo
->
move
(
$destinationPath
,
$image_name
);
$result
=
$setting
->
update
([
$type
=>
null
]);
return
$image_name
;
}
if
(
$result
)
return
true
;
/*
* remove logo or favicon icon
*/
public
function
removeicon
(
$input
)
{
$setting
=
$this
->
query
()
->
get
();
if
(
$input
==
'logo'
)
{
if
(
$setting
[
0
]
->
logo
)
{
if
(
file_exists
(
public_path
()
.
'/img/site_logo/'
.
$setting
[
0
]
->
logo
))
{
unlink
(
'img/site_logo/'
.
$setting
[
0
]
->
logo
);
}
$this
->
query
()
->
update
([
'logo'
=>
null
]);
}
}
else
{
if
(
$setting
[
0
]
->
favicon
)
{
if
(
file_exists
(
public_path
()
.
'/img/favicon_icon/'
.
$setting
[
0
]
->
favicon
))
{
unlink
(
'img/favicon_icon/'
.
$setting
[
0
]
->
favicon
);
}
}
$this
->
query
()
->
update
([
'favicon'
=>
null
]);
}
throw
new
GeneralException
(
trans
(
'exceptions.backend.settings.update_error'
));
}
}
resources/lang/en/labels.php
View file @
9fed1f49
...
...
@@ -201,7 +201,7 @@ return [
'companydetails'
=>
'Company Contact Details'
,
'mail'
=>
'Mail Settings'
,
'footer'
=>
'Footer Settings'
,
'terms'
=>
'Terms
&
Condition Settings'
,
'terms'
=>
'Terms
and
Condition Settings'
,
'google'
=>
'Google Analytics Track Code'
,
],
...
...
resources/views/backend/settings/edit.blade.php
View file @
9fed1f49
This diff is collapsed.
Click to expand it.
routes/Backend/Settings.php
View file @
9fed1f49
...
...
@@ -6,5 +6,5 @@
Route
::
group
([
'namespace'
=>
'Settings'
],
function
()
{
Route
::
resource
(
'settings'
,
'SettingsController'
,
[
'except'
=>
[
'show'
,
'create'
,
'save'
,
'index'
,
'destroy'
]]);
Route
::
post
(
'removeicon
'
,
'SettingsController@removeIcon'
)
->
name
(
'removei
con'
);
Route
::
post
(
'removeicon
/{setting}'
,
'SettingsLogoController@destroy'
)
->
name
(
'removeI
con'
);
});
tests/Feature/Backend/ManageSettingsTest.php
0 → 100644
View file @
9fed1f49
<?php
namespace
Tests\Feature\Backend
;
use
Tests\TestCase
;
use
App\Models\Settings\Setting
;
use
Illuminate\Http\UploadedFile
;
use
Illuminate\Support\Facades\Storage
;
use
Illuminate\Foundation\Testing\WithFaker
;
use
Illuminate\Foundation\Testing\RefreshDatabase
;
class
ManageSettingsTest
extends
TestCase
{
protected
$setting
;
public
function
setUp
()
{
parent
::
setUp
();
$this
->
setting
=
Setting
::
find
(
1
);
$this
->
actingAs
(
$this
->
admin
);
}
/** @test */
public
function
setting_page_shows_different_tabs
()
{
$this
->
get
(
route
(
'admin.settings.edit'
,
$this
->
setting
))
->
assertSee
(
__
(
'labels.backend.settings.seo'
))
->
assertSee
(
__
(
'labels.backend.settings.companydetails'
))
->
assertSee
(
__
(
'labels.backend.settings.mail'
))
->
assertSee
(
__
(
'labels.backend.settings.footer'
))
->
assertSee
(
__
(
'labels.backend.settings.terms'
))
->
assertSee
(
__
(
'labels.backend.settings.google'
));
}
/** @test */
public
function
it_can_update_a_valid_site_logo
()
{
$this
->
patch
(
route
(
'admin.settings.update'
,
$this
->
setting
),
[
'logo'
=>
UploadedFile
::
fake
()
->
image
(
'logo.jpg'
,
226
,
48
)
]);
Storage
::
disk
(
'public'
)
->
assertExists
(
'img/logo/'
.
$this
->
setting
->
logo
);
}
/** @test */
public
function
it_throws_error_for_valid_site_logo
()
{
$this
->
withExceptionHandling
();
$this
->
patch
(
route
(
'admin.settings.update'
,
$this
->
setting
),
[
'logo'
=>
UploadedFile
::
fake
()
->
image
(
'logo.jpg'
,
200
,
500
)
])
->
assertSessionHasErrors
(
'logo'
);
}
/** @test */
public
function
it_can_update_site_favicon
()
{
$this
->
patch
(
route
(
'admin.settings.update'
,
$this
->
setting
),
[
'favicon'
=>
UploadedFile
::
fake
()
->
image
(
'favicon.jpg'
,
16
,
16
)
]);
Storage
::
disk
(
'public'
)
->
assertExists
(
'img/favicon/'
.
$this
->
setting
->
favicon
);
}
/** @test */
public
function
it_throws_error_for_valid_site_favicon
()
{
$this
->
withExceptionHandling
();
$this
->
patch
(
route
(
'admin.settings.update'
,
$this
->
setting
),
[
'favicon'
=>
UploadedFile
::
fake
()
->
image
(
'favicon.jpg'
,
200
,
500
)
])
->
assertSessionHasErrors
(
'favicon'
);
}
/** @test */
public
function
a_user_can_update_settings
()
{
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment