first commit

This commit is contained in:
benjibennn
2023-12-22 12:35:55 +08:00
commit 9f89a732d6
872 changed files with 156291 additions and 0 deletions

32
app/Console/Kernel.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')->hourly();
}
/**
* Register the commands for the application.
*
* @return void
*/
protected function commands()
{
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}

34
app/Events/ChatEvent.php Normal file
View File

@@ -0,0 +1,34 @@
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class ChatEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $chatId;
public $toAdmin;
public $userId;
public function __construct($chatId, $toAdmin = false, $userId = null)
{
$this->chatId = $chatId;
$this->toAdmin = $toAdmin;
$this->userId = $userId;
}
public function broadcastOn(): array
{
return [
new Channel('chat-channel'),
];
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Tymon\JWTAuth\Exceptions\JWTException;
use Tymon\JWTAuth\Exceptions\TokenExpiredException;
use Tymon\JWTAuth\Exceptions\TokenInvalidException;
use Throwable;
use Response;
use Exception;
class Handler extends ExceptionHandler
{
/**
* A list of exception types with their corresponding custom log levels.
*
* @var array<class-string<\Throwable>, \Psr\Log\LogLevel::*>
*/
protected $levels = [
//
];
/**
* A list of the exception types that are not reported.
*
* @var array<int, class-string<\Throwable>>
*/
protected $dontReport = [
//
];
/**
* A list of the inputs that are never flashed to the session on validation exceptions.
*
* @var array<int, string>
*/
protected $dontFlash = [
'current_password',
'password',
'password_confirmation',
];
/**
* Register the exception handling callbacks for the application.
*
* @return void
*/
public function register()
{
if (request()->is('api/*')) {
$this->renderable(function (Throwable $e) {
return Response::json(['error'=>$e->getMessage()],500);
});
$this->renderable(function(TokenInvalidException $e, $request){
return Response::json(['error'=>'Invalid token'],401);
});
$this->renderable(function (TokenExpiredException $e, $request) {
return Response::json(['error'=>'Token has Expired'],401);
});
$this->renderable(function (JWTException $e, $request) {
return Response::json(['error'=>'Token not parsed'],401);
});
}
else {
$this->reportable(function (Throwable $e) {
//
});
}
}
}

View File

@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Storage;
class BookkeepingDocumentLibraryExport implements FromCollection, WithMapping, WithHeadings
{
protected $documents;
public function __construct($documents)
{
$this->documents = $documents;
}
public function collection()
{
return $this->documents;
}
public function map($documents): array
{
return [
$documents->file_name,
(strtolower(app()->getLocale()) == 'zh_hk' ? $documents->name_chinese : $documents->name_english),
$documents->category_name,
$documents->user_name,
Storage::exists($documents->file_path) ? (round(Storage::size($documents->file_path) / 1000) . 'KB') : '-',
$documents->created_at->format('Ymd-H:i'),
];
}
public function headings(): array
{
return [
'Document Name',
'Company',
'Document Category',
'Upload User',
'Document Size',
'Date Uploaded',
];
}
}

BIN
app/Http/.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -0,0 +1,10 @@
<?php
namespace App\Http\Controllers\Auth;
use Wave\Http\Controllers\Auth\ForgotPasswordController as AuthForgotPasswordController;
class ForgotPasswordController extends AuthForgotPasswordController
{
}

View File

@@ -0,0 +1,10 @@
<?php
namespace App\Http\Controllers\Auth;
use Wave\Http\Controllers\Auth\LoginController as AuthLoginController;
class LoginController extends AuthLoginController
{
}

View File

@@ -0,0 +1,10 @@
<?php
namespace App\Http\Controllers\Auth;
use Wave\Http\Controllers\Auth\RegisterController as AuthRegisterController;
class RegisterController extends AuthRegisterController
{
}

View File

@@ -0,0 +1,10 @@
<?php
namespace App\Http\Controllers\Auth;
use Wave\Http\Controllers\Auth\ResetPasswordController as AuthResetPasswordController;
class ResetPasswordController extends AuthResetPasswordController
{
}

View File

@@ -0,0 +1,13 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}

72
app/Http/Kernel.php Normal file
View File

@@ -0,0 +1,72 @@
<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array<int, class-string|string>
*/
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
\Illuminate\Http\Middleware\HandleCors::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
];
/**
* The application's route middleware groups.
*
* @var array<string, array<int, class-string|string>>
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\App\Http\Middleware\Localization::class,
],
'api' => [
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
'throttle:api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array<string, class-string|string>
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
'auth.jwt'=>\App\Http\Middleware\JwtMiddleWare::class,
'user' => \App\Http\Middleware\CheckIfUserRole::class,
'admin' => \App\Http\Middleware\CheckIfAdminRole::class,
'route.access' => \App\Http\Middleware\HasRouteAccess::class,
];
}

View File

@@ -0,0 +1,107 @@
<?php
namespace App\Http\Livewire\Wave;
use Illuminate\Support\Facades\Http;
use Livewire\Component;
class DeployToDo extends Component
{
public $api_key;
public $repo;
public $deploy;
public $app_id;
public $deployments;
public $app;
public function mount(){
// get the deploy.json file and convert to object
$this->deploy = json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/', '', file_get_contents(base_path('deploy.json')) ), true);
$this->checkForAppDeployment();
}
private function checkForAppDeployment(){
if(isset( $this->deploy['wave'] ) && isset( $this->deploy['wave']['app_id'] )){
$this->app_id = $this->deploy['wave']['app_id'];
$this->api_key = $this->deploy['wave']['api_key'];
$this->deployments = $this->getDeployments();
$this->app = $this->getAppInfo();
}
}
public function getDeployments(){
$response = Http::withToken($this->api_key)->get('https://api.digitalocean.com/v2/apps/' . $this->app_id . '/deployments');
return json_decode($response->body(), true);
}
public function getAppInfo(){
$response = Http::withToken($this->api_key)->get('https://api.digitalocean.com/v2/apps/' . $this->app_id);
return json_decode($response->body(), true);
}
private function writeToDeployFile($id, $key, $deployFileArray){
$deployFileArray['wave']['app_id'] = $id;
$deployFileArray['wave']['api_key'] = $key;
file_put_contents(base_path('deploy.json'), stripslashes(json_encode($deployFileArray, JSON_PRETTY_PRINT)));
$this->deploy = json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/', '', file_get_contents(base_path('deploy.json')) ), true);
}
public function deploy(){
if(!isset($this->app_id)){
// repo must contain a '/', do a check for that
$repoSplit = explode('/', $this->repo);
$repoName = (isset($repoSplit[0]) && isset($repoSplit[1])) ? $repoSplit[0] . '-' . $repoSplit[1] : false;
if(!$repoName){
$this->dispatchBrowserEvent('notify', ['type' => 'error', 'message' => 'Please make sure you enter a valiid repo (ex: user/repo)']);
return;
}
if(empty($this->api_key)){
$this->dispatchBrowserEvent('notify', ['type' => 'error', 'message' => 'C\'mon, you can\'t leave the API key field empty.']);
return;
}
if(is_null($this->deploy)){
$this->dispatchBrowserEvent('notify', ['type' => 'error', 'message' => 'Sorry it looks like your deploy.json does not contain valid JSON']);
return;
}
// replace values with repoName and Repo url
$finalJSONPayload = json_encode($this->deploy);
$finalJSONPayload = str_replace('${wave.name}', str_replace('_', '-', $repoName), $finalJSONPayload);
//dd($this->repo);
$finalJSONPayload = str_replace('${wave.repo}', $this->repo, $finalJSONPayload);
$response = Http::withToken($this->api_key)->withBody( $finalJSONPayload, 'application/json')
->post('https://api.digitalocean.com/v2/apps');
// if the response is not successful, display the message back from DigitalOcean
if(!$response->successful()){
$responseBody = json_decode($response->body(), true);
$this->dispatchBrowserEvent('notify', ['type' => 'error', 'message' => $responseBody['message']]);
return;
}
// get app ID and set it in the JSON
$responseBody = json_decode($response->body(), true);
$this->writeToDeployFile($responseBody['app']['id'], $this->api_key, $this->deploy);
$this->checkForAppDeployment();
$this->dispatchBrowserEvent('notify', ['type' => 'success', 'message' => 'Successfully deployed your application!']);
//dd('hit');
}
}
public function render()
{
return view('livewire.wave.deploy-to-do');
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*
* @param \Illuminate\Http\Request $request
* @return string|null
*/
protected function redirectTo($request)
{
if (! $request->expectsJson()) {
return route('login');
}
}
}

View File

@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace App\Http\Middleware;
use App\Models\Role;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class CheckIfAdminRole
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
// Check status
if (auth()->user()->status == 'inactive') {
$redirectUrl = auth()->user()->getRedirectRouteIfNotAuthenticated();
auth()->logout();
return redirect($redirectUrl);
}
// Check role
$roles = [
Role::IT_PERSONNEL_ROLE,
Role::NUMSTATION_MANAGER_ROLE,
Role::NUMSTATION_STAFF_ROLE,
];
if (in_array(auth()->user()->role_id, $roles)) {
return $next($request);
}
return abort(Response::HTTP_FORBIDDEN, '403 Access Forbidden');
}
}

View File

@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
namespace App\Http\Middleware;
use App\Models\Role;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class CheckIfUserRole
{
/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
// Check status
if (auth()->user()->status == 'inactive') {
$redirectUrl = auth()->user()->getRedirectRoute();
auth()->logout();
return redirect($redirectUrl);
}
// Check role
$roles = [
Role::OWNER_ROLE,
Role::ADMINISTRATOR_ROLE,
Role::BOOKKEEPER_ROLE,
Role::COMPANY_SECRETARY_ROLE,
];
if (in_array(auth()->user()->role_id, $roles)) {
return $next($request);
}
return abort(Response::HTTP_FORBIDDEN, '403 Access Forbidden');
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
class EncryptCookies extends Middleware
{
/**
* The names of the cookies that should not be encrypted.
*
* @var array<int, string>
*/
protected $except = [
//
];
}

View File

@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
namespace App\Http\Middleware;
// use App\Models\Permission;
// use App\Models\RoleAccess;
use Auth;
use Closure;
use Illuminate\Auth\Access\AuthorizationException;
use Symfony\Component\HttpFoundation\Response;
class HasRouteAccess
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*
* @throws AuthorizationException
*/
public function handle($request, Closure $next)
{
$action = $request->route()->getActionName();
$permissionRoutes = config('permission-routes');
$permissionKey = '';
foreach ($permissionRoutes as $key => $routes) {
if (in_array($action, $routes)) {
$permissionKey = $key;
break;
}
}
if ($permissionKey == '' || Auth::user()->userRole->hasAccess($permissionKey)) {
return $next($request);
}
return abort(Response::HTTP_FORBIDDEN, '403 Access Forbidden');
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Http\Middleware;
use Closure;
class HttpsRedirect
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (!$request->secure() && app()->environment('production')) {
return redirect()->secure($request->getRequestUri());
}
return $next($request);
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use JWTAuth;
class JWTMiddleWare
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle(Request $request, Closure $next)
{
$user = JWTAuth::parseToken()->authenticate();
return $next($request);
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Session;
class Localization
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle(Request $request, Closure $next)
{
if (Session::has('locale')) {
App::setLocale(Session::get('locale'));
}
return $next($request);
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
class PreventRequestsDuringMaintenance extends Middleware
{
/**
* The URIs that should be reachable while maintenance mode is enabled.
*
* @var array<int, string>
*/
protected $except = [
//
];
}

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
* @param string|null ...$guards
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
*/
public function handle(Request $request, Closure $next, ...$guards)
{
$guards = empty($guards) ? [null] : $guards;
foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return redirect(Auth::user()->getRedirectRoute());
}
}
return $next($request);
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
class TrimStrings extends Middleware
{
/**
* The names of the attributes that should not be trimmed.
*
* @var array<int, string>
*/
protected $except = [
'current_password',
'password',
'password_confirmation',
];
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Http\Middleware\TrustHosts as Middleware;
class TrustHosts extends Middleware
{
/**
* Get the host patterns that should be trusted.
*
* @return array<int, string|null>
*/
public function hosts()
{
return [
$this->allSubdomainsOfApplicationUrl(),
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Http\Middleware\TrustProxies as Middleware;
use Illuminate\Http\Request;
class TrustProxies extends Middleware
{
/**
* The trusted proxies for this application.
*
* @var array<int, string>|string|null
*/
protected $proxies;
/**
* The headers that should be used to detect proxies.
*
* @var int
*/
protected $headers =
Request::HEADER_X_FORWARDED_FOR |
Request::HEADER_X_FORWARDED_HOST |
Request::HEADER_X_FORWARDED_PORT |
Request::HEADER_X_FORWARDED_PROTO |
Request::HEADER_X_FORWARDED_AWS_ELB;
}

View File

@@ -0,0 +1,18 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
class VerifyCsrfToken extends Middleware
{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array<int, string>
*/
protected $except = [
'/paddle/webhook',
'/v1/api/*',
];
}

View File

@@ -0,0 +1,64 @@
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class ForgetPasswordOtp extends Mailable
{
use Queueable, SerializesModels;
protected $otp;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($otp)
{
$this->otp = $otp;
}
/**
* Get the message envelope.
*
* @return \Illuminate\Mail\Mailables\Envelope
*/
public function envelope()
{
return new Envelope(
subject: 'Forget Password Otp',
);
}
/**
* Get the message content definition.
*
* @return \Illuminate\Mail\Mailables\Content
*/
public function content()
{
return new Content(
markdown: 'theme::emails.forgot-password-otp',
with: [
'otp' => $this->otp,
],
);
}
/**
* Get the attachments for the message.
*
* @return array
*/
public function attachments()
{
return [];
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class SendUserInvite extends Mailable
{
use Queueable, SerializesModels;
protected $url;
protected $companyName;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($url, $companyName)
{
$this->url = $url;
$this->companyName = $companyName;
}
/**
* Get the message envelope.
*
* @return \Illuminate\Mail\Mailables\Envelope
*/
public function envelope()
{
return new Envelope(
subject: 'You are invited to ' . $this->companyName,
);
}
/**
* Get the message content definition.
*
* @return \Illuminate\Mail\Mailables\Content
*/
public function content()
{
return new Content(
markdown: 'theme::emails.send-user-invite',
with: [
'url' => $this->url,
'companyName' => $this->companyName,
],
);
}
/**
* Get the attachments for the message.
*
* @return array
*/
public function attachments()
{
return [];
}
}

View File

@@ -0,0 +1,73 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Storage;
class BookkeepingDocument extends Model
{
use HasFactory;
public const PATH_PREFIX = 'public/bookkeeping';
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'company_id',
'user_id',
'batch_name',
'remark',
'file_name',
'bookkeeping_document_category_id',
'status',
'data_molino_status',
'data_molino_return_status',
'xero_status',
'xero_amount',
'url',
'name',
'description',
'file_size',
];
public function company()
{
return $this->belongsTo(Company::class);
}
public function user()
{
return $this->belongsTo(User::class);
}
public function category()
{
return $this->belongsTo(BookkeepingDocumentCategory::class, 'bookkeeping_document_category_id', 'id');
}
public function getFolderPathAttribute()
{
return self::PATH_PREFIX . '/' . $this->id;
}
public function getFilePathAttribute()
{
return ! $this->file_name ? null : $this->getFolderPathAttribute() . "/{$this->file_name}";
}
public function getFileUrlAttribute()
{
$path = $this->getFilePathAttribute();
if ($path && Storage::exists($path)) {
return env('AWS_ENDPOINT') . env('AWS_BUCKET') . '/' . $path;
}
return '#';
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class BookkeepingDocumentCategory extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'status',
];
}

47
app/Models/Company.php Normal file
View File

@@ -0,0 +1,47 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Company extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'email',
'name_english',
'name_chinese',
'registered_office_address_english',
'registered_office_address_chinese',
'br_number',
'xero_api_key',
];
public function getNameAttribute()
{
if (strtolower(app()->getLocale()) == 'zh_hk') {
return $this->name_chinese;
}
return $this->name_english;
}
public function getRegisteredOfficeAddressAttribute()
{
if (strtolower(app()->getLocale()) == 'zh_hk') {
return $this->registered_office_address_chinese;
}
return $this->registered_office_address_english;
}
public function users()
{
return $this->hasMany(User::class);
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class CompanyDocument extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'company_id',
'member_id',
'filename',
'url',
];
}

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class CompanyMember extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'company_id',
'position',
'title',
'name_english',
'name_chinese',
'phone',
'email',
'document_type',
'document_number',
'country',
'address_english',
'address_chinese',
'year_date',
'month_date',
'day_date',
];
public function documents()
{
return $this->hasMany(CompanyDocument::class, 'member_id', 'id');
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class CompanySubscription extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'company_id',
'subscription_id',
'stripe_subscription_id',
'status',
'expiration_at',
];
public function company()
{
return $this->hasOne(Company::class, 'id', 'company_id');
}
public function subscription()
{
return $this->hasOne(Subscription::class, 'id', 'subscription_id');
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class DocumentActionLogs extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'user_id',
'event',
'description',
'status',
'type',
];
public function user()
{
return $this->belongsTo(User::class);
}
}

24
app/Models/InviteUser.php Normal file
View File

@@ -0,0 +1,24 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class InviteUser extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'email',
'token',
'user_id',
'company_id',
'is_used',
];
}

49
app/Models/OnlineHelp.php Normal file
View File

@@ -0,0 +1,49 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class OnlineHelp extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'title_english',
'title_chinese',
'details_english',
'details_chinese',
'category',
'sort',
];
public function getTitleAttribute()
{
if (strtolower(app()->getLocale()) == 'zh_hk') {
return $this->title_chinese;
}
return $this->title_english;
}
public function getDetailsAttribute()
{
if (strtolower(app()->getLocale()) == 'zh_hk') {
return $this->detailss_chinese;
}
return $this->detailss_english;
}
public function getCategoryNameDisplayAttribute()
{
if ($this->category == 'faq') {
return __("FAQ");
}
return __("Online Documents");
}
}

16
app/Models/Permission.php Normal file
View File

@@ -0,0 +1,16 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Permission extends Model
{
use HasFactory;
public function permissionGroup()
{
return $this->hasOne(PermissionGroup::class, 'id', 'permission_group_id');
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class PermissionGroup extends Model
{
use HasFactory;
public function permissions()
{
return $this->hasMany(Permission::class);
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class PermissionRole extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'permission_id',
'role_id',
'company_id',
];
public $timestamps = false;
public function permission()
{
return $this->hasOne(Permission::class, 'id', 'permission_id');
}
public function role()
{
return $this->hasOne(Role::class, 'id', 'role_id');
}
}

50
app/Models/Role.php Normal file
View File

@@ -0,0 +1,50 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Role extends Model
{
use HasFactory;
// Built In Roles
public const ADMIN_ROLE = 1;
public const TRIAL_ROLE = 2;
public const BASIC_ROLE = 3;
public const PRO_ROLE = 4;
public const PREMIUM_ROLE = 5;
public const CANCELLED_ROLE = 6;
// Custom Roles
// User
public const OWNER_ROLE = 7;
public const ADMINISTRATOR_ROLE = 8;
public const BOOKKEEPER_ROLE = 9;
public const COMPANY_SECRETARY_ROLE = 10;
// Admin
public const IT_PERSONNEL_ROLE = 11;
public const NUMSTATION_MANAGER_ROLE = 12;
public const NUMSTATION_STAFF_ROLE = 13;
public function users()
{
return $this->hasMany(User::class);
}
public function rolePermissions()
{
return $this->hasMany(PermissionRole::class);
}
public function hasAccess($permissionKey)
{
$permission = Permission::where('key', $permissionKey)->first();
if ($permission) {
return $this->rolePermissions()->where('permission_id', $permission->id)->exists();
}
return false;
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class ServiceChat extends Model
{
use HasFactory;
public const PATH_PREFIX = 'public/chats';
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'company_id',
'user_id',
'service_type',
];
public function messages()
{
return $this->hasMany(ServiceChatMessage::class);
}
public function user()
{
return $this->belongsTo(User::class);
}
public function company()
{
return $this->belongsTo(Company::class);
}
public function getFolderPathAttribute()
{
return self::PATH_PREFIX . '/' . $this->id;
}
}

View File

@@ -0,0 +1,78 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Storage;
class ServiceChatMessage extends Model
{
use HasFactory;
public const PATH_PREFIX = 'public/chats';
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'service_chat_id',
'message',
'from_user_id',
'to_user_id',
'to_admin',
'is_file',
'file_name',
'is_read',
];
public function getElapsedTimeAttribute()
{
$time = time() - $this->created_at->timestamp;
$time = $time < 1 ? 1 : $time;
$tokens = [
31536000 => 'year',
2592000 => 'month',
604800 => 'week',
86400 => 'day',
3600 => 'hour',
60 => 'min',
1 => 'second',
];
foreach ($tokens as $unit => $text) {
if ($time < $unit) {
continue;
}
$numberOfUnits = floor($time / $unit);
return $numberOfUnits . ' ' . $text . ($numberOfUnits > 1 ? 's' : '') . ' ago';
}
return '';
}
public function getFolderPathAttribute()
{
return self::PATH_PREFIX . '/' . $this->service_chat_id;
}
public function getFilePathAttribute()
{
return ! $this->file_name ? null : $this->getFolderPathAttribute() . "/{$this->file_name}";
}
public function getFileUrlAttribute()
{
$path = $this->getFilePathAttribute();
if ($path && Storage::exists($path)) {
return env('AWS_ENDPOINT') . env('AWS_BUCKET') . '/' . $path;
}
return null;
}
}

View File

@@ -0,0 +1,63 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class SiteSetting extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'terms_and_conditions_english',
'terms_and_conditions_chinese',
'privacy_policy_english',
'privacy_policy_chinese',
'phone',
'whatsapp',
'email',
'office_hour_english',
'office_hour_chinese',
'address_english',
'address_chinese',
'google_drive_api_key',
];
public function getTermsAndConditionsAttribute()
{
if (strtolower(app()->getLocale()) == 'zh_hk') {
return $this->terms_and_conditions_chinese;
}
return $this->terms_and_conditions_english;
}
public function getPrivacyPolicyAttribute()
{
if (strtolower(app()->getLocale()) == 'zh_hk') {
return $this->privacy_policy_chinese;
}
return $this->privacy_policy_english;
}
public function getOfficeHourAttribute()
{
if (strtolower(app()->getLocale()) == 'zh_hk') {
return $this->office_hour_chinese;
}
return $this->office_hour_english;
}
public function getAddressAttribute()
{
if (strtolower(app()->getLocale()) == 'zh_hk') {
return $this->address_chinese;
}
return $this->address_english;
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Subscription extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'service_type',
'name_english',
'name_chinese',
'period_english',
'period_chinese',
'description_english',
'description_chinese',
'price',
'status',
];
public function basicServices()
{
return $this->hasMany(SubscriptionBasicService::class);
}
public function optionalServices()
{
return $this->hasMany(SubscriptionOptionalService::class);
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class SubscriptionBasicService extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'subscription_id',
'title_english',
'title_chinese',
];
public function lists()
{
return $this->hasMany(SubscriptionBasicServiceList::class);
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class SubscriptionBasicServiceList extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'subscription_basic_service_id',
'title_english',
'title_chinese',
];
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class SubscriptionOptionalService extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'subscription_id',
'title_english',
'title_chinese',
'price',
'period',
'is_custom',
'custom_description',
];
}

