Skip to content

Instantly share code, notes, and snippets.

@iolson
Created July 31, 2015 15:14
Show Gist options
  • Save iolson/ca78ce08dff886b55560 to your computer and use it in GitHub Desktop.
Save iolson/ca78ce08dff886b55560 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Controllers\Dashboard;
use App\Repositories\Setting\SettingRepositoryInterface as Setting;
use Illuminate\Database\QueryException;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\View\View;
use Laracasts\Flash\Flash;
use Laraflock\Dashboard\Controllers\BaseDashboardController;
use Laraflock\Dashboard\Exceptions\FormValidationException;
use Laraflock\Dashboard\Repositories\Auth\AuthRepositoryInterface as Auth;
use Laraflock\Dashboard\Repositories\Permission\PermissionRepositoryInterface as Permission;
use Laraflock\Dashboard\Repositories\Role\RoleRepositoryInterface as Role;
use Laraflock\Dashboard\Repositories\User\UserRepositoryInterface as User;
class SettingController extends BaseDashboardController
{
/**
* Setting interface.
*
* @var \App\Repositories\Setting\SettingRepositoryInterface
*/
protected $setting;
/**
* The constructor.
*
* @param \Laraflock\Dashboard\Repositories\Auth\AuthRepositoryInterface $auth
* @param \Laraflock\Dashboard\Repositories\Permission\PermissionRepositoryInterface $permission
* @param \Laraflock\Dashboard\Repositories\Role\RoleRepositoryInterface $role
* @param \Laraflock\Dashboard\Repositories\User\UserRepositoryInterface $user
* @param \App\Repositories\Setting\SettingRepositoryInterface $setting
*/
public function __construct(Auth $auth, Permission $permission, Role $role, User $user, Setting $setting)
{
$this->setting = $setting;
parent::__construct($auth, $permission, $role, $user);
}
public function index()
{
return view('settings.index');
}
public function inviteCodes()
{
$settings = $this->setting->getAllByPrefix('invite_code_')->lists('value', 'name')->toArray();
if (empty($settings)) {
$settings = [];
}
if (!isset($settings['invite_code_percentage'])) {
$settings['invite_code_percentage'] = null;
}
if (!isset($settings['invite_code_email'])) {
$settings['invite_code_email'] = null;
}
return view('settings.invite-codes')->with(['settings' => $settings]);
}
public function storeInviteCodes(Request $request)
{
$rules = [
'invite_code_percentage' => 'required|integer',
'invite_code_email' => 'required|email',
];
try {
$this->setting->update($request->all(), $rules, 'invite_code_');
} catch (FormValidationException $e) {
Flash::error($e->getMessage());
return redirect()
->route('settings.inviteCode')
->withErrors($e->getErrors())
->withInput();
} catch (QueryException $e) {
Flash::error($e->getMessage());
return redirect()
->route('settings.inviteCode')
->withInput();
}
Flash::success('Settings successfully updated.');
return redirect()->route('settings.inviteCode');
}
public function users()
{
$settings = $this->setting->getAllByPrefix('users_')->lists('value', 'name')->toArray();
if (empty($settings)) {
$settings = [];
}
if (!isset($settings['users_success_message'])) {
$settings['users_success_message'] = null;
}
return view('settings.users')->with(['settings' => $settings]);
}
public function storeUsers(Request $request)
{
$rules = [];
try {
$this->setting->update($request->all(), $rules, 'users_');
} catch (FormValidationException $e) {
Flash::error($e->getMessage());
return redirect()
->route('settings.users')
->withErrors($e->getErrors())
->withInput();
} catch (QueryException $e) {
Flash::error($e->getMessage());
return redirect()
->route('settings.users')
->withInput();
}
Flash::success('Settings successfully updated.');
return redirect()->route('settings.users');
}
public function contact()
{
}
public function storeContact(Request $request)
{
}
public function newsletter()
{
$settings = $this->setting->getAllByPrefix('mailchimp_')->lists('value', 'name')->toArray();
if (empty($settings)) {
$settings = [];
}
if (!isset($settings['mailchimp_api_key'])) {
$settings['mailchimp_api_key'] = null;
}
if (!isset($settings['mailchimp_list_id'])) {
$settings['mailchimp_list_id'] = null;
}
if (!isset($settings['mailchimp_success_message'])) {
$settings['mailchimp_success_message'] = null;
}
return view('settings.newsletter')->with(['settings' => $settings]);
}
public function storeNewsletter(Request $request)
{
$rules = [
'mailchimp_api_key' => 'required',
'mailchimp_list_id' => 'required',
'mailchimp_success_message' => 'required',
];
try {
$this->setting->update($request->all(), $rules, 'mailchimp_');
} catch (FormValidationException $e) {
Flash::error($e->getMessage());
return redirect()
->route('settings.newsletter')
->withErrors($e->getErrors())
->withInput();
} catch (QueryException $e) {
Flash::error($e->getMessage());
return redirect()
->route('settings.newsletter')
->withInput();
}
Flash::success('Settings successfully updated.');
return redirect()->route('settings.newsletter');
}
public function socialMedia()
{
}
public function storeSocialMedia(Request $request)
{
}
public function homepage()
{
}
public function storeHomepage(Request $request)
{
}
public function books()
{
}
public function storeBooks(Request $request)
{
}
public function account()
{
}
public function storeAccount(Request $request)
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment