54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Modules\Admin\Repositories;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Modules\Admin\Models\Setting;
|
|
|
|
class SettingRepository implements SettingInterface
|
|
{
|
|
public function findAll()
|
|
{
|
|
return Setting::get()->mapWithKeys(function ($setting) {
|
|
return [$setting->key => $setting->value];
|
|
});
|
|
}
|
|
|
|
public function getSettingById($SettingId)
|
|
{
|
|
return Setting::findOrFail($SettingId);
|
|
}
|
|
|
|
public function getList()
|
|
{
|
|
return Setting::pluck('title', 'id');
|
|
}
|
|
|
|
public function delete($SettingId)
|
|
{
|
|
Setting::destroy($SettingId);
|
|
}
|
|
public function create(array $settingDetails, Request $request)
|
|
{
|
|
$thumbName = time() . '.' . $request->file('thumb')->extension();
|
|
$logoName = uniqid() . '.' . $request->file('logo')->extension();
|
|
|
|
$request->thumb->move(public_path('images/setting'), $thumbName);
|
|
$request->logo->move(public_path('images/setting'), $logoName);
|
|
|
|
$path = 'images/setting/';
|
|
$settingDetails['logo'] = $path . $logoName;
|
|
$settingDetails['thumb'] = $path . $thumbName;
|
|
|
|
// dd($settingDetails);
|
|
return Setting::create($settingDetails);
|
|
}
|
|
|
|
public function update($SettingId, $newDetails)
|
|
{
|
|
$setting = Setting::where('id', $SettingId);
|
|
|
|
$setting->update($newDetails);
|
|
}
|
|
}
|