126
app/Models/User.php Normal file
View File

@@ -0,0 +1,126 @@
<?php
namespace App\Models;
use App\Providers\RouteServiceProvider;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Notifications\Notifiable;
use Wave\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable, SoftDeletes;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'username',
'password',
'verification_code',
'verified',
'trial_ends_at',
'company_id',
'first_name',
'last_name',
'alias_name',
'phone',
'forgot_password_otp',
'status',
'role_id',
'api_token',
'admin_active_company_id'
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'trial_ends_at' => 'datetime',
];
public function getRedirectRoute()
{
switch ($this->role_id) {
case Role::OWNER_ROLE:
return RouteServiceProvider::USER_HOME;
case Role::ADMINISTRATOR_ROLE:
return RouteServiceProvider::USER_HOME;
case Role::BOOKKEEPER_ROLE:
return RouteServiceProvider::USER_HOME;
case Role::COMPANY_SECRETARY_ROLE:
return RouteServiceProvider::USER_HOME;
case Role::IT_PERSONNEL_ROLE:
return RouteServiceProvider::ADMIN_HOME;
case Role::NUMSTATION_MANAGER_ROLE:
return RouteServiceProvider::ADMIN_HOME;
case Role::NUMSTATION_STAFF_ROLE:
return RouteServiceProvider::ADMIN_HOME;
default:
return RouteServiceProvider::USER_HOME;
}
}
public function getRedirectRouteIfNotAuthenticated()
{
switch ($this->role_id) {
case Role::OWNER_ROLE:
return RouteServiceProvider::USER_LOGIN;
case Role::ADMINISTRATOR_ROLE:
return RouteServiceProvider::USER_LOGIN;
case Role::BOOKKEEPER_ROLE:
return RouteServiceProvider::USER_LOGIN;
case Role::COMPANY_SECRETARY_ROLE:
return RouteServiceProvider::USER_LOGIN;
case Role::IT_PERSONNEL_ROLE:
return RouteServiceProvider::ADMIN_LOGIN;
case Role::NUMSTATION_MANAGER_ROLE:
return RouteServiceProvider::ADMIN_LOGIN;
case Role::NUMSTATION_STAFF_ROLE:
return RouteServiceProvider::ADMIN_LOGIN;
default:
return RouteServiceProvider::USER_LOGIN;
}
}
public function company()
{
return $this->belongsTo(Company::class);
}
public function notificationSettings()
{
return $this->hasMany(UserNotificationSetting::class);
}
public function userRole()
{
return $this->hasOne(Role::class, 'id', 'role_id');
}
public function notifications()
{
return $this->hasMany(UserNotification::class);
}
public function adminActiveCompany()
{
return $this->hasOne(Company::class, 'id', 'admin_active_company_id');
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class UserAccessLog extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'user_id',
'event',
'description',
'status'
];
}

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class UserCompany extends Model
{
use HasFactory;
}

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class UserEnquiry extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'user_id',
'name',
'phone',
'email',
'title',
'message',
'category',
'status',
'reply',
];
public function user()
{
return $this->belongsTo(User::class);
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class UserNotification extends Model
{
use HasFactory;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'user_id',
'title',
'description',
'category',
'target_id',
'target_type',
'is_read',
'is_admin',
'status',
];
public function getUrlAttribute()
{
$url = '';
if (strtolower($this->category) == 'service chat') {
$url = route('cms.chat');
$chat = ServiceChat::find($this->target_id);
if ($chat) {
$url = $url . '?user_id=' . $chat->user_id . '&company_id=' . $chat->company_id . '&chat_id=' . $this->target_id;
}
}
else if (strtolower($this->category) == 'bookkeeping queue') {
$url = route('cms.bookkeepings');
}
return $url;
}
public function getCategoryUrlAttribute()
{
$url = '';
if (strtolower($this->category) == 'service chat') {
$url = route('cms.chat');
}
else if (strtolower($this->category) == 'bookkeeping queue') {
$url = route('cms.bookkeepings');
}
return $url;
}
public function getImageUrlAttribute()
{
$url = '';
if (strtolower($this->category) == 'service chat') {
$url = asset('themes/tailwind/images/building.svg');
}
else if (strtolower($this->category) == 'bookkeeping queue') {
$ext = pathinfo($this->description, PATHINFO_EXTENSION);
$url = $ext == 'pdf' ? asset('themes/tailwind/images/pdf.svg') : asset('themes/tailwind/images/jpg.svg');
}
return $url;
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class UserNotificationSetting extends Model
{
use HasFactory;
//
public const USER_PUSH_NOTIFICATION = 'user_push_notification';
public const USER_BOOKKEEPING_QUEUE = 'user_bookkeeping_queue';
public const USER_COMPANY_SECURTY_QUEUE = 'user_company_securty_queue';
public const USER_CHAT_ROOM = 'user_chat_room';
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'user_id',
'notification',
'is_active',
];
}

View File

@@ -0,0 +1,107 @@
<?php
namespace App\Providers;
use App\Models\Company;
// use App\Models\RelationshipUserCompany;
use App\Models\User;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\View;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
if ($this->app->environment() == 'production') {
$this->app['request']->server->set('HTTPS', true);
}
$this->setSchemaDefaultLength();
Validator::extend('base64image', function ($attribute, $value, $parameters, $validator) {
$explode = explode(',', $value);
$allow = ['png', 'jpg', 'svg', 'jpeg'];
$format = str_replace(
[
'data:image/',
';',
'base64',
],
[
'', '', '',
],
$explode[0]
);
// check file format
if (!in_array($format, $allow)) {
return false;
}
// check base64 format
if (!preg_match('%^[a-zA-Z0-9/+]*={0,2}$%', $explode[1])) {
return false;
}
return true;
});
view()->composer('partials.language_switcher', function ($view) {
$view->with('current_locale', app()->getLocale());
$view->with('available_locales', config('app.available_locales'));
});
View::composer(['theme::user.layouts.app'], function ($view) {
if (auth()->check()) {
$current_user = auth()->user();
$current_company = Company::find($current_user->current_active_company);
// $userCompanies = RelationshipUserCompany::where('user_id', $current_user->id)->pluck('company_id')->all();
// $companies = Company::findMany($userCompanies);
$view->with([
// 'companies' => $companies,
// 'userCompanies' => $userCompanies,
'current_company' => $current_company,
]);
}
});
// View::composer(['theme::layouts.app'], function ($view) {
// if (auth()->check()) {
// $current_user = auth()->user();
// $users = User::where('role_id', '>=', '11')->where('status', 'active')->get();
// $view->with([
// 'users' => $users,
// ]);
// }
// });
}
private function setSchemaDefaultLength(): void
{
try {
Schema::defaultStringLength(191);
}
catch (\Exception $exception){}
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
class AuthServiceProvider extends ServiceProvider
{
/**
* The model to policy mappings for the application.
*
* @var array<class-string, class-string>
*/
protected $policies = [
// 'App\Models\Model' => 'App\Policies\ModelPolicy',
];
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
//
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Broadcast;
use Illuminate\Support\ServiceProvider;
class BroadcastServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Broadcast::routes();
require base_path('routes/channels.php');
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Providers;
use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;
class EventServiceProvider extends ServiceProvider
{
/**
* The event to listener mappings for the application.
*
* @var array<class-string, array<int, class-string>>
*/
protected $listen = [
// Registered::class => [
// SendEmailVerificationNotification::class,
// ],
];
/**
* Register any events for your application.
*
* @return void
*/
public function boot()
{
//
}
/**
* Determine if events and listeners should be automatically discovered.
*
* @return bool
*/
public function shouldDiscoverEvents()
{
return false;
}
}

View File

@@ -0,0 +1,55 @@
<?php
namespace App\Providers;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
{
/**
* The path to the "home" route for your application.
*
* Typically, users are redirected here after authentication.
*
* @var string
*/
public const USER_HOME = '/user/dashboard';
public const USER_LOGIN = '/login';
public const ADMIN_HOME = '/cms/dashboard';
public const ADMIN_LOGIN = '/cms/login';
/**
* Define your route model bindings, pattern filters, and other route configuration.
*
* @return void
*/
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
Route::middleware('api')
->prefix('api')
->group(base_path('routes/api.php'));
Route::middleware('web')
->group(base_path('routes/web.php'));
});
}
/**
* Configure the rate limiters for the application.
*
* @return void
*/
protected function configureRateLimiting()
{
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
});
}
}

20
app/helpers.php Normal file
View File

@@ -0,0 +1,20 @@
<?php
use App\Models\UserNotification;
if (! function_exists('storeUserNotification')) {
function storeUserNotification($userId, $title, $description = null, $category = null, $isAdmin = false, $targetId = null, $targetType = null, $status = 'success', $isRead = false)
{
return UserNotification::create([
'user_id' => $userId,
'title' => $title,
'description' => $description,
'category' => $category,
'target_id' => $targetId,
'target_type' => $targetType,
'is_read' => $isRead,
'is_admin' => $isAdmin,
'status' => $status,
]);
}
}