Skip to content

Commit

Permalink
setting.blade.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Nguyen Tan Dung committed Dec 10, 2023
1 parent 1d33130 commit c42480e
Show file tree
Hide file tree
Showing 31 changed files with 733 additions and 232 deletions.
50 changes: 50 additions & 0 deletions app/Helpers/Helper.php
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);
}
}
}
12 changes: 6 additions & 6 deletions app/Http/Controllers/Admin/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@

use App\Http\Controllers\Controller;
use App\Http\Requests\Auth\LoginRequest;
use App\Http\Services\Admin\AuthServices;
use App\Http\Services\Admin\AuthService;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;

class AuthController extends Controller
{
Protected AuthServices $authServices;
Protected AuthService $authServices;

public function __construct()
{
$this->authServices = new AuthServices();
$this->authServices = new AuthService();
}

public function login() : View
public function login(): View
{
return view('admin.auth.login');
}

public function logout()
public function logout(): RedirectResponse
{
Auth::logout();
return redirect()
->route('admin.login')
->with('success', trans("Logout Successfully"));
}

public function processLogin(LoginRequest $request)
public function processLogin(LoginRequest $request): RedirectResponse
{
$data = $request->validated();
$remember = $request->has('remember');
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Admin/HomepageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\View\View;

class HomepageController extends Controller
{
public function __invoke()
public function __invoke() : View
{
return view('admin.index');
}
Expand Down
65 changes: 0 additions & 65 deletions app/Http/Controllers/Admin/OptionController.php

This file was deleted.

42 changes: 42 additions & 0 deletions app/Http/Controllers/Admin/SettingController.php
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");
}
}
3 changes: 2 additions & 1 deletion app/Http/Controllers/User/HomepageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace App\Http\Controllers\User;

use App\Http\Controllers\Controller;
use Illuminate\View\View;

class HomepageController extends Controller
{
public function __invoke()
public function __invoke(): View
{
return view('index');
}
Expand Down
24 changes: 24 additions & 0 deletions app/Http/Middleware/CheckAdminMiddleware.php
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);
}
}
43 changes: 43 additions & 0 deletions app/Http/Repositories/Admin/SettingRepository.php
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;
}
}
}
51 changes: 51 additions & 0 deletions app/Http/Requests/SettingRequest.php
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"),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use App\Models\User;
use Illuminate\Support\Facades\Auth;

class AuthServices {
class AuthService {

public function login(string $email, string $password, bool $remember): bool
{
Expand Down
Loading

0 comments on commit c42480e

Please sign in to comment.