Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Platform
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
Platform
Commits
4477b3ac
Commit
4477b3ac
authored
Oct 18, 2014
by
Nicolas Widart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Creating settings options
parent
15d0754e
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
114 additions
and
1 deletion
+114
-1
Setting.php
Entities/Setting.php
+5
-0
SettingTranslation.php
Entities/SettingTranslation.php
+9
-0
SettingController.php
Http/Controllers/Admin/SettingController.php
+7
-1
SettingRequest.php
Http/Requests/SettingRequest.php
+21
-0
EloquentSettingRepository.php
Repositories/Eloquent/EloquentSettingRepository.php
+59
-0
SettingRepository.php
Repositories/SettingRepository.php
+13
-0
No files found.
Entities/Setting.php
View file @
4477b3ac
<?php
namespace
Modules\Setting\Entities
;
use
Dimsav\Translatable\Translatable
;
use
Illuminate\Database\Eloquent\Model
;
class
Setting
extends
Model
{
use
Translatable
;
public
$translatedAttributes
=
[
'value'
,
'description'
];
protected
$fillable
=
[
'name'
,
'value'
,
'description'
];
}
Entities/SettingTranslation.php
0 → 100644
View file @
4477b3ac
<?php
namespace
Modules\Setting\Entities
;
use
Illuminate\Database\Eloquent\Model
;
class
SettingTranslation
extends
Model
{
public
$timestamps
=
false
;
protected
$fillable
=
[
'value'
,
'description'
];
}
Http/Controllers/Admin/SettingController.php
View file @
4477b3ac
<?php
namespace
Modules\Setting\Http\Controllers\Admin
;
use
Illuminate\Support\Facades\Redirect
;
use
Illuminate\Support\Facades\View
;
use
Laracasts\Flash\Flash
;
use
Modules\Core\Http\Controllers\Admin\AdminBaseController
;
use
Modules\Setting\Http\Requests\SettingRequest
;
use
Modules\Setting\Repositories\SettingRepository
;
class
SettingController
extends
AdminBaseController
...
...
@@ -23,8 +26,11 @@ class SettingController extends AdminBaseController
return
View
::
make
(
'setting::admin.settings'
);
}
public
function
store
()
public
function
store
(
SettingRequest
$request
)
{
$this
->
setting
->
createOrUpdate
(
$request
->
all
());
Flash
::
success
(
'Settings saved!'
);
return
Redirect
::
route
(
'dashboard.setting.index'
);
}
}
Http/Requests/SettingRequest.php
0 → 100644
View file @
4477b3ac
<?php
namespace
Modules\Setting\Http\Requests
;
use
Illuminate\Foundation\Http\FormRequest
;
class
SettingRequest
extends
FormRequest
{
public
function
rules
()
{
return
[];
}
public
function
authorize
()
{
return
true
;
}
public
function
messages
()
{
return
[];
}
}
Repositories/Eloquent/EloquentSettingRepository.php
View file @
4477b3ac
...
...
@@ -16,8 +16,67 @@ class EloquentSettingRepository extends EloquentBaseRepository implements Settin
{
}
/**
* @param mixed $data
* @return mixed
*/
public
function
create
(
$data
)
{
}
/**
* Create or update the settings
* @param $settings
* @return mixed|void
*/
public
function
createOrUpdate
(
$settings
)
{
$this
->
removeTokenKey
(
$settings
);
foreach
(
$settings
as
$settingName
=>
$settingValues
)
{
// Check if setting exists
if
(
$setting
=
$this
->
findByName
(
$settingName
))
{
}
$this
->
createForName
(
$settingName
,
$settingValues
);
}
}
/**
* Remove the token from the input array
* @param $settings
*/
private
function
removeTokenKey
(
&
$settings
)
{
unset
(
$settings
[
'_token'
]);
}
/**
* Find a setting by its name
* @param $settingName
* @return mixed
*/
public
function
findByName
(
$settingName
)
{
return
$this
->
model
->
whereHas
(
'translations'
,
function
(
$q
)
use
(
$settingName
)
{
$q
->
where
(
'name'
,
$settingName
);
})
->
first
();
}
/**
* Create a setting with the given name
* @param $settingName
* @param $settingValues
*/
private
function
createForName
(
$settingName
,
$settingValues
)
{
$setting
=
new
$this
->
model
;
$setting
->
name
=
$settingName
;
foreach
(
$settingValues
as
$lang
=>
$value
)
{
$setting
->
translate
(
$lang
)
->
value
=
$value
;
}
$setting
->
save
();
}
}
Repositories/SettingRepository.php
View file @
4477b3ac
...
...
@@ -4,4 +4,17 @@ use Modules\Core\Repositories\BaseRepository;
interface
SettingRepository
extends
BaseRepository
{
/**
* Create or update the settings
* @param $settings
* @return mixed
*/
public
function
createOrUpdate
(
$settings
);
/**
* Find a setting by its name
* @param $settingName
* @return mixed
*/
public
function
findByName
(
$settingName
);
}
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