-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nguyen Tan Dung
committed
Dec 10, 2023
1 parent
1d33130
commit c42480e
Showing
31 changed files
with
733 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,51 @@ | ||
<?php | ||
|
||
use App\Http\Services\Admin\SettingService; | ||
|
||
if (!function_exists('option')) { | ||
function option($name, $default = '') | ||
{ | ||
$settingService = new SettingService(); | ||
$value = $settingService->getValueByKey($name); | ||
|
||
if ($value == null) { | ||
return $default; | ||
} | ||
|
||
return $value; | ||
} | ||
|
||
if (!function_exists('getNameRouteMain')) { | ||
function getNameRouteMain(): string | ||
{ | ||
$arrRouteName = explode('.', request()->route()->getName()); | ||
|
||
$result = $arrRouteName[0]; | ||
if($arrRouteName[0] == 'admin') { | ||
$result = $arrRouteName[1]; | ||
} | ||
|
||
return $result == "index" ? "" : $result; | ||
} | ||
} | ||
|
||
if (!function_exists('getSubtitle')) { | ||
function getSubtitle(): string | ||
{ | ||
$result = getNameRouteMain(); | ||
|
||
return $result == "" ? "" : ' - '. ucfirst($result); | ||
} | ||
} | ||
|
||
if (!function_exists('getImageFromStorage')) { | ||
function getImageFromStorage($value, $url): string | ||
{ | ||
if ($value == '' || $value == null) { | ||
return asset($url); | ||
} | ||
|
||
return Storage::url($value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\SettingRequest; | ||
use App\Http\Services\Admin\SettingService; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Illuminate\View\View; | ||
|
||
class SettingController extends Controller | ||
{ | ||
protected SettingService $settingService; | ||
|
||
public function __construct() | ||
{ | ||
$this->settingService = new SettingService(); | ||
} | ||
/** | ||
* Display a listing of the resource. | ||
*/ | ||
public function index(): View | ||
{ | ||
return view("admin.setting"); | ||
} | ||
|
||
/** | ||
* Save the form for editing the specified resource. | ||
*/ | ||
public function save(SettingRequest $request) | ||
{ | ||
$data = $request->validated(); | ||
$result = $this->settingService->save($data); | ||
|
||
if ($result) | ||
return redirect() | ||
->route("admin.index") | ||
->with("success", trans("Update Successfully")); | ||
return redirect()->back()->withErrors("Update Failed"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace App\Http\Middleware; | ||
|
||
use Closure; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class CheckAdminMiddleware | ||
{ | ||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next | ||
*/ | ||
public function handle(Request $request, Closure $next): Response | ||
{ | ||
if (Auth::user()->level !== 4) | ||
return redirect()->route('admin.login')->withErrors('You must login account admin to continue'); | ||
|
||
return $next($request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace App\Http\Repositories\Admin; | ||
|
||
use App\Models\Option; | ||
use Illuminate\Database\Eloquent\Builder; | ||
|
||
class SettingRepository | ||
{ | ||
protected Option $option; | ||
|
||
public function __construct() | ||
{ | ||
$this->option = new Option(); | ||
} | ||
|
||
/** | ||
* @param string $key | ||
* @return Builder|Option | ||
*/ | ||
public function getSetting(string $key): Builder|Option | ||
{ | ||
return $this->option::query() | ||
->where('name', $key)->firstOrFail(); | ||
} | ||
|
||
public function save(string $key, string $value = null): bool | ||
{ | ||
try { | ||
$option = $this->option::query() | ||
->updateOrCreate([ | ||
"name" => $key | ||
], [ | ||
"value" => $value | ||
]); | ||
|
||
$option->save(); | ||
return true; | ||
} catch (\Exception $e) { | ||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class SettingRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
*/ | ||
public function authorize(): bool | ||
{ | ||
return Auth::user()->level == 4; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string> | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
"site_name" => ["required", "string", "min:4"], | ||
"slogan" => ["required", "string", "min:4"], | ||
"logo_light" => ["image", "mimes:jpeg,png,jpg", "max:3072", "nullable"], | ||
"logo_dark" => ["image", "mimes:jpeg,png,jpg", "max:3072", "nullable"], | ||
"site_address" => ["required", "string", "min:4"], | ||
"email" => ["required", "email"], | ||
"phone" => ["required", "string", "min:5", "max:15"], | ||
"lat" => ["required", "numeric"], | ||
"lng" => ["required", "numeric"], | ||
]; | ||
} | ||
|
||
public function messages(): array | ||
{ | ||
return [ | ||
"image" => trans("Invalid image"), | ||
"mimes:jpeg,png,jpg" => trans("uploaded image must be png, jpg, jpeg file"), | ||
"max:3072" => trans("Images must be under 3072 kb"), | ||
"email" => trans("Unknown error please try again"), | ||
"string" => trans("Unknown error please try again"), | ||
"min:4" => trans("Fields must be more than 4 characters"), | ||
"phone.max:15" => trans("Fields must be less than 32 characters"), | ||
"numeric" => trans("Unknown error please try again"), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.