complete Complete User Request Submission section RAD-1
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
indent_size = 4
|
||||
indent_style = space
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.{yml,yaml}]
|
||||
indent_size = 2
|
||||
|
||||
[docker-compose.yml]
|
||||
indent_size = 4
|
||||
@@ -0,0 +1,65 @@
|
||||
APP_NAME=Laravel
|
||||
APP_ENV=local
|
||||
APP_KEY=
|
||||
APP_DEBUG=true
|
||||
APP_URL=http://localhost
|
||||
|
||||
APP_LOCALE=en
|
||||
APP_FALLBACK_LOCALE=en
|
||||
APP_FAKER_LOCALE=en_US
|
||||
|
||||
APP_MAINTENANCE_DRIVER=file
|
||||
# APP_MAINTENANCE_STORE=database
|
||||
|
||||
PHP_CLI_SERVER_WORKERS=4
|
||||
|
||||
BCRYPT_ROUNDS=12
|
||||
|
||||
LOG_CHANNEL=stack
|
||||
LOG_STACK=single
|
||||
LOG_DEPRECATIONS_CHANNEL=null
|
||||
LOG_LEVEL=debug
|
||||
|
||||
DB_CONNECTION=mysql
|
||||
# DB_HOST=127.0.0.1
|
||||
# DB_PORT=3306
|
||||
# DB_DATABASE=laravel
|
||||
# DB_USERNAME=root
|
||||
# DB_PASSWORD=
|
||||
|
||||
SESSION_DRIVER=database
|
||||
SESSION_LIFETIME=120
|
||||
SESSION_ENCRYPT=false
|
||||
SESSION_PATH=/
|
||||
SESSION_DOMAIN=null
|
||||
|
||||
BROADCAST_CONNECTION=log
|
||||
FILESYSTEM_DISK=local
|
||||
QUEUE_CONNECTION=database
|
||||
|
||||
CACHE_STORE=database
|
||||
# CACHE_PREFIX=
|
||||
|
||||
MEMCACHED_HOST=127.0.0.1
|
||||
|
||||
REDIS_CLIENT=phpredis
|
||||
REDIS_HOST=127.0.0.1
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
|
||||
MAIL_MAILER=log
|
||||
MAIL_SCHEME=null
|
||||
MAIL_HOST=127.0.0.1
|
||||
MAIL_PORT=2525
|
||||
MAIL_USERNAME=null
|
||||
MAIL_PASSWORD=null
|
||||
MAIL_FROM_ADDRESS="hello@example.com"
|
||||
MAIL_FROM_NAME="${APP_NAME}"
|
||||
|
||||
AWS_ACCESS_KEY_ID=
|
||||
AWS_SECRET_ACCESS_KEY=
|
||||
AWS_DEFAULT_REGION=us-east-1
|
||||
AWS_BUCKET=
|
||||
AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||
|
||||
VITE_APP_NAME="${APP_NAME}"
|
||||
@@ -0,0 +1,11 @@
|
||||
* text=auto eol=lf
|
||||
|
||||
*.blade.php diff=html
|
||||
*.css diff=css
|
||||
*.html diff=html
|
||||
*.md diff=markdown
|
||||
*.php diff=php
|
||||
|
||||
/.github export-ignore
|
||||
CHANGELOG.md export-ignore
|
||||
.styleci.yml export-ignore
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/.phpunit.cache
|
||||
/node_modules
|
||||
/public/hot
|
||||
/public/build
|
||||
/public/storage
|
||||
/storage/*.key
|
||||
/storage/pail
|
||||
/vendor
|
||||
.env
|
||||
.env.backup
|
||||
.env.production
|
||||
.phpactor.json
|
||||
.phpunit.result.cache
|
||||
Homestead.json
|
||||
Homestead.yaml
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
/auth.json
|
||||
/.fleet
|
||||
/.idea
|
||||
/.nova
|
||||
/.vscode
|
||||
/.zed
|
||||
.DS_Store
|
||||
package-lock.json
|
||||
@@ -0,0 +1,106 @@
|
||||
import defaultTheme from "tailwindcss/defaultTheme";
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
export default {
|
||||
content: [
|
||||
'./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php',
|
||||
'./storage/framework/views/*.php',
|
||||
'./resources/**/*.blade.php',
|
||||
'./resources/**/*.js',
|
||||
'./resources/**/*.vue',
|
||||
],
|
||||
darkMode: 'class',
|
||||
theme: {
|
||||
container: {
|
||||
center: true,
|
||||
},
|
||||
extend: {
|
||||
colors: {
|
||||
client: {
|
||||
sidebar: {
|
||||
text: '#97a2b6',
|
||||
icon: '#97a2b6',
|
||||
textHover: '#9899ac',
|
||||
iconHover: '#9899ac',
|
||||
hoverItem: '#009ef7',
|
||||
bgLink: '#030615',
|
||||
bgLinkHover: '#252a41',
|
||||
bgLinkHoverItem: '#2f3551',
|
||||
background: '#171a28',
|
||||
},
|
||||
primary: '#18181B',
|
||||
primaryDarker: '#3A1078',
|
||||
primaryBlue: '#3795BD',
|
||||
primaryLight: '#F7F7F8',
|
||||
white: '#FFFFFF',
|
||||
gray: 'rgba(102,102,102,0.62)',
|
||||
Fontcolor: '#3A3845',
|
||||
},
|
||||
sidebar: {
|
||||
text: '#9899ac',
|
||||
svgHover: '#009ef7',
|
||||
bgHover: '#1B1B28',
|
||||
},
|
||||
body: {
|
||||
light: '#F2F4F7',
|
||||
},
|
||||
white: {
|
||||
DEFAULT: '#ffffff',
|
||||
active: '#F5F8FA',
|
||||
},
|
||||
primary: {
|
||||
DEFAULT: '#009EF7',
|
||||
active: '#0095e8',
|
||||
light: '#F1FAFF',
|
||||
},
|
||||
light: {
|
||||
DEFAULT: '#F5F8FA',
|
||||
active: '#eff2f5',
|
||||
},
|
||||
secondary: {
|
||||
DEFAULT: '#E4E6EF',
|
||||
active: '#b5b5c3',
|
||||
},
|
||||
success: {
|
||||
DEFAULT: '#50CD89',
|
||||
active: '#47be7e',
|
||||
light: '#E8FFF3',
|
||||
},
|
||||
info: {
|
||||
DEFAULT: '#7239EA',
|
||||
active: '#5014d0',
|
||||
light: '#F8F5FF',
|
||||
},
|
||||
warning: {
|
||||
DEFAULT: '#FFC700',
|
||||
active: '#f1bc00',
|
||||
light: '#FFF8DD',
|
||||
},
|
||||
danger: {
|
||||
DEFAULT: '#F1416C',
|
||||
active: '#d9214e',
|
||||
light: '#FFF5F8',
|
||||
},
|
||||
dark: {
|
||||
DEFAULT: '#181C32',
|
||||
active: '#131628',
|
||||
light: '#EFF2F5',
|
||||
},
|
||||
},
|
||||
gridTemplateColumns: {
|
||||
'menu': 'repeat(auto-fit, minmax(1rem, auto))',
|
||||
'a': 'auto',
|
||||
'af': 'auto 1fr',
|
||||
'fa': '1fr auto',
|
||||
'2a': 'auto auto',
|
||||
'3a': 'auto auto auto',
|
||||
},
|
||||
boxShadow: {
|
||||
'all': '0 0 20px rgba(0,0,0,0.08)',
|
||||
},
|
||||
fontFamily: {
|
||||
dana: ['dana', 'sans-serif'],
|
||||
sans: ['Nunito', ...defaultTheme.fontFamily.sans],
|
||||
},
|
||||
},
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,105 @@
|
||||
import defaultTheme from "tailwindcss/defaultTheme";
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
export default {
|
||||
content: [
|
||||
'./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php',
|
||||
'./storage/framework/views/*.php',
|
||||
'./resources/**/*.blade.php',
|
||||
'./resources/**/*.js',
|
||||
'./resources/**/*.vue',
|
||||
],
|
||||
darkMode: 'class',
|
||||
theme: {
|
||||
container: {
|
||||
center: true,
|
||||
},
|
||||
extend: {
|
||||
colors: {
|
||||
primary: {
|
||||
DEFAULT: '#009EF7',
|
||||
active: '#0095e8',
|
||||
light: '#F1FAFF',
|
||||
},
|
||||
light: {
|
||||
DEFAULT: '#F5F8FA',
|
||||
active: '#eff2f5',
|
||||
},
|
||||
secondary: {
|
||||
DEFAULT: '#E4E6EF',
|
||||
active: '#b5b5c3',
|
||||
},
|
||||
success: {
|
||||
DEFAULT: '#50CD89',
|
||||
active: '#47be7e',
|
||||
light: '#E8FFF3',
|
||||
},
|
||||
info: {
|
||||
DEFAULT: '#7239EA',
|
||||
active: '#5014d0',
|
||||
light: '#F8F5FF',
|
||||
},
|
||||
warning: {
|
||||
DEFAULT: '#FFC700',
|
||||
active: '#f1bc00',
|
||||
light: '#FFF8DD',
|
||||
},
|
||||
danger: {
|
||||
100: '#F8DBE0',
|
||||
DEFAULT: '#F1416C',
|
||||
active: '#d9214e',
|
||||
light: '#FFF5F8',
|
||||
},
|
||||
dark: {
|
||||
DEFAULT: '#181C32',
|
||||
active: '#131628',
|
||||
light: '#EFF2F5',
|
||||
},
|
||||
dominant: {
|
||||
50: '#EFEAEA',
|
||||
100: '#CAB4B4',
|
||||
200: '#AF8587',
|
||||
300: '#965457',
|
||||
400: '#7A1419',
|
||||
500: '#800E13',
|
||||
600: '#6a0b10',
|
||||
700: '#550408',
|
||||
800: '#3F0104',
|
||||
900: '#3a0510',
|
||||
DEFAULT: '#800E13',
|
||||
active: '#6a0b10',
|
||||
light: '#FFF5F5',
|
||||
},
|
||||
complement: {
|
||||
50: '#F6F7F9',
|
||||
100: '#DEE3EB',
|
||||
200: '#C8D2E2',
|
||||
300: '#965457',
|
||||
400: '#FF8787',
|
||||
500: '#800E13',
|
||||
600: '#6a0b10',
|
||||
700: '#576989',
|
||||
800: '#3F0104',
|
||||
900: '#2F343D',
|
||||
DEFAULT: '#800E13',
|
||||
active: '#6a0b10',
|
||||
light: '#FFF5F5',
|
||||
},
|
||||
},
|
||||
gridTemplateColumns: {
|
||||
'menu': 'repeat(auto-fit, minmax(1rem, auto))',
|
||||
'a': 'auto',
|
||||
'af': 'auto 1fr',
|
||||
'fa': '1fr auto',
|
||||
'2a': 'auto auto',
|
||||
'3a': 'auto auto auto',
|
||||
},
|
||||
boxShadow: {
|
||||
'all': '0 0 20px rgba(0,0,0,0.08)',
|
||||
},
|
||||
fontFamily: {
|
||||
'yekan-bakh': ['yekanBakh', 'sans-serif'],
|
||||
sans: ['Nunito', ...defaultTheme.fontFamily.sans],
|
||||
},
|
||||
},
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum DocumentPriorityEnum: string
|
||||
{
|
||||
use EnumHasOptions;
|
||||
|
||||
case Medium = 'عادی';
|
||||
case High = 'اورژانسی';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum DocumentStatusEnum: string
|
||||
{
|
||||
use EnumHasOptions;
|
||||
|
||||
case Registered = 'ثبت شده';
|
||||
case InProgress = 'در حال انجام';
|
||||
case Completed = 'تکمیل شده';
|
||||
case Rejected = 'رد شده';
|
||||
case Cancelled = 'لغو شده';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
trait EnumHasOptions
|
||||
{
|
||||
|
||||
public static function options(): array
|
||||
{
|
||||
$options = [];
|
||||
foreach (self::cases() as $case) {
|
||||
$options[$case->value] = __("enums." . class_basename(self::class) . "." . $case->name);
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
public static function values(): array
|
||||
{
|
||||
return array_column(self::cases(), 'value');
|
||||
}
|
||||
|
||||
public static function fromName(string $name): self | null
|
||||
{
|
||||
foreach (self::cases() as $case) {
|
||||
if ($case->name === $name) {
|
||||
return $case;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function keys(): array
|
||||
{
|
||||
return array_column(self::cases(), 'name');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum MediaCollectionEnum: string
|
||||
{
|
||||
use EnumHasOptions;
|
||||
|
||||
case Primary = 'primary';
|
||||
case History = 'history';
|
||||
case Attachments = 'attachments';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum MediaDiskEnum: string
|
||||
{
|
||||
use EnumHasOptions;
|
||||
|
||||
case Public = 'public';
|
||||
case Private = 'private';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum PetGenderEnum: string
|
||||
{
|
||||
use EnumHasOptions;
|
||||
|
||||
case Male = 'نر';
|
||||
case Female = 'ماده';
|
||||
case Unknown = 'نامشخص';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum PetTypeEnum: string
|
||||
{
|
||||
use EnumHasOptions;
|
||||
|
||||
case Dog = 'سگ';
|
||||
case Cat = 'گربه';
|
||||
case Bird = 'پرنده';
|
||||
case Fish = 'ماهی';
|
||||
case Rabbit = 'خرگوش';
|
||||
case Hamster = 'همستر';
|
||||
case GuineaPig = 'خوکچه هندی';
|
||||
case Turtle = 'لاک پشت';
|
||||
case Snake = 'مار';
|
||||
case Lizard = 'مارمولک';
|
||||
case Other = 'سایر';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum ReportStatusEnum: string
|
||||
{
|
||||
use EnumHasOptions;
|
||||
|
||||
case Draft = 'پیشنویس';
|
||||
case InProgress = 'در حال انجام';
|
||||
case Completed = 'تکمیل شده';
|
||||
case Reviewed = 'بررسی شده';
|
||||
case Approved = 'تایید شده';
|
||||
case Rejected = 'رد شده';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
|
||||
enum UserEnum : string {
|
||||
use EnumHasOptions;
|
||||
|
||||
case Supervisor = 'سرپرست';
|
||||
case Vet = 'دانپزشک';
|
||||
case Admin = 'مدیر';
|
||||
case Doctor = 'پزشک';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\Document;
|
||||
use App\Enums\DocumentStatusEnum;
|
||||
use App\Enums\DocumentPriorityEnum;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
|
||||
class DocumentExport implements FromCollection
|
||||
{
|
||||
|
||||
protected $filters;
|
||||
|
||||
public function __construct($filters = [])
|
||||
{
|
||||
$this->filters = $filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
return Document::with(['pet', 'requester'])->when(isset($this->filters['search']) , function ($query){
|
||||
$query->where(function ($q){
|
||||
$q->where('code', 'LIKE', "%{$this->filters['search']}%")
|
||||
->orWhere('id', $this->filters['search'])
|
||||
->orWhereHas('requester', function ($userQuery) {
|
||||
$userQuery->where('fullname', 'LIKE', "%{$this->filters['search']}%")
|
||||
->orWhere('username', 'LIKE', "%{$this->filters['search']}%")
|
||||
->orWhere('email', 'LIKE', "%{$this->filters['search']}%")
|
||||
->orWhere('phone', 'LIKE', "%{$this->filters['search']}%");
|
||||
});
|
||||
});
|
||||
})
|
||||
->when(isset($this->filters['status']), function ($query) {
|
||||
$query->where('status' , DocumentStatusEnum::fromName($this->filters['status'])->value );
|
||||
})
|
||||
->when(isset($this->filters['priority']), function ($query) {
|
||||
$query->where('priority' , DocumentPriorityEnum::fromName($this->filters['priority'])->value);
|
||||
})
|
||||
->when(isset($this->filters['pet']), function ($query) {
|
||||
$query->where('pet_id' , $this->filters['pet']);
|
||||
})
|
||||
->latest()
|
||||
->get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
|
||||
use App\Models\Permission;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
|
||||
class PermissionExport implements FromCollection
|
||||
{
|
||||
|
||||
protected $filters;
|
||||
|
||||
public function __construct($filters = [])
|
||||
{
|
||||
$this->filters = $filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
return Permission::when(isset($request->search) , function ($query){
|
||||
$query->where(function ($q) {
|
||||
$q->where('name', 'LIKE', "%{$this->filters['search']}%")
|
||||
->orWhere('label','LIKE', "%{$this->filters['search']}%");
|
||||
});
|
||||
})
|
||||
->latest()
|
||||
->get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\Pet;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
|
||||
class PetExport implements FromCollection
|
||||
{
|
||||
|
||||
protected $filters;
|
||||
|
||||
public function __construct($filters = [])
|
||||
{
|
||||
$this->filters = $filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
return Pet::when(isset($this->filters['search']) , function ($query){
|
||||
$query->where(function ($q) {
|
||||
$q->where('id', 'LIKE', "%{$this->filters['search']}%")
|
||||
->orWhere('name', 'LIKE', "%{$this->filters['search']}%");
|
||||
});
|
||||
})
|
||||
->when(isset($this->filters['type']) && $this->filters['type'] != 'همه نوع ها', function ($query) {
|
||||
$query->whereIn('type' , $this->filters['type']);
|
||||
})
|
||||
->when(isset($this->filters['gender']) && $this->filters['gender'] != 'همه جنسیت ها', function ($query) {
|
||||
$query->where('gender' , $this->filters['gender']);
|
||||
})
|
||||
->latest()
|
||||
->get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
class RolesExport implements FromCollection
|
||||
{
|
||||
|
||||
protected $filters;
|
||||
|
||||
public function __construct($filters = [])
|
||||
{
|
||||
$this->filters = $filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
return Role::when(isset($request->search) , function ($query){
|
||||
$query->where(function ($q) {
|
||||
$q->where('name', 'LIKE', "%{$this->filters['search']}%")
|
||||
->orWhere('label','LIKE', "%{$this->filters['search']}%");
|
||||
});
|
||||
})
|
||||
->latest()
|
||||
->get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\User;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
|
||||
class UsersExport implements FromCollection
|
||||
{
|
||||
|
||||
protected $filters;
|
||||
|
||||
public function __construct($filters = [])
|
||||
{
|
||||
$this->filters = $filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
return User::when(isset($request->search) , function ($query){
|
||||
$query->where(function ($q) {
|
||||
$q->where('name', 'LIKE', "%{$this->filters['search']}%")
|
||||
->orWhere('email','LIKE', "%{$this->filters['search']}%");
|
||||
});
|
||||
})
|
||||
->when(isset($this->filters['level']) && $this->filters['level'] != 'همه سطح ها', function ($query) {
|
||||
$query->where('level' , $this->filters['level']);
|
||||
})
|
||||
->latest()
|
||||
->get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Enums\UserEnum;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
public function login(Request $request)
|
||||
{
|
||||
if (Auth::check()) {
|
||||
return redirect('/admin/dashboard');
|
||||
}
|
||||
|
||||
return Inertia::admin('Auth/login');
|
||||
}
|
||||
public function loginAction(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'email' => 'required|max:255|email|exists:users,email',
|
||||
'password' => 'required|min:8|max:255',
|
||||
]);
|
||||
|
||||
$data = $request->only(['email' , 'password']);
|
||||
|
||||
|
||||
|
||||
if (!Auth::attempt($data , $request->input('remember'))){
|
||||
return response()->json([
|
||||
'errors'=> [
|
||||
'email' => ['ایمیل و کلمه عبور شما با هم مطابقت ندارن']
|
||||
]
|
||||
] , 401);
|
||||
}
|
||||
|
||||
$request->session()->regenerate();
|
||||
return request()->json([
|
||||
'message'
|
||||
] , 200);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function register(Request $request)
|
||||
{
|
||||
if (Auth::check()) {
|
||||
return redirect('/');
|
||||
}
|
||||
return Inertia::admin('Auth/register');
|
||||
}
|
||||
|
||||
public function registerAction(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'name' => 'required|min:2|max:255',
|
||||
'email' => 'required|max:255|email|unique:users,email',
|
||||
'password' => 'required|min:8|max:255|confirmed',
|
||||
]);
|
||||
|
||||
$user = User::create([
|
||||
'name' => $request->name,
|
||||
'email' => $request->email,
|
||||
'password' => Hash::make($request->password),
|
||||
'level' => UserEnum::Admin->value,
|
||||
]);
|
||||
Auth::login($user);
|
||||
return redirect('/admin/dashboard');
|
||||
}
|
||||
public function logout(){
|
||||
Auth::logout();
|
||||
return redirect('/admin/auth/login');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,263 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Document;
|
||||
use App\Http\Resources\Admin\DocumentResource;
|
||||
use App\Http\Resources\Admin\DocumentEditFormResource;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Enums\DocumentStatusEnum;
|
||||
use App\Enums\DocumentPriorityEnum;
|
||||
use Inertia\Inertia;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Exports\DocumentExport;
|
||||
use App\Http\Resources\Admin\PetResource;
|
||||
use App\Models\Pet;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use App\Http\Requests\Admin\DocumentRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Services\FileStorageService;
|
||||
use App\Enums\MediaDiskEnum;
|
||||
|
||||
class DocumentController extends Controller
|
||||
{
|
||||
use AuthorizesRequests;
|
||||
|
||||
protected FileStorageService $fileStorageService;
|
||||
|
||||
public function __construct(FileStorageService $fileStorageService)
|
||||
{
|
||||
$this->fileStorageService = $fileStorageService;
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$this->authorize('documents.index');
|
||||
|
||||
$lists = Document::with(['pet', 'requester'])
|
||||
->when(isset($request->search) , function ($query) use ($request){
|
||||
$query->where(function ($q) use ($request) {
|
||||
$q->where('code', 'LIKE', "%{$request->search}%")
|
||||
->orWhere('id', $request->search)
|
||||
->orWhereHas('requester', function ($userQuery) use ($request) {
|
||||
$userQuery->where('fullname', 'LIKE', "%{$request->search}%")
|
||||
->orWhere('username', 'LIKE', "%{$request->search}%")
|
||||
->orWhere('email', 'LIKE', "%{$request->search}%")
|
||||
->orWhere('phone', 'LIKE', "%{$request->search}%");
|
||||
});
|
||||
});
|
||||
})
|
||||
->when(isset($request->status), function ($query) use ($request) {
|
||||
$query->where('status' , DocumentStatusEnum::fromName($request->status)->value );
|
||||
})
|
||||
->when(isset($request->priority), function ($query) use ($request) {
|
||||
$query->where('priority' , DocumentPriorityEnum::fromName($request->priority)->value);
|
||||
})
|
||||
->when(isset($request->pet), function ($query) use ($request) {
|
||||
$query->where('pet_id' , $request->pet);
|
||||
})
|
||||
->latest()
|
||||
->paginate(20)
|
||||
->withQueryString()
|
||||
->onEachSide(1);
|
||||
|
||||
$documents = DocumentResource::collection($lists);
|
||||
|
||||
|
||||
return Inertia::admin('Documents/index', [
|
||||
'documents' => $documents,
|
||||
'search' => $request->search,
|
||||
'status' => $request->status,
|
||||
'priority' => $request->priority,
|
||||
'pet' => $request->pet,
|
||||
'permissions_edit' => auth()->user()->can('documents.edit') ? false : true,
|
||||
'permissions_delete' => auth()->user()->can('documents.delete') ? false : true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->authorize('documents.create');
|
||||
|
||||
$pets = PetResource::collection(Pet::latest()->take(20)->get())->map(function($pet) {
|
||||
return [
|
||||
'label' => $pet->name,
|
||||
'value' => $pet->id
|
||||
];
|
||||
});
|
||||
|
||||
return Inertia::admin('Documents/create_and_edit', [
|
||||
'pets' => $pets,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function store(DocumentRequest $request)
|
||||
{
|
||||
$this->authorize('documents.create');
|
||||
|
||||
$document = Document::create(
|
||||
[
|
||||
'status' => DocumentStatusEnum::fromName($request->status)->value,
|
||||
'priority' => DocumentPriorityEnum::fromName($request->priority)->value,
|
||||
'note' => $request->note,
|
||||
'modality' => $request->modality,
|
||||
'pet_id' => $request->pet_id,
|
||||
'requester_id' => Auth::id(),
|
||||
'submitted_at' => $request->submitted_at,
|
||||
'scan_date' => $request->scan_date,
|
||||
'processing_deadline' => $request->processing_deadline,
|
||||
]
|
||||
);
|
||||
|
||||
if ($request->has('primary_files')) {
|
||||
$primaryFileIds = $request->primary_files ?? [];
|
||||
if (!empty($primaryFileIds)) {
|
||||
$document->media()->attach($primaryFileIds, ['collection' => 'primary']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->has('history_files')) {
|
||||
$historyFileIds = $request->history_files ?? [];
|
||||
if (!empty($historyFileIds)) {
|
||||
$document->media()->attach($historyFileIds, ['collection' => 'history']);
|
||||
}
|
||||
}
|
||||
|
||||
session()->flash('success', 'پرونده با موفقیت ثبت شد');
|
||||
return response(null , 200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function show(Document $document)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
public function edit(Document $document)
|
||||
{
|
||||
$this->authorize('documents.edit');
|
||||
|
||||
$document->load(['primaryFiles', 'historyFiles', 'requester']);
|
||||
|
||||
$pets = PetResource::collection(Pet::latest()->take(20)->get())->map(function($pet) {
|
||||
return [
|
||||
'label' => $pet->name,
|
||||
'value' => $pet->id
|
||||
];
|
||||
});
|
||||
|
||||
return Inertia::admin('Documents/create_and_edit', [
|
||||
'document' => DocumentEditFormResource::make($document)->resolve(),
|
||||
'is_edit' => true,
|
||||
'pets' => $pets,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function update(DocumentRequest $request, Document $document)
|
||||
{
|
||||
$this->authorize('documents.edit');
|
||||
|
||||
$document->update(
|
||||
[
|
||||
'status' => DocumentStatusEnum::fromName($request->status)->value,
|
||||
'priority' => DocumentPriorityEnum::fromName($request->priority)->value,
|
||||
'note' => $request->note,
|
||||
'modality' => $request->modality,
|
||||
'pet_id' => $request->pet_id,
|
||||
'requester_id' => Auth::id(),
|
||||
'submitted_at' => $request->submitted_at,
|
||||
'scan_date' => $request->scan_date,
|
||||
'processing_deadline' => $request->processing_deadline,
|
||||
]
|
||||
);
|
||||
|
||||
if ($request->has('primary_files')) {
|
||||
$primaryFileIds = $request->primary_files ?? [];
|
||||
$document->media()->wherePivot('collection', 'primary')->detach();
|
||||
if (!empty($primaryFileIds)) {
|
||||
$document->media()->attach($primaryFileIds, ['collection' => 'primary']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->has('history_files')) {
|
||||
$historyFileIds = $request->history_files ?? [];
|
||||
$document->media()->wherePivot('collection', 'history')->detach();
|
||||
if (!empty($historyFileIds)) {
|
||||
$document->media()->attach($historyFileIds, ['collection' => 'history']);
|
||||
}
|
||||
}
|
||||
|
||||
session()->flash('success', 'پرونده با موفقیت بروزرسانی شد');
|
||||
return response(null , 200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function destroy(Document $document)
|
||||
{
|
||||
$this->authorize('documents.delete');
|
||||
|
||||
$document->delete();
|
||||
session()->flash('success', 'مدرک مورد نظر با موفقیت حذف شد.');
|
||||
return response(null , 200);
|
||||
}
|
||||
|
||||
public function exportData(Request $request)
|
||||
{
|
||||
$filters = $request->only(['status', 'priority', 'pet' , 'search']);
|
||||
return Excel::download(new DocumentExport($filters), 'documents.xlsx');
|
||||
}
|
||||
|
||||
public function uploadFile(Request $request)
|
||||
{
|
||||
$this->authorize('documents.create');
|
||||
|
||||
$request->validate([
|
||||
'file' => 'required|file|max:20480',
|
||||
]);
|
||||
|
||||
$file = $request->file('file');
|
||||
$medium = $this->fileStorageService->storeFile($file, MediaDiskEnum::Private->value, 'documents');
|
||||
|
||||
return response()->json($medium);
|
||||
}
|
||||
|
||||
public function getOptions(Request $request)
|
||||
{
|
||||
$this->authorize('documents.index');
|
||||
|
||||
|
||||
$lists = Document::with(['pet', 'requester'])
|
||||
->when(isset($request->search) && !empty($request->search), function ($query) use ($request){
|
||||
$query->where(function ($q) use ($request) {
|
||||
$q->where('code', 'LIKE', "%{$request->search}%")
|
||||
->orWhere('id', $request->search)
|
||||
->orWhereHas('requester', function ($userQuery) use ($request) {
|
||||
$userQuery->where('fullname', 'LIKE', "%{$request->search}%")
|
||||
->orWhere('username', 'LIKE', "%{$request->search}%")
|
||||
->orWhere('email', 'LIKE', "%{$request->search}%")
|
||||
->orWhere('phone', 'LIKE', "%{$request->search}%");
|
||||
});
|
||||
});
|
||||
})
|
||||
->latest()
|
||||
->take(20)
|
||||
->get(['id', 'code', 'modality']);
|
||||
|
||||
$options = $lists->map(function ($document) {
|
||||
return [
|
||||
'label' => "پرونده {$document->code} - {$document->modality}",
|
||||
'value' => $document->id
|
||||
];
|
||||
});
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $options
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Medium;
|
||||
use App\Services\FileStorageService;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class MediumController extends Controller
|
||||
{
|
||||
protected FileStorageService $fileStorageService;
|
||||
|
||||
public function __construct(FileStorageService $fileStorageService)
|
||||
{
|
||||
$this->fileStorageService = $fileStorageService;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$medium = Medium::latest()->paginate(15);
|
||||
return Inertia::admin('Medium', [
|
||||
'medium' => $medium
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'file' => 'required|max:20240',
|
||||
]);
|
||||
|
||||
$file = $request->file('file');
|
||||
|
||||
$fileRecord = $this->fileStorageService->storeFile($file, 'public', 'media');
|
||||
|
||||
return response()->json($fileRecord);
|
||||
}
|
||||
|
||||
public function destroy(Medium $media)
|
||||
{
|
||||
$this->fileStorageService->deleteMedium($media);
|
||||
$media->delete();
|
||||
return redirect()->back()->with('success', 'فایل مورد نظر با موفقیت حذف شد.');
|
||||
}
|
||||
|
||||
public function getMedium()
|
||||
{
|
||||
$medium = Medium::latest()->paginate(15);
|
||||
return response()->json($medium);
|
||||
}
|
||||
|
||||
public function download(Medium $media)
|
||||
{
|
||||
return $this->fileStorageService->downloadFile($media);
|
||||
}
|
||||
|
||||
public function serve(Medium $media)
|
||||
{
|
||||
return $this->fileStorageService->serveFile($media);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class PanelController extends Controller
|
||||
{
|
||||
public function index(){
|
||||
return Inertia::admin('index');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Pet;
|
||||
use App\Http\Resources\Admin\PetResource;
|
||||
use App\Http\Requests\Admin\PetRequest;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Inertia\Inertia;
|
||||
use App\Exports\PetExport;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class PetController extends Controller
|
||||
{
|
||||
use AuthorizesRequests;
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$this->authorize('pets.index');
|
||||
|
||||
$lists = Pet::with(['owner'])
|
||||
->when(isset($request->search) , function ($query) use ($request){
|
||||
$query->where(function ($q) use ($request) {
|
||||
$q->where('name', 'LIKE', "%{$request->search}%")
|
||||
->orWhere('id', $request->search);
|
||||
});
|
||||
})
|
||||
->when(isset($request->type) && $request->type != 'همه نوع ها', function ($query) use ($request) {
|
||||
$query->whereIn('type' , $request->type);
|
||||
})
|
||||
->when(isset($request->gender) && $request->gender != 'همه جنسیت ها', function ($query) use ($request) {
|
||||
$query->where('gender' , $request->gender);
|
||||
})
|
||||
->latest()
|
||||
->paginate(20)
|
||||
->withQueryString()
|
||||
->onEachSide(1);
|
||||
|
||||
$pets = PetResource::collection($lists);
|
||||
|
||||
return Inertia::admin('Pets/index', [
|
||||
'pets' => $pets,
|
||||
'search' => $request->search,
|
||||
'type' => $request->type,
|
||||
'gender' => $request->gender,
|
||||
'permissions_edit' => auth()->user()->can('pets.edit') ? false : true,
|
||||
'permissions_delete' => auth()->user()->can('pets.delete') ? false : true,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->authorize('pets.create');
|
||||
return Inertia::admin('Pets/create_and_edit');
|
||||
}
|
||||
|
||||
|
||||
public function store(PetRequest $request)
|
||||
{
|
||||
$this->authorize('pets.create');
|
||||
auth()->user()->pets()->create([
|
||||
'name' => $request->name,
|
||||
'type' => $request->type,
|
||||
'gender' => $request->gender,
|
||||
'breed' => $request->breed,
|
||||
'weight' => $request->weight,
|
||||
'sterilized' => $request->sterilized,
|
||||
'birthday' => $request->birthday,
|
||||
]);
|
||||
|
||||
session()->flash('success', 'کیس با موفقیت ثبت شد');
|
||||
return response(null , 200);
|
||||
}
|
||||
|
||||
|
||||
public function show(Pet $pet)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
public function edit(Pet $pet)
|
||||
{
|
||||
$this->authorize('pets.edit');
|
||||
return Inertia::admin('Pets/create_and_edit', [
|
||||
'pet' => PetResource::make($pet)->resource,
|
||||
'is_edit' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function update(PetRequest $request, Pet $pet)
|
||||
{
|
||||
$this->authorize('pets.edit');
|
||||
$pet->update([
|
||||
'name' => $request->name,
|
||||
'type' => $request->type,
|
||||
'gender' => $request->gender,
|
||||
'breed' => $request->breed,
|
||||
'weight' => $request->weight,
|
||||
'sterilized' => $request->sterilized,
|
||||
'birthday' => $request->birthday,
|
||||
]);
|
||||
|
||||
session()->flash('success', 'کیس با موفقیت بروزرسانی شد');
|
||||
return response(null , 200);
|
||||
}
|
||||
|
||||
|
||||
public function destroy(Pet $pet)
|
||||
{
|
||||
$this->authorize('pets.delete');
|
||||
$pet->delete();
|
||||
|
||||
session()->flash('success', 'کیس با موفقیت حذف شد');
|
||||
return response(null , 200);
|
||||
}
|
||||
|
||||
public function bulkDelete(Request $request)
|
||||
{
|
||||
$this->authorize('pets.delete');
|
||||
Pet::destroy($request->ids);
|
||||
session()->flash('success', 'کیس های مورد نظر با موفقیت حذف شدند.');
|
||||
return response(null , 200);
|
||||
}
|
||||
|
||||
public function exportData(Request $request)
|
||||
{
|
||||
$filters = $request->only(['type', 'gender', 'search']);
|
||||
return Excel::download(new PetExport($filters), 'pets.xlsx');
|
||||
}
|
||||
|
||||
public function getOptions(Request $request)
|
||||
{
|
||||
$this->authorize('pets.index');
|
||||
|
||||
$lists = Pet::when(isset($request->search) , function ($query) use ($request){
|
||||
$query->where('name', 'LIKE', "%{$request->search}%")
|
||||
->orWhere('id', $request->search);
|
||||
})
|
||||
->latest()
|
||||
->take(20)
|
||||
->get(['id', 'name']);
|
||||
|
||||
$options = $lists->map(function ($pet) {
|
||||
return [
|
||||
'label' => $pet->name,
|
||||
'value' => $pet->id
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $options
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\Admin\ReportResource;
|
||||
use App\Models\Report;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use App\Http\Requests\Admin\ReportRequest;
|
||||
use App\Enums\ReportStatusEnum;
|
||||
|
||||
class ReportController extends Controller
|
||||
{
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$lists = Report::with(['document', 'doctor'])
|
||||
->when(isset($request->search) , function ($query) use ($request){
|
||||
$query->where(function ($q) use ($request) {
|
||||
$q->where('id', 'LIKE', "%{$request->search}%")
|
||||
->orWhereHas('document', function ($documentQuery) use ($request) {
|
||||
$documentQuery->where('code', 'LIKE', "%{$request->search}%");
|
||||
})
|
||||
->orWhereHas('doctor', function ($userQuery) use ($request) {
|
||||
$userQuery->where('fullname', 'LIKE', "%{$request->search}%")
|
||||
->orWhere('username', 'LIKE', "%{$request->search}%")
|
||||
->orWhere('email', 'LIKE', "%{$request->search}%");
|
||||
});
|
||||
});
|
||||
})
|
||||
->when(isset($request->status) && $request->status != 'همه وضعیت ها', function ($query) use ($request) {
|
||||
$query->where('status' , $request->status);
|
||||
})
|
||||
->latest()
|
||||
->paginate(20)
|
||||
->withQueryString()
|
||||
->onEachSide(1);
|
||||
|
||||
$reports = ReportResource::collection($lists);
|
||||
|
||||
return Inertia::admin('Reports/index', [
|
||||
'reports' => $reports,
|
||||
'search' => $request->search,
|
||||
'status' => $request->status,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
public function store(ReportRequest $request)
|
||||
{
|
||||
Report::create([
|
||||
'document_id' => $request->document_id,
|
||||
'doctor_id' => $request->doctor_id,
|
||||
'status' => ReportStatusEnum::fromName($request->status)->value,
|
||||
'body' => $request->body,
|
||||
'submitted_at' => $request->submitted_at,
|
||||
]);
|
||||
|
||||
session()->flash('success', 'گزارش با موفقیت ثبت شد');
|
||||
return response(null , 200);
|
||||
}
|
||||
|
||||
|
||||
public function show(Report $report)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
public function edit(Report $report)
|
||||
{
|
||||
return Inertia::admin('Reports/edit', [
|
||||
'report' => $report,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function update(ReportRequest $request, Report $report)
|
||||
{
|
||||
$report->update([
|
||||
'document_id' => $request->document_id,
|
||||
'doctor_id' => $request->doctor_id,
|
||||
'status' => ReportStatusEnum::fromName($request->status)->value,
|
||||
'body' => $request->body,
|
||||
'submitted_at' => $request->submitted_at,
|
||||
]);
|
||||
|
||||
session()->flash('success', 'گزارش با موفقیت ویرایش شد');
|
||||
return response(null , 200);
|
||||
}
|
||||
|
||||
|
||||
public function destroy(Report $report)
|
||||
{
|
||||
$report->delete();
|
||||
session()->flash('success', 'گزارش با موفقیت حذف شد');
|
||||
return response(null , 200);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Role;
|
||||
|
||||
use App\Exports\PermissionExport;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\Admin\PermissionResource;
|
||||
use App\Models\Permission;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class PermissionController extends Controller
|
||||
{
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$permissions = Permission::when(isset($request->search) , function ($query) use ($request){
|
||||
$query->where(function ($q) use ($request) {
|
||||
$q->where('name', 'LIKE', "%{$request->search}%")
|
||||
->orWhere('label','LIKE', "%{$request->search}%");
|
||||
});
|
||||
})
|
||||
->latest()
|
||||
->paginate(20)
|
||||
->withQueryString()
|
||||
->onEachSide(1);
|
||||
|
||||
return Inertia::admin('Permissions/index', [
|
||||
'permissions' => PermissionResource::collection($permissions),
|
||||
'search' => $request->search,
|
||||
]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$permissions = Permission::latest()->where('parent_id' , 0)->get();
|
||||
return Inertia::admin('Permissions/create_and_edit', [
|
||||
'permissions' => PermissionResource::collection($permissions),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$valid = $request->validate([
|
||||
'name' => ['required' , 'max:255'],
|
||||
'label' => ['required' , 'max:255'],
|
||||
]);
|
||||
|
||||
Permission::create([
|
||||
'name' => $valid['name'],
|
||||
'label' => $valid['label'],
|
||||
'parent_id' => $request->parent_id ?? 0,
|
||||
]);
|
||||
|
||||
session()->flash('success', 'سطح جدید با موفقیت ایجاد شد.');
|
||||
|
||||
return response(null , 201);
|
||||
}
|
||||
|
||||
public function bulkDelete(Request $request)
|
||||
{
|
||||
Permission::destroy($request->ids);
|
||||
session()->flash('success', 'سطح های مورد نظر با موفقیت حذف شدند.');
|
||||
return response(null , 200);
|
||||
}
|
||||
|
||||
public function exportData(Request $request)
|
||||
{
|
||||
$filters = $request->only(['search']);
|
||||
return Excel::download(new PermissionExport($filters), 'permissions.xlsx');
|
||||
}
|
||||
|
||||
public function show(Permission $permission)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function edit(Permission $permission)
|
||||
{
|
||||
$permissions = Permission::latest()->where('parent_id' , 0)->get();
|
||||
return Inertia::admin('Permissions/create_and_edit', [
|
||||
'permission' => [
|
||||
'id' => $permission->id,
|
||||
'name' => $permission->name,
|
||||
'label' => $permission->label,
|
||||
'parent_id' => $permission->parent_id,
|
||||
'created_at' => optional($permission->created_at)->format('Y-m-d H:i:s'),
|
||||
],
|
||||
'permissions' => PermissionResource::collection($permissions),
|
||||
'is_edit' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, Permission $permission)
|
||||
{
|
||||
$valid = $request->validate([
|
||||
'name' => ['required' , 'max:255'],
|
||||
'label' => ['required' , 'max:255'],
|
||||
]);
|
||||
|
||||
$permission->update([
|
||||
'name' => $valid['name'],
|
||||
'label' => $valid['label'],
|
||||
'parent_id' => $request->parent_id ?? 0,
|
||||
]);
|
||||
|
||||
session()->flash('success', 'سطح مورد نظر با موفقیت بروزرسانی شد.');
|
||||
return response(null , 200);
|
||||
}
|
||||
|
||||
public function destroy(Permission $permission)
|
||||
{
|
||||
$permission->delete();
|
||||
session()->flash('success', 'سطح مورد نظر با موفقیت حذف شد.');
|
||||
return response(null , 200);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\Role;
|
||||
|
||||
use App\Exports\RolesExport;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\Admin\RoleResource;
|
||||
use App\Models\Permission;
|
||||
use Inertia\Inertia;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class RoleController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$roles = Role::when(isset($request->search) , function ($query) use ($request){
|
||||
$query->where(function ($q) use ($request) {
|
||||
$q->where('name', 'LIKE', "%{$request->search}%")
|
||||
->orWhere('label','LIKE', "%{$request->search}%");
|
||||
});
|
||||
})
|
||||
->latest()
|
||||
->paginate(20)
|
||||
->withQueryString()
|
||||
->onEachSide(1);
|
||||
|
||||
return Inertia::admin('Roles/index', [
|
||||
'roles' => RoleResource::collection($roles),
|
||||
'search' => $request->search,
|
||||
]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$permissions = Permission::latest()->where('parent_id' , 0)->with(['permissionsParent'])->get();
|
||||
return Inertia::admin('Roles/create_and_edit', [
|
||||
'permissions' => $permissions,
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$valid = $request->validate([
|
||||
'name' => ['required' , 'max:255'],
|
||||
'label' => ['required' , 'max:255'],
|
||||
]);
|
||||
|
||||
$role = Role::create([
|
||||
'name' => $valid['name'],
|
||||
'label' => $valid['label'],
|
||||
]);
|
||||
|
||||
if ($request->selectedPermissionIds) {
|
||||
$ids = collect($request->selectedPermissionIds)
|
||||
->flatten()
|
||||
->unique()
|
||||
->toArray();
|
||||
$role->syncPermissions($ids);
|
||||
}
|
||||
|
||||
|
||||
session()->flash('success', 'مقام جدید با موفقیت ایجاد شد.');
|
||||
|
||||
return response(null , 201);
|
||||
}
|
||||
|
||||
public function bulkDelete(Request $request)
|
||||
{
|
||||
Role::destroy($request->ids);
|
||||
|
||||
session()->flash('success', 'مقام های مورد نظر با موفقیت حذف شدند.');
|
||||
return response(null , 200);
|
||||
}
|
||||
|
||||
public function exportData(Request $request)
|
||||
{
|
||||
$filters = $request->only(['search']);
|
||||
return Excel::download(new RolesExport($filters), 'roles.xlsx');
|
||||
}
|
||||
|
||||
public function show(Role $role)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function edit(Role $role)
|
||||
{
|
||||
$permissions = Permission::latest()
|
||||
->where('parent_id', 0)
|
||||
->with(['permissionsParent'])
|
||||
->get();
|
||||
|
||||
$selectedPermissionIds = $role->permissions
|
||||
->groupBy(function($permission) {
|
||||
return $permission->parent_id ?: $permission->id;
|
||||
})
|
||||
->map(function($group) {
|
||||
return $group->pluck('id')->toArray();
|
||||
})
|
||||
->toArray();
|
||||
|
||||
|
||||
return Inertia::admin('Roles/create_and_edit', [
|
||||
'role' => [
|
||||
'id' => $role->id,
|
||||
'name' => $role->name,
|
||||
'label' => $role->label,
|
||||
'permissions' => $selectedPermissionIds,
|
||||
'created_at' => optional($role->created_at)->format('Y-m-d H:i:s'),
|
||||
],
|
||||
'permissions' => $permissions,
|
||||
'is_edit' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, Role $role)
|
||||
{
|
||||
$valid = $request->validate([
|
||||
'name' => ['required' , 'max:255'],
|
||||
'label' => ['required' , 'max:255'],
|
||||
]);
|
||||
|
||||
$role->update([
|
||||
'name' => $valid['name'],
|
||||
'label' => $valid['label'],
|
||||
]);
|
||||
|
||||
if ($request->selectedPermissionIds) {
|
||||
$ids = collect($request->selectedPermissionIds)
|
||||
->flatten()
|
||||
->unique()
|
||||
->toArray();
|
||||
$role->syncPermissions($ids);
|
||||
}
|
||||
|
||||
session()->flash('success', 'مقام مورد نظر با موفقیت بروزرسانی شد.');
|
||||
return response(null , 200);
|
||||
}
|
||||
|
||||
public function destroy(Role $role)
|
||||
{
|
||||
$role->delete();
|
||||
session()->flash('success', 'مقام مورد نظر با موفقیت حذف شد.');
|
||||
return response(null , 200);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\SettingProfileRequest;
|
||||
use App\Http\Resources\Admin\SessionsIndexResource;
|
||||
use App\Models\Medium;
|
||||
use App\Models\Session;
|
||||
use App\Models\User;
|
||||
use App\Services\FileStorageService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class SettingUserController extends Controller
|
||||
{
|
||||
protected FileStorageService $fileStorageService;
|
||||
|
||||
public function __construct(FileStorageService $fileStorageService)
|
||||
{
|
||||
$this->fileStorageService = $fileStorageService;
|
||||
}
|
||||
|
||||
public function profile()
|
||||
{
|
||||
return Inertia::admin('Settings/User/Profile', []);
|
||||
}
|
||||
public function updateData(SettingProfileRequest $request , User $user)
|
||||
{
|
||||
if (Auth::id() !== $request->route('user')->id) {
|
||||
abort(403);
|
||||
}
|
||||
$user->update($request->validated());
|
||||
return response($user, 200);
|
||||
}
|
||||
public function uploadAvatar(Request $request){
|
||||
$request->validate([
|
||||
'file' => 'required|mimes:png,jpg,jpeg,gif|max:10240'
|
||||
]);
|
||||
|
||||
$user = Auth::user();
|
||||
|
||||
if (!empty($user->profile_url)) {
|
||||
if ($file = Medium::where('url', $user->profile_url)->first()) {
|
||||
$this->fileStorageService->deleteMedium($file);
|
||||
}
|
||||
}
|
||||
|
||||
$file = $request->file('file');
|
||||
$fileRecord = $this->fileStorageService->storeFile($file, 'public', 'profile');
|
||||
|
||||
$user->update(['profile_url' => $fileRecord->url]);
|
||||
|
||||
return response(['profile_url' => $fileRecord->url], 200);
|
||||
}
|
||||
|
||||
public function security()
|
||||
{
|
||||
return Inertia::admin('Settings/User/Security', []);
|
||||
}
|
||||
|
||||
public function sessions()
|
||||
{
|
||||
$userSessions = Session::where('user_id', Auth::id())->get();
|
||||
$sessions = SessionsIndexResource::collection($userSessions)->toArray(request());
|
||||
return Inertia::admin('Settings/User/Sessions', compact('sessions'));
|
||||
}
|
||||
public function deleteSession(Session $session){
|
||||
$state = Session::where([
|
||||
'id' => $session->id,
|
||||
'user_id' => Auth::id(),
|
||||
])->delete();
|
||||
|
||||
if ($state){
|
||||
session()->flash('success', 'نشست مورد نظر حذف شد');
|
||||
return response(null, 200);
|
||||
}else{
|
||||
session()->flash('error', 'نشست مورد نظر یافت نشد!');
|
||||
return response(null, 400);
|
||||
}
|
||||
}
|
||||
public function bulkDelete(Request $request)
|
||||
{
|
||||
Session::whereIn('id', $request->ids)->delete();
|
||||
session()->flash('success', 'نشست های مورد نظر با موفقیت حذف شدند.');
|
||||
return response(null, 200);
|
||||
}
|
||||
|
||||
public function changePassword(Request $request)
|
||||
{
|
||||
$fields = $request->validate([
|
||||
'password' => 'required|min:8',
|
||||
'newPassword' => 'required|min:8|confirmed',
|
||||
]);
|
||||
$user = Auth::user();
|
||||
|
||||
if (!Hash::check($fields['password'], $user->password)){
|
||||
return response()->json([
|
||||
'message' => 'پسورد فعلی نادرست است'
|
||||
], 401);
|
||||
}
|
||||
|
||||
$user->update([
|
||||
'password' => Hash::make($fields['newPassword']),
|
||||
]);
|
||||
|
||||
session()->flash('success', 'تغییر کلمه عبور با موفقیت انجام شد.');
|
||||
return response(null, 200);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Exports\UsersExport;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\UserRequest;
|
||||
use App\Http\Resources\Admin\UserResource;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Inertia\Inertia;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use App\Enums\UserEnum;
|
||||
|
||||
class UserController extends Controller
|
||||
{
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$lists = User::when(isset($request->search) , function ($query) use ($request){
|
||||
$query->where(function ($q) use ($request) {
|
||||
$q->where('username', 'LIKE', "%{$request->search}%")
|
||||
->orWhere('phone', 'LIKE', "%{$request->search}%")
|
||||
->orWhere('fullname', 'LIKE', "%{$request->search}%")
|
||||
->orWhere('email','LIKE', "%{$request->search}%");
|
||||
});
|
||||
})
|
||||
->when(isset($request->level) && $request->level != 'همه سطح ها', function ($query) use ($request) {
|
||||
$query->where('level' , $request->level);
|
||||
})
|
||||
->latest()
|
||||
->paginate(20)
|
||||
->withQueryString()
|
||||
->onEachSide(1);
|
||||
$users = UserResource::collection($lists);
|
||||
|
||||
|
||||
return Inertia::admin('Users/index', [
|
||||
'users' => $users,
|
||||
'search' => $request->search,
|
||||
'level' => $request->level,
|
||||
]);
|
||||
}
|
||||
|
||||
public function bulkDelete(Request $request)
|
||||
{
|
||||
User::destroy($request->ids);
|
||||
session()->flash('success', 'کاربر های مورد نظر با موفقیت حذف شدند.');
|
||||
return response(null , 200);
|
||||
}
|
||||
|
||||
public function exportData(Request $request)
|
||||
{
|
||||
$filters = $request->only(['level', 'search']);
|
||||
return Excel::download(new UsersExport($filters), 'users.xlsx');
|
||||
}
|
||||
|
||||
|
||||
public function create()
|
||||
{
|
||||
$roles = Role::latest()->get();
|
||||
return Inertia::admin('Users/create_and_edit', [
|
||||
'roles' => $roles,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function store(UserRequest $request)
|
||||
{
|
||||
|
||||
$user = User::create([
|
||||
'username' => $request->username,
|
||||
'email' => $request->email,
|
||||
'phone' => $request->phone,
|
||||
'fullname' => $request->fullname,
|
||||
'password' => Hash::make($request->password),
|
||||
'level' => $request->level,
|
||||
'national_code' => $request->national_code,
|
||||
'profile_url' => $request->image ? $request->image['url'] : '',
|
||||
'created_at' => Carbon::parse($request->datetime),
|
||||
'updated_at' => Carbon::parse($request->datetime),
|
||||
]);
|
||||
|
||||
if ($request->role){
|
||||
$user->assignRole($request->role);
|
||||
}
|
||||
|
||||
session()->flash('success', 'کاربر جدید با موفقیت ایجاد شد.');
|
||||
|
||||
return response(null , 200);
|
||||
}
|
||||
|
||||
|
||||
public function show(User $user)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
|
||||
public function edit(User $user)
|
||||
{
|
||||
$roles = Role::latest()->get();
|
||||
return Inertia::admin('Users/create_and_edit', [
|
||||
'user' => [
|
||||
'id' => $user->id,
|
||||
'username' => $user->username,
|
||||
'phone' => $user->phone,
|
||||
'fullname' => $user->fullname,
|
||||
'email' => $user->email,
|
||||
'level' => $user->level,
|
||||
'role' => $user->roles()->pluck('id')->toArray(),
|
||||
'profile_url' => $user->profile_url,
|
||||
'created_at' => optional($user->created_at)->format('Y-m-d H:i:s'),
|
||||
],
|
||||
'roles' => $roles,
|
||||
'is_edit' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function update(UserRequest $request, User $user)
|
||||
{
|
||||
|
||||
$user->update([
|
||||
'username' => $request->username,
|
||||
'email' => $request->email,
|
||||
'phone' => $request->phone,
|
||||
'fullname' => $request->fullname,
|
||||
'password' => $request->password ? Hash::make($request->password) : $user->password,
|
||||
'profile_url' => $request->image ? $request->image['url'] : '',
|
||||
'level' => $request->level,
|
||||
'national_code' => $request->national_code,
|
||||
'created_at' => Carbon::parse($request->datetime),
|
||||
'updated_at' => Carbon::parse($request->datetime),
|
||||
]);
|
||||
|
||||
if ($request->role) {
|
||||
$user->syncRoles($request->role);
|
||||
} else {
|
||||
$user->syncRoles([]);
|
||||
}
|
||||
|
||||
session()->flash('success', 'کاربر با موفقیت بروزرسانی شد.');
|
||||
return response(null , 200);
|
||||
}
|
||||
|
||||
|
||||
public function destroy(User $user)
|
||||
{
|
||||
$user->delete();
|
||||
session()->flash('success', 'کاربر مورد نظر با موفقیت حذف شد.');
|
||||
return response(null , 200);
|
||||
}
|
||||
|
||||
public function getDoctorsOptions(Request $request)
|
||||
{
|
||||
$lists = User::where('level', UserEnum::Doctor->value)
|
||||
->when(isset($request->search) && !empty($request->search), function ($query) use ($request) {
|
||||
$query->where(function ($q) use ($request) {
|
||||
$q->where('fullname', 'LIKE', "%{$request->search}%")
|
||||
->orWhere('username', 'LIKE', "%{$request->search}%")
|
||||
->orWhere('email', 'LIKE', "%{$request->search}%");
|
||||
});
|
||||
})
|
||||
->latest()
|
||||
->take(20)
|
||||
->get(['id', 'fullname', 'username', 'email']);
|
||||
|
||||
$options = $lists->map(function ($user) {
|
||||
return [
|
||||
'label' => $user->fullname,
|
||||
'value' => $user->id
|
||||
];
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => $options
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Enums\UserEnum;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Requests\Client\Auth\UserRegistrationRequest;
|
||||
use App\Http\Requests\Client\Auth\VerifyOtpRequest;
|
||||
use App\Services\Auth\AuthService;
|
||||
use App\Services\Auth\OtpService;
|
||||
use App\Services\Auth\RegistrationService;
|
||||
use Inertia\Inertia;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
private AuthService $authService;
|
||||
private OtpService $otpService;
|
||||
private RegistrationService $registrationService;
|
||||
|
||||
|
||||
public function __construct(AuthService $authService, OtpService $otpService, RegistrationService $registrationService)
|
||||
{
|
||||
$this->authService = $authService;
|
||||
$this->otpService = $otpService;
|
||||
$this->registrationService = $registrationService;
|
||||
}
|
||||
|
||||
public function phone()
|
||||
{
|
||||
return Inertia::client('Auth/Phone');
|
||||
}
|
||||
|
||||
public function checkPhone(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'prefix' => 'required|string',
|
||||
'phone' => ['required', 'string', new \App\Rules\PhoneNumber]
|
||||
]);
|
||||
|
||||
$prefix = $request->input('prefix');
|
||||
$phone = $request->input('phone');
|
||||
|
||||
$fullPhone = $this->formatFullPhoneNumber($prefix, $phone);
|
||||
|
||||
$levels = $this->authService->getLevelsForPhone($fullPhone);
|
||||
|
||||
if (count($levels) === 1) {
|
||||
session(['login_phone' => $fullPhone, 'login_level' => $levels[0]]);
|
||||
return redirect()->route('password');
|
||||
}
|
||||
|
||||
if (count($levels) > 1) {
|
||||
session(['login_phone' => $fullPhone, 'available_levels' => $levels]);
|
||||
return redirect()->route('portal');
|
||||
}
|
||||
|
||||
session(['register_phone' => $fullPhone]);
|
||||
return redirect()->route('register.chooseType');
|
||||
}
|
||||
|
||||
|
||||
private function formatFullPhoneNumber(string $prefix, string $phone): string
|
||||
{
|
||||
$phone = ltrim($phone, '0');
|
||||
|
||||
return $prefix . $phone;
|
||||
}
|
||||
|
||||
public function choosePortal(Request $request)
|
||||
{
|
||||
$phone = session('login_phone');
|
||||
$availableLevels = session('available_levels');
|
||||
|
||||
if (!$phone || !$availableLevels) return redirect()->route('login');
|
||||
|
||||
if ($request->level && in_array($request->level, $availableLevels)) {
|
||||
session(['login_level' => $request->level]);
|
||||
return redirect()->route('password');
|
||||
}
|
||||
|
||||
return Inertia::client('Auth/ChoosePortal', compact('phone', 'availableLevels'));
|
||||
}
|
||||
|
||||
public function showPasswordForm()
|
||||
{
|
||||
$phone = session('login_phone');
|
||||
$level = session('login_level');
|
||||
|
||||
if (!$phone || !$level) return redirect()->route('login');
|
||||
|
||||
return Inertia::client('Auth/Password', compact('phone', 'level'));
|
||||
}
|
||||
|
||||
public function authenticate(Request $request)
|
||||
{
|
||||
$request->validate(['password' => 'required|string']);
|
||||
|
||||
$phone = session('login_phone');
|
||||
$level = session('login_level');
|
||||
|
||||
if (!$phone || !$level) {
|
||||
session()->flash('error', 'لطفاً ابتدا شماره موبایل خود را وارد کنید');
|
||||
return redirect()->route('login');
|
||||
}
|
||||
$persianLevel = $this->convertLevelToPersian($level);
|
||||
|
||||
$user = $this->authService->authenticateByPhoneAndLevel($phone, $persianLevel, $request->password);
|
||||
if (!$user) {
|
||||
return back()->withErrors(['password' => 'گذرواژه یا شماره موبایل اشتباه است']);
|
||||
}
|
||||
|
||||
return redirect()->route('dashboard.index');
|
||||
}
|
||||
|
||||
public function sendOtp()
|
||||
{
|
||||
$phone = session('login_phone');
|
||||
|
||||
if (!$phone) {
|
||||
session()->flash('error', 'شماره موبایل یافت نشد.');
|
||||
return redirect()->route('login');
|
||||
}
|
||||
|
||||
session()->forget(['otp_verified', 'verified_phone']);
|
||||
|
||||
$this->otpService->sendForPhone($phone, minutes: 3);
|
||||
|
||||
session()->flash('success', 'کد تایید ارسال شد.');
|
||||
return redirect()->route('otpVerification');
|
||||
}
|
||||
|
||||
public function otpVerification()
|
||||
{
|
||||
$phone = session('login_phone');
|
||||
if (!$phone) {
|
||||
session()->flash('error', 'شماره موبایل یافت نشد. مجدداً تلاش کنید.');
|
||||
return redirect()->route('login');
|
||||
}
|
||||
|
||||
return Inertia::client('Auth/OtpVerification', ['phone' => $phone]);
|
||||
}
|
||||
|
||||
public function verifyOtp(VerifyOtpRequest $request)
|
||||
{
|
||||
$phone = session('login_phone');
|
||||
if (!$phone) {
|
||||
session()->flash('error', 'شماره موبایل یافت نشد. مجدداً تلاش کنید.');
|
||||
return redirect()->route('login');
|
||||
}
|
||||
|
||||
$ok = $this->otpService->verifyCode($phone, $request->otp_code);
|
||||
|
||||
if (!$ok) {
|
||||
session()->flash('error', 'کد وارد شده معتبر نیست یا منقضی شده است.');
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
session(['otp_verified' => true, 'verified_phone' => $phone]);
|
||||
session()->flash('success', 'کد تایید با موفقیت تایید شد.');
|
||||
return redirect()->route('resetPassword');
|
||||
}
|
||||
|
||||
public function resetPassword()
|
||||
{
|
||||
if (!session('otp_verified') || !session('verified_phone')) {
|
||||
session()->flash('error', 'لطفاً ابتدا شماره موبایل خود را احراز کنید');
|
||||
return redirect()->route('login');
|
||||
}
|
||||
|
||||
return Inertia::client('Auth/ResetPassword', ['phone' => session('verified_phone')]);
|
||||
}
|
||||
|
||||
public function updatePassword(Request $request)
|
||||
{
|
||||
if (!session('otp_verified') || !session('verified_phone')) {
|
||||
session()->flash('error', 'لطفاً ابتدا شماره موبایل خود را احراز کنید');
|
||||
return redirect()->route('login');
|
||||
}
|
||||
$level = $this->convertLevelToPersian(session('login_level'));
|
||||
|
||||
$request->validate(['password' => 'required|string|min:8|confirmed']);
|
||||
|
||||
$user = User::where('phone', session('verified_phone'))
|
||||
->where('level', $level)
|
||||
->first();
|
||||
if (!$user) {
|
||||
session()->flash('error', 'کاربر یافت نشد.');
|
||||
return redirect()->route('login');
|
||||
}
|
||||
|
||||
$user->update(['password' => Hash::make($request->password)]);
|
||||
session()->flush();
|
||||
|
||||
session()->flash('success', 'رمز عبور با موفقیت تغییر یافت.');
|
||||
return redirect()->route('login');
|
||||
}
|
||||
|
||||
public function chooseType()
|
||||
{
|
||||
$phone = session('register_phone');
|
||||
return Inertia::client('Auth/ChooseRegisterType', ['phone' => $phone]);
|
||||
}
|
||||
|
||||
public function registerSupervisor()
|
||||
{
|
||||
$phone = session('register_phone');
|
||||
return Inertia::client('Auth/RegisterSupervisor', ['phone' => $phone]);
|
||||
}
|
||||
|
||||
public function registerVeterinarian()
|
||||
{
|
||||
$phone = session('register_phone');
|
||||
return Inertia::client('Auth/RegisterVet', ['phone' => $phone]);
|
||||
}
|
||||
|
||||
public function store(UserRegistrationRequest $request)
|
||||
{
|
||||
$phone = session('register_phone');
|
||||
if (!$phone) {
|
||||
session()->flash('error', 'لطفاً ابتدا شماره موبایل خود را وارد کنید');
|
||||
return redirect()->route('login');
|
||||
}
|
||||
|
||||
$data = array_merge($request->validated(), ['phone' => $phone]);
|
||||
|
||||
$this->registrationService->registerAndLogin($data);
|
||||
|
||||
session()->flash('success', 'ثبتنام با موفقیت انجام شد.');
|
||||
|
||||
|
||||
return redirect()->route('dashboard.index');
|
||||
}
|
||||
|
||||
private function convertLevelToPersian($level)
|
||||
{
|
||||
return match ($level) {
|
||||
'supervisor' => UserEnum::Supervisor->value,
|
||||
'doctor' => UserEnum::Doctor->value,
|
||||
'veterinarian' => UserEnum::Vet->value,
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
Auth::logout();
|
||||
session()->flush();
|
||||
return redirect()->route('login');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client\Doctor;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class CaseController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return Inertia::client('Dashboard/Cases/Index');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client\Doctor;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return Inertia::client('Dashboard/Dashboard');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client\Doctor;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Document;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class DocumentController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return Inertia::client('Dashboard/Documents/Index');
|
||||
}
|
||||
|
||||
public function show(Document $document)
|
||||
{
|
||||
return Inertia::client('Dashboard/Documents/show', [
|
||||
'document' => $document,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client\Doctor;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class ReportController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return Inertia::client('Dashboard/Reports/Index');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Client\Doctor;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
|
||||
class ShiftController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return Inertia::client('Dashboard/Shifts/Index');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
abstract class Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class CheckPermission
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next , string $permission): Response
|
||||
{
|
||||
$user = $request->user();
|
||||
if (!$user || !$user->can($permission)) {
|
||||
abort(403, 'Unauthorized');
|
||||
}
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class EnsureAdminAccess
|
||||
{
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
if (!Auth::check()) {
|
||||
return redirect()->route('admin.auth.login');
|
||||
}
|
||||
|
||||
$user = Auth::user();
|
||||
|
||||
if ($user->level !== 'مدیر') {
|
||||
abort(404, 'not found');
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Middleware;
|
||||
|
||||
class HandleInertiaRequests extends Middleware
|
||||
{
|
||||
/**
|
||||
* The root template that's loaded on the first page visit.
|
||||
*
|
||||
* @see https://inertiajs.com/server-side-setup#root-template
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $rootView = 'app';
|
||||
|
||||
/**
|
||||
* Determines the current asset version.
|
||||
*
|
||||
* @see https://inertiajs.com/asset-versioning
|
||||
*/
|
||||
public function version(Request $request): ?string
|
||||
{
|
||||
return parent::version($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the props that are shared by default.
|
||||
*
|
||||
* @see https://inertiajs.com/shared-data
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function share(Request $request): array
|
||||
{
|
||||
return [
|
||||
...parent::share($request),
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
use App\Enums\DocumentStatusEnum;
|
||||
use App\Enums\DocumentPriorityEnum;
|
||||
|
||||
class DocumentRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'modality' => ['nullable', 'string', 'max:255'],
|
||||
'status' => ['nullable', 'string', 'max:255' , Rule::in(DocumentStatusEnum::keys())],
|
||||
'priority' => ['nullable', 'string', 'max:255' , Rule::in(DocumentPriorityEnum::keys())],
|
||||
'note' => ['nullable', 'string', 'max:255'],
|
||||
'pet_id' => ['required', 'exists:pets,id'],
|
||||
'submitted_at' => ['nullable', 'date'],
|
||||
'scan_date' => ['nullable', 'date'],
|
||||
'processing_deadline' => ['nullable', 'date'],
|
||||
'primary_files' => ['nullable', 'array'],
|
||||
'history_files' => ['nullable', 'array'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
use App\Enums\PetTypeEnum;
|
||||
use App\Enums\PetGenderEnum;
|
||||
use App\Support\Converters\PersianToEnglish;
|
||||
|
||||
class PetRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'type' => ['required', 'string', 'max:255', Rule::in(PetTypeEnum::values())],
|
||||
'gender' => ['required', 'string', 'max:255', Rule::in(PetGenderEnum::values())],
|
||||
'breed' => ['required', 'string', 'max:255'],
|
||||
'weight' => ['required', 'integer'],
|
||||
'sterilized' => ['required', 'boolean'],
|
||||
'birthday' => ['required', 'date'],
|
||||
];
|
||||
}
|
||||
|
||||
public function prepareForValidation()
|
||||
{
|
||||
$this->merge([
|
||||
'weight' => PersianToEnglish::toEnglish($this->weight),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
use App\Enums\ReportStatusEnum;
|
||||
|
||||
class ReportRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'document_id' => ['required', 'exists:documents,id'],
|
||||
'doctor_id' => ['required', 'exists:users,id'],
|
||||
'medium_id' => ['nullable', 'exists:media,id'],
|
||||
'status' => ['required', 'string', 'max:255' , Rule::in(ReportStatusEnum::keys())],
|
||||
'body' => ['required', 'string'],
|
||||
'submitted_at' => ['required', 'date'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class SettingProfileRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$toBeEditedUser = $this->route('user');
|
||||
return [
|
||||
'name' => ['required', 'max:255',
|
||||
isset($toBeEditedUser)
|
||||
? Rule::unique('users', 'name')->ignore($toBeEditedUser->id)
|
||||
: Rule::unique('users', 'name')],
|
||||
'first_name' => 'nullable | max:255',
|
||||
'last_name' => 'nullable | max:255',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use App\Enums\UserEnum;
|
||||
use App\Rules\PhoneNumber;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UserRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the User is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$toBeEditedUser = $this->route()->parameter('user');
|
||||
return [
|
||||
'username' => ['nullable', 'min:2', 'max:255',
|
||||
isset($toBeEditedUser)
|
||||
? Rule::unique('users')->ignore($toBeEditedUser->id)
|
||||
: Rule::unique('users')],
|
||||
'phone' => ['required', 'max:255', new PhoneNumber],
|
||||
'fullname' => 'nullable | max:255',
|
||||
'role' => ['nullable', 'array', 'exists:roles,id'],
|
||||
'profile_url' => ['nullable', 'exists:medium,url'],
|
||||
'email' => ['nullable', 'email', 'max:255',
|
||||
isset($toBeEditedUser)
|
||||
? Rule::unique('users')->ignore($toBeEditedUser->id)
|
||||
: Rule::unique('users')],
|
||||
'password' => [isset($toBeEditedUser) ? 'nullable' : 'required', 'min:8' , 'confirmed'],
|
||||
'level' => ['required', Rule::in(['مدیر' , 'پزشک' , 'سرپرست'])],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Client\Auth;
|
||||
|
||||
use App\Rules\PhoneNumber;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UserRegistrationRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'phone' => ['required', 'string', new PhoneNumber],
|
||||
'fullname' => 'nullable|string|max:255',
|
||||
'national_code' => 'required|string|max:255',
|
||||
'specialty' => 'nullable|string|max:255',
|
||||
'clinic_name' => 'nullable|string|max:255',
|
||||
'clinic_phone' => 'nullable|string|max:255',
|
||||
'province' => 'nullable|string|max:255',
|
||||
'city' => 'nullable|string|max:255',
|
||||
'address' => 'nullable|string|max:255',
|
||||
'level' => 'nullable|string|max:50',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Client\Auth;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class VerifyOtpRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'otp_code' => [
|
||||
'required',
|
||||
'numeric',
|
||||
'digits:4',
|
||||
Rule::exists('otp_codes', 'code')->where(function ($query) {
|
||||
$query->where('phone', session('login_phone'))
|
||||
->where('expires_at', '>', now());
|
||||
})
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Admin;
|
||||
|
||||
use App\Enums\DocumentStatusEnum;
|
||||
use App\Enums\DocumentPriorityEnum;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class DocumentEditFormResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'note' => $this->note,
|
||||
'priority' => $this->priority,
|
||||
'image' => $this->image,
|
||||
'code' => $this->code,
|
||||
'modality' => $this->modality,
|
||||
'status' => $this->status instanceof DocumentStatusEnum ? $this->status->name : $this->status,
|
||||
'priority' => $this->priority instanceof DocumentPriorityEnum ? $this->priority->name : $this->priority,
|
||||
'pet_id' => $this->pet_id,
|
||||
'requester' => $this->relationLoaded('requester') ? optional($this->requester)->only(['id','fullname']) : null,
|
||||
'submitted_at' => $this->submitted_at,
|
||||
'processing_deadline' => $this->processing_deadline,
|
||||
'primary_files' => $this->relationLoaded('primaryFiles') ? $this->primaryFiles->map(function ($file) {
|
||||
return [
|
||||
'id' => $file->id,
|
||||
'filename' => $file->filename,
|
||||
'mime_type' => $file->mime_type,
|
||||
];
|
||||
}) : [],
|
||||
'history_files' => $this->relationLoaded('historyFiles') ? $this->historyFiles->map(function ($file) {
|
||||
return [
|
||||
'id' => $file->id,
|
||||
'filename' => $file->filename,
|
||||
'mime_type' => $file->mime_type,
|
||||
];
|
||||
}) : [],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Admin;
|
||||
|
||||
use App\Enums\DocumentStatusEnum;
|
||||
use App\Enums\DocumentPriorityEnum;
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class DocumentResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'note' => $this->note,
|
||||
'priority' => $this->priority,
|
||||
'image' => $this->image,
|
||||
'code' => $this->code,
|
||||
'modality' => $this->modality,
|
||||
'status' => $this->status,
|
||||
'priority' => $this->priority,
|
||||
'pet' => $this->relationLoaded('pet') ? optional($this->pet)->only(['id','name','birthday']) : null,
|
||||
'requester' => $this->relationLoaded('requester') ? optional($this->requester)->only(['id','fullname']) : null,
|
||||
'submitted_at' => verta($this->submitted_at)->format('%Y/%m/%d - H:i'),
|
||||
'processing_deadline' => verta($this->processing_deadline)->format('%Y/%m/%d - H:i'),
|
||||
];
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class PermissionResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'label' => $this->label,
|
||||
'created_at' => verta($this->created_at)->format('%d %B %Y %H:%M:%S'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class PetResource extends JsonResource
|
||||
{
|
||||
|
||||
function calculateAge($birthday) {
|
||||
if (!$birthday) return null;
|
||||
|
||||
$birth = Carbon::parse($birthday);
|
||||
$now = Carbon::now();
|
||||
|
||||
$years = (int) $birth->diffInYears($now);
|
||||
$months = (int) $birth->copy()->addYears($years)->diffInMonths($now);
|
||||
$days = (int) $birth->copy()->addYears($years)->addMonths($months)->diffInDays($now);
|
||||
|
||||
$parts = [];
|
||||
if ($years > 0) $parts[] = $years . ' ساله';
|
||||
if ($months > 0) $parts[] = $months . ' ماهه';
|
||||
if ($days > 0 && $years == 0) $parts[] = $days . ' روزه';
|
||||
|
||||
return implode(' و ', $parts) ?: 'تازه متولد';
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'type' => $this->type,
|
||||
'gender' => $this->gender,
|
||||
'breed' => $this->breed,
|
||||
'weight' => $this->weight,
|
||||
'sterilized' => $this->sterilized,
|
||||
'birthday' => verta($this->birthday)->format('%Y/%m/%d - H:i'),
|
||||
'age' => $this->calculateAge($this->birthday),
|
||||
'owner' => $this->relationLoaded('owner') ? $this->owner->only(['id','fullname']) : null,
|
||||
'created_at' => verta($this->created_at)->format('%Y/%m/%d - H:i'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Panel;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class RelationWordResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'wordRelated' => $this->relatedWord?->word,
|
||||
'wordRelated_id' => $this->relatedWord?->id,
|
||||
'description' => $this->description,
|
||||
'relation_type' => $this->relation_type,
|
||||
'created_at' => verta($this->created_at)->format('%d %B %Y %H:%M:%S'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Admin;
|
||||
|
||||
use Hekmatinasser\Verta\Verta;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ReportResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'document' => $this->relationLoaded('document') ? $this->document->only(['id','code']) : null,
|
||||
'status' => $this->status,
|
||||
'body' => $this->body,
|
||||
'doctor' => $this->relationLoaded('doctor') ? $this->doctor->only(['id','fullname']) : null,
|
||||
'submitted_at' => verta($this->submitted_at)->format('%Y/%m/%d - H:i'),
|
||||
'submitted_at_form' => $this->submitted_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class RoleResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'label' => $this->label,
|
||||
'created_at' => verta($this->created_at)->format('%d %B %Y %H:%M:%S'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Admin;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class SessionsIndexResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'ip' => $this->ip_address,
|
||||
'user_agent' => $this->user_agent,
|
||||
"last_activity" => $this->generateLastTime(),
|
||||
];
|
||||
}
|
||||
|
||||
private function generateLastTime()
|
||||
{
|
||||
$timestamp = $this->last_activity;
|
||||
|
||||
$carbon = Carbon::createFromTimestamp($timestamp);
|
||||
return verta($carbon)->format('%Y/%m/%d - H:i');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class UserResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'username' => $this->username,
|
||||
'phone' => $this->phone,
|
||||
'fullname' => $this->fullname,
|
||||
'level' => $this->level,
|
||||
'email' => $this->email,
|
||||
'created_at' => verta($this->created_at)->format('%d %B %Y %H:%M:%S'),
|
||||
'profile_url' => $this->profile_url,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class UserShortResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'username' => $this->username,
|
||||
'phone' => $this->phone,
|
||||
'fullname' => $this->fullname,
|
||||
'level' => $this->level,
|
||||
'email' => $this->email,
|
||||
'profile_url' => $this->profile_url,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\DocumentStatusEnum;
|
||||
use App\Enums\DocumentPriorityEnum;
|
||||
use App\Observers\DocumentObserver;
|
||||
use Illuminate\Database\Eloquent\Attributes\ObservedBy;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
#[ObservedBy(DocumentObserver::class)]
|
||||
class Document extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $fillable = [
|
||||
'code',
|
||||
'modality',
|
||||
'status',
|
||||
'priority',
|
||||
'note',
|
||||
'submitted_at',
|
||||
'scan_date',
|
||||
'processing_deadline',
|
||||
'finalized_at',
|
||||
'finalized_by',
|
||||
'rejection_reason',
|
||||
'pet_id',
|
||||
'requester_id',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'status' => DocumentStatusEnum::class,
|
||||
'priority' => DocumentPriorityEnum::class,
|
||||
'submitted_at' => 'datetime',
|
||||
'scan_date' => 'datetime',
|
||||
'processing_deadline' => 'datetime',
|
||||
'finalized_at' => 'datetime',
|
||||
'finalized_by' => 'integer',
|
||||
'pet_id' => 'integer',
|
||||
'requester_id' => 'integer',
|
||||
];
|
||||
|
||||
public function pet()
|
||||
{
|
||||
return $this->belongsTo(Pet::class);
|
||||
}
|
||||
|
||||
public function requester()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'requester_id');
|
||||
}
|
||||
|
||||
public function finalizedBy()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function assignments()
|
||||
{
|
||||
return $this->hasMany(DocumentAssignment::class);
|
||||
}
|
||||
|
||||
public function reports()
|
||||
{
|
||||
return $this->hasMany(Report::class);
|
||||
}
|
||||
|
||||
public function media()
|
||||
{
|
||||
return $this->morphToMany(
|
||||
\App\Models\Medium::class,
|
||||
'mediable',
|
||||
'media_assignments',
|
||||
'mediable_id',
|
||||
'media_id'
|
||||
)->withPivot('collection');
|
||||
}
|
||||
|
||||
public function primaryFiles()
|
||||
{
|
||||
return $this->media()->wherePivot('collection', 'primary');
|
||||
}
|
||||
|
||||
public function historyFiles()
|
||||
{
|
||||
return $this->media()->wherePivot('collection', 'history');
|
||||
}
|
||||
|
||||
public function users()
|
||||
{
|
||||
return $this->belongsToMany(User::class, 'document_assignments')
|
||||
->withPivot('role')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function mediaAssignments()
|
||||
{
|
||||
return $this->morphMany(MediaAssignment::class, 'mediable');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DocumentAssignment extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $fillable = [
|
||||
'document_id',
|
||||
'user_id',
|
||||
'role',
|
||||
];
|
||||
|
||||
public function document()
|
||||
{
|
||||
return $this->belongsTo(Document::class);
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\MediaCollectionEnum;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class MediaAssignment extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $fillable = [
|
||||
'media_id',
|
||||
'mediable_id',
|
||||
'mediable_type',
|
||||
'collection',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'collection' => MediaCollectionEnum::class,
|
||||
];
|
||||
|
||||
public function media()
|
||||
{
|
||||
return $this->belongsTo(Medium::class);
|
||||
}
|
||||
|
||||
public function mediable()
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\MediaDiskEnum;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class Medium extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $fillable = [
|
||||
'filename',
|
||||
'disk',
|
||||
'path',
|
||||
'size',
|
||||
'url',
|
||||
'mime_type'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'disk' => MediaDiskEnum::class,
|
||||
];
|
||||
|
||||
public function getFullUrlAttribute()
|
||||
{
|
||||
if ($this->disk === MediaDiskEnum::Public) {
|
||||
return Storage::disk('public')->path($this->path);
|
||||
}elseif($this->disk === MediaDiskEnum::Private){
|
||||
return Storage::disk('private')->path($this->path);
|
||||
}
|
||||
|
||||
return $this->url ?? null;
|
||||
}
|
||||
|
||||
public function getStorageDisk()
|
||||
{
|
||||
return Storage::disk($this->disk?->value ?? 'public');
|
||||
}
|
||||
|
||||
public function exists()
|
||||
{
|
||||
return $this->getStorageDisk()->exists($this->path);
|
||||
}
|
||||
|
||||
public function getContents()
|
||||
{
|
||||
return $this->getStorageDisk()->get($this->path);
|
||||
}
|
||||
|
||||
public function deleteFile()
|
||||
{
|
||||
if ($this->exists()) {
|
||||
return $this->getStorageDisk()->delete($this->path);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getHumanSizeAttribute()
|
||||
{
|
||||
$bytes = $this->size;
|
||||
$units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
|
||||
for ($i = 0; $bytes > 1024 && $i < count($units) - 1; $i++) {
|
||||
$bytes /= 1024;
|
||||
}
|
||||
|
||||
return round($bytes, 2) . ' ' . $units[$i];
|
||||
}
|
||||
|
||||
public function isPublic()
|
||||
{
|
||||
return $this->disk === MediaDiskEnum::Public;
|
||||
}
|
||||
|
||||
public function isPrivate()
|
||||
{
|
||||
return $this->disk === MediaDiskEnum::Private;
|
||||
}
|
||||
|
||||
public function assignments()
|
||||
{
|
||||
return $this->hasMany(MediaAssignment::class , 'media_id' , 'id');
|
||||
}
|
||||
|
||||
public function reports()
|
||||
{
|
||||
return $this->morphedByMany(
|
||||
\App\Models\Report::class,
|
||||
'mediable',
|
||||
'media_assignments',
|
||||
'media_id',
|
||||
'mediable_id'
|
||||
);
|
||||
}
|
||||
|
||||
public function documents()
|
||||
{
|
||||
return $this->morphedByMany(
|
||||
\App\Models\Document::class,
|
||||
'mediable',
|
||||
'media_assignments',
|
||||
'media_id',
|
||||
'mediable_id'
|
||||
);
|
||||
}
|
||||
|
||||
public function users()
|
||||
{
|
||||
return $this->hasMany(User::class , 'media_id' , 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class OtpCode extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'phone',
|
||||
'code',
|
||||
'expires_at'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'expires_at' => 'datetime'
|
||||
];
|
||||
|
||||
public function isExpired()
|
||||
{
|
||||
return now()->isAfter($this->expires_at);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Spatie\Permission\Models\Permission as SpatiePermission;
|
||||
|
||||
class Permission extends SpatiePermission
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $with = ['permissionsParent'];
|
||||
|
||||
public function permissionsParent(){
|
||||
return $this->hasMany(Permission::class , 'parent_id' , 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\PetTypeEnum;
|
||||
use App\Enums\PetGenderEnum;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Pet extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'type',
|
||||
'gender',
|
||||
'breed',
|
||||
'weight',
|
||||
'sterilized',
|
||||
'birthday',
|
||||
'owner_id',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'type' => PetTypeEnum::class,
|
||||
'gender' => PetGenderEnum::class,
|
||||
'weight' => 'integer',
|
||||
'sterilized' => 'boolean',
|
||||
'birthday' => 'date',
|
||||
];
|
||||
|
||||
public function owner()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'owner_id');
|
||||
}
|
||||
|
||||
public function documents()
|
||||
{
|
||||
return $this->hasMany(Document::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\ReportStatusEnum;
|
||||
use App\Enums\MediaCollectionEnum;
|
||||
use App\Enums\UserEnum;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Report extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $fillable = [
|
||||
'document_id',
|
||||
'doctor_id',
|
||||
'medium_id',
|
||||
'status',
|
||||
'body',
|
||||
'submitted_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'status' => ReportStatusEnum::class,
|
||||
'submitted_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function document()
|
||||
{
|
||||
return $this->belongsTo(Document::class , 'document_id');
|
||||
}
|
||||
|
||||
public function doctor()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'doctor_id')->where('level', UserEnum::Doctor->value);
|
||||
}
|
||||
|
||||
public function media()
|
||||
{
|
||||
return $this->morphToMany(
|
||||
\App\Models\Medium::class,
|
||||
'mediable',
|
||||
'media_assignments',
|
||||
'mediable_id',
|
||||
'media_id'
|
||||
)->withPivot('collection')->withTimestamps();
|
||||
}
|
||||
|
||||
public function medium()
|
||||
{
|
||||
return $this->belongsTo(Medium::class);
|
||||
}
|
||||
|
||||
public function attachments()
|
||||
{
|
||||
return $this->media()->wherePivot('collection', MediaCollectionEnum::Attachments->value);
|
||||
}
|
||||
|
||||
public function mediaAssignments()
|
||||
{
|
||||
return $this->morphMany(MediaAssignment::class, 'mediable');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Session extends Model
|
||||
{
|
||||
protected $table = 'sessions';
|
||||
public $timestamps = false;
|
||||
protected $primaryKey = 'id';
|
||||
protected $keyType = 'string';
|
||||
protected $casts = [
|
||||
'payload' => 'string',
|
||||
'last_activity' => 'integer',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasFactory, Notifiable , HasRoles;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
|
||||
protected $fillable = [
|
||||
'username',
|
||||
'fullname',
|
||||
'national_code',
|
||||
'level',
|
||||
'email',
|
||||
'phone',
|
||||
'password',
|
||||
'profile_url',
|
||||
'clinic_name',
|
||||
'clinic_phone',
|
||||
'province',
|
||||
'city',
|
||||
'address',
|
||||
'specialty',
|
||||
'created_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
|
||||
public function documents()
|
||||
{
|
||||
return $this->belongsToMany(Document::class, 'document_assignments')
|
||||
->withPivot('role')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function pets()
|
||||
{
|
||||
return $this->hasMany(Pet::class, 'owner_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\Document;
|
||||
use App\Services\Document\DocumentCodeService;
|
||||
|
||||
class DocumentObserver
|
||||
{
|
||||
protected DocumentCodeService $service;
|
||||
|
||||
public function __construct(DocumentCodeService $service)
|
||||
{
|
||||
$this->service = $service;
|
||||
}
|
||||
|
||||
public function creating(Document $document): void
|
||||
{
|
||||
if (empty($document->code)) {
|
||||
$document->code = $this->service->generate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Inertia\Inertia;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Inertia\ResponseFactory;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
public const HOME = '/';
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
ResponseFactory::macro('client', function ($component, $props = []) {
|
||||
return Inertia::render($component, $props)->rootView('client');
|
||||
});
|
||||
ResponseFactory::macro('admin', function ($component, $props = []) {
|
||||
return Inertia::render($component, $props)->rootView('app');
|
||||
});
|
||||
|
||||
|
||||
|
||||
Inertia::share([
|
||||
'errors' => function () {
|
||||
return Session::get('errors')
|
||||
? Session::get('errors')->getBag('default')->getMessages()
|
||||
: (object) [];
|
||||
},
|
||||
'auth' => function () {
|
||||
$user = Auth::user();
|
||||
$permissions = $user ? $user->getAllPermissions()->pluck('name') : [];
|
||||
return [
|
||||
'User' => $user,
|
||||
'permissions' => $permissions,
|
||||
];
|
||||
},
|
||||
]);
|
||||
Inertia::share('flash', function () {
|
||||
return [
|
||||
'success' => Session::get('success'),
|
||||
'error' => Session::get('error'),
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\Document;
|
||||
use App\Observers\DocumentObserver;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
|
||||
class EventServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function boot()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,373 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
|
||||
class PhoneNumber implements ValidationRule
|
||||
{
|
||||
/**
|
||||
* Run the validation rule.
|
||||
*/
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
if (!is_string($value)) {
|
||||
$fail('شماره تلفن نامعتبر است.');
|
||||
return;
|
||||
}
|
||||
|
||||
$phone = $this->normalizePhone($value);
|
||||
|
||||
if (!$this->isValidFormat($phone)) {
|
||||
$fail('شماره تلفن نامعتبر است.');
|
||||
session()->flash('error', 'شماره تلفن نامعتبر است.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->isValidCountryCode($phone)) {
|
||||
$fail('کد کشور نامعتبر است.');
|
||||
session()->flash('error', 'کد کشور نامعتبر است.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->isValidLength($phone)) {
|
||||
$fail('شماره تلفن نامعتبر است.');
|
||||
session()->flash('error', 'شماره تلفن نامعتبر است.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private function normalizePhone(string $phone): string
|
||||
{
|
||||
$phone = $this->convertPersianToEnglish($phone);
|
||||
return preg_replace('/[^0-9+]/', '', $phone);
|
||||
}
|
||||
|
||||
private function isValidFormat(string $phone): bool
|
||||
{
|
||||
return str_starts_with($phone, '+') || ctype_digit($phone);
|
||||
}
|
||||
|
||||
private function isValidCountryCode(string $phone): bool
|
||||
{
|
||||
if (!str_starts_with($phone, '+')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$phoneWithoutPlus = substr($phone, 1);
|
||||
$countryCodes = $this->getValidCountryCodes();
|
||||
|
||||
foreach ($countryCodes as $code) {
|
||||
if (str_starts_with($phoneWithoutPlus, $code)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function isValidLength(string $phone): bool
|
||||
{
|
||||
if (str_starts_with($phone, '+')) {
|
||||
$phoneWithoutPlus = substr($phone, 1);
|
||||
return strlen($phoneWithoutPlus) >= 7 && strlen($phoneWithoutPlus) <= 15;
|
||||
}
|
||||
|
||||
$phone = ltrim($phone, '0');
|
||||
return strlen($phone) >= 7 && strlen($phone) <= 12;
|
||||
}
|
||||
|
||||
private function convertPersianToEnglish(string $text): string
|
||||
{
|
||||
$persianNumbers = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
|
||||
$englishNumbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
|
||||
|
||||
return str_replace($persianNumbers, $englishNumbers, $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get valid country codes
|
||||
*/
|
||||
private function getValidCountryCodes(): array
|
||||
{
|
||||
return [
|
||||
// Middle East
|
||||
'98', // Iran
|
||||
'966', // Saudi Arabia
|
||||
'971', // UAE
|
||||
'965', // Kuwait
|
||||
'974', // Qatar
|
||||
'968', // Oman
|
||||
'973', // Bahrain
|
||||
'962', // Jordan
|
||||
'961', // Lebanon
|
||||
'963', // Syria
|
||||
'964', // Iraq
|
||||
'967', // Yemen
|
||||
'970', // Palestine
|
||||
'972', // Israel
|
||||
|
||||
// Europe
|
||||
'44', // UK
|
||||
'33', // France
|
||||
'49', // Germany
|
||||
'39', // Italy
|
||||
'34', // Spain
|
||||
'31', // Netherlands
|
||||
'32', // Belgium
|
||||
'41', // Switzerland
|
||||
'43', // Austria
|
||||
'46', // Sweden
|
||||
'47', // Norway
|
||||
'45', // Denmark
|
||||
'358', // Finland
|
||||
'48', // Poland
|
||||
'420', // Czech Republic
|
||||
'36', // Hungary
|
||||
'40', // Romania
|
||||
'380', // Ukraine
|
||||
'7', // Russia
|
||||
'375', // Belarus
|
||||
'371', // Latvia
|
||||
'372', // Estonia
|
||||
'370', // Lithuania
|
||||
'90', // Turkey
|
||||
'994', // Azerbaijan
|
||||
'374', // Armenia
|
||||
'995', // Georgia
|
||||
|
||||
// Asia
|
||||
'86', // China
|
||||
'81', // Japan
|
||||
'82', // South Korea
|
||||
'91', // India
|
||||
'92', // Pakistan
|
||||
'880', // Bangladesh
|
||||
'93', // Afghanistan
|
||||
'992', // Tajikistan
|
||||
'993', // Turkmenistan
|
||||
'996', // Kyrgyzstan
|
||||
'998', // Uzbekistan
|
||||
'65', // Singapore
|
||||
'60', // Malaysia
|
||||
'66', // Thailand
|
||||
'84', // Vietnam
|
||||
'62', // Indonesia
|
||||
'63', // Philippines
|
||||
'977', // Nepal
|
||||
'975', // Bhutan
|
||||
'976', // Mongolia
|
||||
'855', // Cambodia
|
||||
'856', // Laos
|
||||
'95', // Myanmar
|
||||
'94', // Sri Lanka
|
||||
'960', // Maldives
|
||||
'886', // Taiwan
|
||||
'852', // Hong Kong
|
||||
'853', // Macau
|
||||
'850', // North Korea
|
||||
|
||||
// Americas
|
||||
'1', // USA/Canada
|
||||
'52', // Mexico
|
||||
'55', // Brazil
|
||||
'54', // Argentina
|
||||
'56', // Chile
|
||||
'57', // Colombia
|
||||
'51', // Peru
|
||||
'58', // Venezuela
|
||||
'598', // Uruguay
|
||||
'595', // Paraguay
|
||||
'591', // Bolivia
|
||||
'593', // Ecuador
|
||||
'592', // Guyana
|
||||
'597', // Suriname
|
||||
|
||||
// Africa
|
||||
'20', // Egypt
|
||||
'212', // Morocco
|
||||
'213', // Algeria
|
||||
'216', // Tunisia
|
||||
'218', // Libya
|
||||
'249', // Sudan
|
||||
'27', // South Africa
|
||||
'234', // Nigeria
|
||||
'254', // Kenya
|
||||
'251', // Ethiopia
|
||||
'255', // Tanzania
|
||||
'256', // Uganda
|
||||
'233', // Ghana
|
||||
'225', // Ivory Coast
|
||||
'237', // Cameroon
|
||||
'236', // Central African Republic
|
||||
'235', // Chad
|
||||
'241', // Gabon
|
||||
'242', // Republic of the Congo
|
||||
'243', // Democratic Republic of the Congo
|
||||
'244', // Angola
|
||||
'245', // Guinea-Bissau
|
||||
'250', // Rwanda
|
||||
'257', // Burundi
|
||||
'258', // Mozambique
|
||||
'260', // Zambia
|
||||
'261', // Madagascar
|
||||
'263', // Zimbabwe
|
||||
'264', // Namibia
|
||||
'265', // Malawi
|
||||
'266', // Lesotho
|
||||
'267', // Botswana
|
||||
'268', // Eswatini
|
||||
'269', // Comoros
|
||||
'291', // Eritrea
|
||||
'252', // Somalia
|
||||
'253', // Djibouti
|
||||
|
||||
// Oceania
|
||||
'61', // Australia
|
||||
'64', // New Zealand
|
||||
'679', // Fiji
|
||||
'675', // Papua New Guinea
|
||||
'685', // Samoa
|
||||
'676', // Tonga
|
||||
'677', // Solomon Islands
|
||||
'678', // Vanuatu
|
||||
'680', // Palau
|
||||
'681', // Wallis and Futuna
|
||||
'682', // Cook Islands
|
||||
'683', // Niue
|
||||
'686', // Kiribati
|
||||
'687', // New Caledonia
|
||||
'688', // Tuvalu
|
||||
'689', // French Polynesia
|
||||
'690', // Tokelau
|
||||
'691', // Micronesia
|
||||
'692', // Marshall Islands
|
||||
|
||||
// Additional countries from JavaScript file
|
||||
'355', // Albania
|
||||
'376', // Andorra
|
||||
'1268', // Antigua and Barbuda
|
||||
'1242', // Bahamas
|
||||
'1246', // Barbados
|
||||
'501', // Belize
|
||||
'229', // Benin
|
||||
'1767', // Dominica
|
||||
'1809', // Dominican Republic
|
||||
'503', // El Salvador
|
||||
'240', // Equatorial Guinea
|
||||
'291', // Eritrea
|
||||
'372', // Estonia
|
||||
'679', // Fiji
|
||||
'220', // Gambia
|
||||
'995', // Georgia
|
||||
'1473', // Grenada
|
||||
'502', // Guatemala
|
||||
'224', // Guinea
|
||||
'245', // Guinea-Bissau
|
||||
'509', // Haiti
|
||||
'504', // Honduras
|
||||
'354', // Iceland
|
||||
'353', // Ireland
|
||||
'1876', // Jamaica
|
||||
'962', // Jordan
|
||||
'254', // Kenya
|
||||
'686', // Kiribati
|
||||
'965', // Kuwait
|
||||
'996', // Kyrgyzstan
|
||||
'856', // Laos
|
||||
'371', // Latvia
|
||||
'961', // Lebanon
|
||||
'266', // Lesotho
|
||||
'231', // Liberia
|
||||
'218', // Libya
|
||||
'423', // Liechtenstein
|
||||
'370', // Lithuania
|
||||
'352', // Luxembourg
|
||||
'261', // Madagascar
|
||||
'265', // Malawi
|
||||
'223', // Mali
|
||||
'356', // Malta
|
||||
'692', // Marshall Islands
|
||||
'222', // Mauritania
|
||||
'230', // Mauritius
|
||||
'52', // Mexico
|
||||
'691', // Micronesia
|
||||
'373', // Moldova
|
||||
'377', // Monaco
|
||||
'976', // Mongolia
|
||||
'382', // Montenegro
|
||||
'212', // Morocco
|
||||
'258', // Mozambique
|
||||
'95', // Myanmar
|
||||
'264', // Namibia
|
||||
'674', // Nauru
|
||||
'977', // Nepal
|
||||
'505', // Nicaragua
|
||||
'227', // Niger
|
||||
'234', // Nigeria
|
||||
'47', // Norway
|
||||
'968', // Oman
|
||||
'92', // Pakistan
|
||||
'680', // Palau
|
||||
'507', // Panama
|
||||
'675', // Papua New Guinea
|
||||
'595', // Paraguay
|
||||
'51', // Peru
|
||||
'63', // Philippines
|
||||
'48', // Poland
|
||||
'351', // Portugal
|
||||
'974', // Qatar
|
||||
'40', // Romania
|
||||
'250', // Rwanda
|
||||
'1869', // Saint Kitts and Nevis
|
||||
'1758', // Saint Lucia
|
||||
'1784', // Saint Vincent and the Grenadines
|
||||
'685', // Samoa
|
||||
'378', // San Marino
|
||||
'239', // Sao Tome and Principe
|
||||
'966', // Saudi Arabia
|
||||
'221', // Senegal
|
||||
'381', // Serbia
|
||||
'248', // Seychelles
|
||||
'232', // Sierra Leone
|
||||
'421', // Slovakia
|
||||
'386', // Slovenia
|
||||
'677', // Solomon Islands
|
||||
'252', // Somalia
|
||||
'27', // South Africa
|
||||
'82', // South Korea
|
||||
'94', // Sri Lanka
|
||||
'249', // Sudan
|
||||
'597', // Suriname
|
||||
'268', // Eswatini
|
||||
'46', // Sweden
|
||||
'41', // Switzerland
|
||||
'963', // Syria
|
||||
'886', // Taiwan
|
||||
'992', // Tajikistan
|
||||
'255', // Tanzania
|
||||
'66', // Thailand
|
||||
'670', // Timor-Leste
|
||||
'228', // Togo
|
||||
'676', // Tonga
|
||||
'1868', // Trinidad and Tobago
|
||||
'216', // Tunisia
|
||||
'993', // Turkmenistan
|
||||
'688', // Tuvalu
|
||||
'256', // Uganda
|
||||
'380', // Ukraine
|
||||
'971', // United Arab Emirates
|
||||
'44', // United Kingdom
|
||||
'1', // United States
|
||||
'598', // Uruguay
|
||||
'998', // Uzbekistan
|
||||
'678', // Vanuatu
|
||||
'379', // Vatican City
|
||||
'58', // Venezuela
|
||||
'967', // Yemen
|
||||
'260', // Zambia
|
||||
'263', // Zimbabwe
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
namespace App\Services\Auth;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
class AuthService
|
||||
{
|
||||
public function getLevelsForPhone(string $phone): array
|
||||
{
|
||||
session()->flush();
|
||||
$users = User::where('phone', $phone)->get(['level']);
|
||||
|
||||
return $users
|
||||
->map(fn($user) => match ($user->level) {
|
||||
'پزشک' => 'doctor',
|
||||
'سرپرست' => 'supervisor',
|
||||
'دانپزشک' => 'veterinarian',
|
||||
default => null,
|
||||
})
|
||||
->filter()
|
||||
->unique()
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
public function authenticateByPhoneAndLevel(string $phone, string $level, string $password): ?User
|
||||
{
|
||||
$user = User::where('phone', $phone)
|
||||
->where('level', $level)
|
||||
->first();
|
||||
|
||||
if (! $user) return null;
|
||||
|
||||
if (! Hash::check($password, $user->password)) return null;
|
||||
|
||||
Auth::login($user);
|
||||
session()->regenerate();
|
||||
session()->forget('register_phone' , 'verified_phone' , 'otp_verified' , 'login_phone' , 'login_level' , 'available_levels');
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Auth;
|
||||
|
||||
use App\Models\OtpCode;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class OtpService
|
||||
{
|
||||
public function generateCode(): string
|
||||
{
|
||||
return (string) random_int(1000, 9999);
|
||||
}
|
||||
|
||||
public function sendForPhone(string $phone, int $minutes = 3): OtpCode
|
||||
{
|
||||
$code = $this->generateCode();
|
||||
$expiresAt = now()->addMinutes($minutes);
|
||||
|
||||
$otpCode = OtpCode::updateOrCreate(
|
||||
['phone' => $phone],
|
||||
['code' => $code, 'expires_at' => $expiresAt]
|
||||
);
|
||||
|
||||
$this->sendSms($phone, $code);
|
||||
|
||||
return $otpCode;
|
||||
}
|
||||
|
||||
public function verifyCode(string $phone, string $code): bool
|
||||
{
|
||||
$deleted = OtpCode::where('phone', $phone)
|
||||
->where('code', $code)
|
||||
->where('expires_at', '>', now())
|
||||
->delete();
|
||||
|
||||
return (bool) $deleted;
|
||||
}
|
||||
|
||||
public function existsValid(string $phone, string $code): bool
|
||||
{
|
||||
return OtpCode::where('phone', $phone)
|
||||
->where('code', $code)
|
||||
->where('expires_at', '>', now())
|
||||
->exists();
|
||||
}
|
||||
|
||||
private function sendSms(string $phone, string $code): array
|
||||
{
|
||||
try {
|
||||
$formattedRecipient = $this->formatPhoneForSms($phone);
|
||||
|
||||
$response = Http::withHeaders([
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => 'application/json',
|
||||
'Api-Key' => config('services.iranpayamak.api_key'),
|
||||
])
|
||||
->post(config('services.iranpayamak.api_url'), [
|
||||
'code' => config('services.iranpayamak.patterns.verify_code'),
|
||||
'attributes' => [
|
||||
'otp' => $code,
|
||||
'status' => 'بازنشانی رمز عبور'
|
||||
],
|
||||
'recipient' => $formattedRecipient,
|
||||
'line_number' => config('services.iranpayamak.line_number'),
|
||||
'number_format' => 'english',
|
||||
]);
|
||||
|
||||
if ($response->successful()) {
|
||||
return $response->json();
|
||||
} else {
|
||||
return [
|
||||
'status' => 'error',
|
||||
'message' => 'SMS sending failed: ' . $response->status(),
|
||||
'data' => $response->body()
|
||||
];
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return [
|
||||
'status' => 'error',
|
||||
'message' => 'SMS sending exception: ' . $e->getMessage(),
|
||||
'data' => null
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function formatPhoneForSms(string $phone): string
|
||||
{
|
||||
if (str_starts_with($phone, '+98')) {
|
||||
return '0' . substr($phone, 3);
|
||||
}
|
||||
return $phone;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Auth;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RegistrationService
|
||||
{
|
||||
public function createUser(array $data): User
|
||||
{
|
||||
return DB::transaction(function () use ($data) {
|
||||
$user = User::create([
|
||||
'username' => 'rdl_'.Str::random(10),
|
||||
'phone' => $data['phone'],
|
||||
'email' => $data['email'] ?? null,
|
||||
'password' => Hash::make($data['password'] ?? Str::random(12)),
|
||||
'level' => $data['level'],
|
||||
'fullname' => $data['fullname'] ?? null,
|
||||
'national_code' => $data['national_code'] ?? null,
|
||||
'clinic_name' => $data['clinic_name'] ?? null,
|
||||
'clinic_phone' => $data['clinic_phone'] ?? null,
|
||||
'province' => $data['province'] ?? null,
|
||||
'city' => $data['city'] ?? null,
|
||||
'address' => $data['address'] ?? null,
|
||||
'specialty' => $data['specialty'] ?? null,
|
||||
]);
|
||||
|
||||
return $user;
|
||||
});
|
||||
}
|
||||
|
||||
public function registerAndLogin(array $data): Authenticatable
|
||||
{
|
||||
$user = $this->createUser($data);
|
||||
|
||||
Auth::login($user);
|
||||
session()->regenerate();
|
||||
session()->forget('register_phone' , 'verified_phone' , 'otp_verified' , 'login_phone' , 'login_level' , 'available_levels');
|
||||
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace App\Services\Document;
|
||||
|
||||
use App\Models\Document;
|
||||
use RuntimeException;
|
||||
|
||||
class DocumentCodeService
|
||||
{
|
||||
public function generate(int $tries = 10): string
|
||||
{
|
||||
for ($i = 0; $i < $tries; $i++) {
|
||||
$code = str_pad((string) random_int(0, 999999), 6, '0', STR_PAD_LEFT);
|
||||
if (! Document::where('code', $code)->exists()) {
|
||||
return $code;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException('Unable to generate unique code');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Medium;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class FileStorageService
|
||||
{
|
||||
public function storeFile(UploadedFile $file, string $disk = 'public', string $directory = 'files'): Medium
|
||||
{
|
||||
$diskInstance = Storage::disk($disk);
|
||||
$filename = $this->generateUniqueFilename($file);
|
||||
$path = $directory . '/' . $filename;
|
||||
$visibility = $disk === 'public' ? 'public' : 'private';
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$diskInstance->putFileAs($directory, $file, $filename, ['visibility' => $visibility]);
|
||||
|
||||
$medium = Medium::create([
|
||||
'filename' => $filename,
|
||||
'disk' => $disk,
|
||||
'path' => $path,
|
||||
'url' => $visibility === 'public' ? Storage::disk('public')->url($path) : null,
|
||||
'size' => $file->getSize(),
|
||||
'mime_type' => $file->getMimeType(),
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
return $medium;
|
||||
} catch (\Throwable $e) {
|
||||
DB::rollBack();
|
||||
if ($diskInstance->exists($path)) {
|
||||
$diskInstance->delete($path);
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function moveToDisk(Medium $medium, string $newDisk): bool
|
||||
{
|
||||
if ($medium->disk->value === $newDisk) return true;
|
||||
|
||||
$old = Storage::disk($medium->disk->value);
|
||||
$new = Storage::disk($newDisk);
|
||||
|
||||
$stream = $old->readStream($medium->path);
|
||||
if ($stream === false) return false;
|
||||
|
||||
$new->put($medium->path, $stream);
|
||||
if (is_resource($stream)) fclose($stream);
|
||||
|
||||
if ($newDisk === 'public') {
|
||||
$new->setVisibility($medium->path, 'public');
|
||||
$medium->url = Storage::disk('public')->url($medium->path);
|
||||
} else {
|
||||
$medium->url = null;
|
||||
}
|
||||
|
||||
$old->delete($medium->path);
|
||||
$medium->disk = $newDisk;
|
||||
$medium->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function deleteMedium(Medium $medium): mixed
|
||||
{
|
||||
$disk = Storage::disk($medium->disk->value);
|
||||
if ($disk->exists($medium->path)) {
|
||||
$disk->delete($medium->path);
|
||||
}
|
||||
return $medium->delete();
|
||||
}
|
||||
|
||||
public function downloadFile(Medium $medium)
|
||||
{
|
||||
if (!$medium->isPrivate()) {
|
||||
abort(404, 'فایل مورد نظر یافت نشد.');
|
||||
}
|
||||
|
||||
if (!$medium->exists()) {
|
||||
abort(404, 'فایل مورد نظر یافت نشد.');
|
||||
}
|
||||
|
||||
return response()->download(
|
||||
$medium->getStorageDisk()->path($medium->path),
|
||||
$medium->filename
|
||||
);
|
||||
}
|
||||
|
||||
public function serveFile(Medium $medium)
|
||||
{
|
||||
if (!$medium->isPrivate()) {
|
||||
abort(404, 'فایل مورد نظر یافت نشد.');
|
||||
}
|
||||
|
||||
if (!$medium->exists()) {
|
||||
abort(404, 'فایل مورد نظر یافت نشد.');
|
||||
}
|
||||
|
||||
$file = $medium->getContents();
|
||||
$mimeType = $medium->mime_type;
|
||||
|
||||
if (!$mimeType) {
|
||||
$mimeType = mime_content_type($medium->getStorageDisk()->path($medium->path));
|
||||
}
|
||||
|
||||
return response($file, 200, [
|
||||
'Content-Type' => $mimeType,
|
||||
'Content-Disposition' => 'inline; filename="' . $medium->filename . '"'
|
||||
]);
|
||||
}
|
||||
|
||||
private function generateUniqueFilename(UploadedFile $file): string
|
||||
{
|
||||
$ext = $file->getClientOriginalExtension();
|
||||
$name = Str::slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME));
|
||||
return time() . '_' . Str::random(6) . '_' . $name . ($ext ? ".{$ext}" : '');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support\Converters;
|
||||
|
||||
class PersianToEnglish
|
||||
{
|
||||
public static function toEnglish(string $value): string
|
||||
{
|
||||
$persian = ['۰','۱','۲','۳','۴','۵','۶','۷','۸','۹'];
|
||||
$english = ['0','1','2','3','4','5','6','7','8','9'];
|
||||
|
||||
return str_replace($persian, $english, $value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
use Illuminate\Foundation\Application;
|
||||
use Symfony\Component\Console\Input\ArgvInput;
|
||||
|
||||
define('LARAVEL_START', microtime(true));
|
||||
|
||||
// Register the Composer autoloader...
|
||||
require __DIR__.'/vendor/autoload.php';
|
||||
|
||||
// Bootstrap Laravel and handle the command...
|
||||
/** @var Application $app */
|
||||
$app = require_once __DIR__.'/bootstrap/app.php';
|
||||
|
||||
$status = $app->handleCommand(new ArgvInput);
|
||||
|
||||
exit($status);
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Foundation\Configuration\Exceptions;
|
||||
use Illuminate\Foundation\Configuration\Middleware;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
return Application::configure(basePath: dirname(__DIR__))
|
||||
->withRouting(
|
||||
commands: __DIR__.'/../routes/console.php',
|
||||
health: '/up',
|
||||
using: function () {
|
||||
Route::middleware('web')
|
||||
->group(base_path('routes/web.php'));
|
||||
|
||||
Route::middleware('web')
|
||||
->prefix('admin')
|
||||
->name('admin.')
|
||||
->group(base_path('routes/admin.php'));
|
||||
},
|
||||
)
|
||||
->withMiddleware(function (Middleware $middleware) {
|
||||
$middleware->web([
|
||||
\App\Http\Middleware\HandleInertiaRequests::class,
|
||||
]);
|
||||
$middleware->alias([
|
||||
'check.permission' => \App\Http\Middleware\CheckPermission::class,
|
||||
'admin.access' => \App\Http\Middleware\EnsureAdminAccess::class,
|
||||
]);
|
||||
})
|
||||
->withExceptions(function (Exceptions $exceptions) {
|
||||
//
|
||||
})->create();
|
||||
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
App\Providers\AppServiceProvider::class,
|
||||
];
|
||||
@@ -0,0 +1,78 @@
|
||||
{
|
||||
"$schema": "https://getcomposer.org/schema.json",
|
||||
"name": "laravel/laravel",
|
||||
"type": "project",
|
||||
"description": "The skeleton application for the Laravel framework.",
|
||||
"keywords": ["laravel", "framework"],
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"php": "^8.2",
|
||||
"hekmatinasser/verta": "^8.5",
|
||||
"inertiajs/inertia-laravel": "^2.0",
|
||||
"laravel/framework": "^12.0",
|
||||
"laravel/tinker": "^2.10.1",
|
||||
"maatwebsite/excel": "^3.1",
|
||||
"spatie/laravel-permission": "^6.17",
|
||||
"tightenco/ziggy": "^2.5"
|
||||
},
|
||||
"require-dev": {
|
||||
"barryvdh/laravel-debugbar": "^3.16",
|
||||
"fakerphp/faker": "^1.23",
|
||||
"itsgoingd/clockwork": "^5.3",
|
||||
"laravel/pail": "^1.2.2",
|
||||
"laravel/pint": "^1.13",
|
||||
"laravel/sail": "^1.41",
|
||||
"mockery/mockery": "^1.6",
|
||||
"nunomaduro/collision": "^8.6",
|
||||
"phpunit/phpunit": "^11.5.3"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\": "app/",
|
||||
"Database\\Factories\\": "database/factories/",
|
||||
"Database\\Seeders\\": "database/seeders/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Tests\\": "tests/"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"post-autoload-dump": [
|
||||
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
|
||||
"@php artisan package:discover --ansi"
|
||||
],
|
||||
"post-update-cmd": [
|
||||
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
|
||||
],
|
||||
"post-root-package-install": [
|
||||
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
|
||||
],
|
||||
"post-create-project-cmd": [
|
||||
"@php artisan key:generate --ansi",
|
||||
"@php -r \"file_exists('database/database.sqlite') || touch('database/database.sqlite');\"",
|
||||
"@php artisan migrate --graceful --ansi"
|
||||
],
|
||||
"dev": [
|
||||
"Composer\\Config::disableProcessTimeout",
|
||||
"npx concurrently -c \"#93c5fd,#c4b5fd,#fb7185,#fdba74\" \"php artisan serve\" \"php artisan queue:listen --tries=1\" \"php artisan pail --timeout=0\" \"npm run dev\" --names=server,queue,logs,vite"
|
||||
]
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"dont-discover": []
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"optimize-autoloader": true,
|
||||
"preferred-install": "dist",
|
||||
"sort-packages": true,
|
||||
"allow-plugins": {
|
||||
"pestphp/pest-plugin": true,
|
||||
"php-http/discovery": true
|
||||
}
|
||||
},
|
||||
"minimum-stability": "stable",
|
||||
"prefer-stable": true
|
||||
}
|
||||
Generated
+9308
File diff suppressed because it is too large
Load Diff
+126
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value is the name of your application, which will be used when the
|
||||
| framework needs to place the application's name in a notification or
|
||||
| other UI elements where an application name needs to be displayed.
|
||||
|
|
||||
*/
|
||||
|
||||
'name' => env('APP_NAME', 'Laravel'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Environment
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value determines the "environment" your application is currently
|
||||
| running in. This may determine how you prefer to configure various
|
||||
| services the application utilizes. Set this in your ".env" file.
|
||||
|
|
||||
*/
|
||||
|
||||
'env' => env('APP_ENV', 'production'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Debug Mode
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When your application is in debug mode, detailed error messages with
|
||||
| stack traces will be shown on every error that occurs within your
|
||||
| application. If disabled, a simple generic error page is shown.
|
||||
|
|
||||
*/
|
||||
|
||||
'debug' => (bool) env('APP_DEBUG', false),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application URL
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This URL is used by the console to properly generate URLs when using
|
||||
| the Artisan command line tool. You should set this to the root of
|
||||
| the application so that it's available within Artisan commands.
|
||||
|
|
||||
*/
|
||||
|
||||
'url' => env('APP_URL', 'http://localhost'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Timezone
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the default timezone for your application, which
|
||||
| will be used by the PHP date and date-time functions. The timezone
|
||||
| is set to "UTC" by default as it is suitable for most use cases.
|
||||
|
|
||||
*/
|
||||
|
||||
'timezone' => 'Asia/Tehran',
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Application Locale Configuration
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The application locale determines the default locale that will be used
|
||||
| by Laravel's translation / localization methods. This option can be
|
||||
| set to any locale for which you plan to have translation strings.
|
||||
|
|
||||
*/
|
||||
|
||||
'locale' => env('APP_LOCALE', 'en'),
|
||||
|
||||
'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'),
|
||||
|
||||
'faker_locale' => env('APP_FAKER_LOCALE', 'en_US'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Encryption Key
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This key is utilized by Laravel's encryption services and should be set
|
||||
| to a random, 32 character string to ensure that all encrypted values
|
||||
| are secure. You should do this prior to deploying the application.
|
||||
|
|
||||
*/
|
||||
|
||||
'cipher' => 'AES-256-CBC',
|
||||
|
||||
'key' => env('APP_KEY'),
|
||||
|
||||
'previous_keys' => [
|
||||
...array_filter(
|
||||
explode(',', env('APP_PREVIOUS_KEYS', ''))
|
||||
),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Maintenance Mode Driver
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These configuration options determine the driver used to determine and
|
||||
| manage Laravel's "maintenance mode" status. The "cache" driver will
|
||||
| allow maintenance mode to be controlled across multiple machines.
|
||||
|
|
||||
| Supported drivers: "file", "cache"
|
||||
|
|
||||
*/
|
||||
|
||||
'maintenance' => [
|
||||
'driver' => env('APP_MAINTENANCE_DRIVER', 'file'),
|
||||
'store' => env('APP_MAINTENANCE_STORE', 'database'),
|
||||
],
|
||||
|
||||
];
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authentication Defaults
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option defines the default authentication "guard" and password
|
||||
| reset "broker" for your application. You may change these values
|
||||
| as required, but they're a perfect start for most applications.
|
||||
|
|
||||
*/
|
||||
|
||||
'defaults' => [
|
||||
'guard' => env('AUTH_GUARD', 'web'),
|
||||
'passwords' => env('AUTH_PASSWORD_BROKER', 'users'),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Authentication Guards
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Next, you may define every authentication guard for your application.
|
||||
| Of course, a great default configuration has been defined for you
|
||||
| which utilizes session storage plus the Eloquent User provider.
|
||||
|
|
||||
| All authentication guards have a User provider, which defines how the
|
||||
| users are actually retrieved out of your database or other storage
|
||||
| system used by the application. Typically, Eloquent is utilized.
|
||||
|
|
||||
| Supported: "session"
|
||||
|
|
||||
*/
|
||||
|
||||
'guards' => [
|
||||
'web' => [
|
||||
'driver' => 'session',
|
||||
'provider' => 'users',
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| User Providers
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| All authentication guards have a User provider, which defines how the
|
||||
| users are actually retrieved out of your database or other storage
|
||||
| system used by the application. Typically, Eloquent is utilized.
|
||||
|
|
||||
| If you have multiple User tables or models you may configure multiple
|
||||
| providers to represent the model / table. These providers may then
|
||||
| be assigned to any extra authentication guards you have defined.
|
||||
|
|
||||
| Supported: "database", "eloquent"
|
||||
|
|
||||
*/
|
||||
|
||||
'providers' => [
|
||||
'users' => [
|
||||
'driver' => 'eloquent',
|
||||
'model' => env('AUTH_MODEL', App\Models\User::class),
|
||||
],
|
||||
|
||||
// 'users' => [
|
||||
// 'driver' => 'database',
|
||||
// 'table' => 'users',
|
||||
// ],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Resetting Passwords
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These configuration options specify the behavior of Laravel's password
|
||||
| reset functionality, including the table utilized for token storage
|
||||
| and the User provider that is invoked to actually retrieve users.
|
||||
|
|
||||
| The expiry time is the number of minutes that each reset token will be
|
||||
| considered valid. This security feature keeps tokens short-lived so
|
||||
| they have less time to be guessed. You may change this as needed.
|
||||
|
|
||||
| The throttle setting is the number of seconds a User must wait before
|
||||
| generating more password reset tokens. This prevents the User from
|
||||
| quickly generating a very large amount of password reset tokens.
|
||||
|
|
||||
*/
|
||||
|
||||
'passwords' => [
|
||||
'users' => [
|
||||
'provider' => 'users',
|
||||
'table' => env('AUTH_PASSWORD_RESET_TOKEN_TABLE', 'password_reset_tokens'),
|
||||
'expire' => 60,
|
||||
'throttle' => 60,
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Password Confirmation Timeout
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may define the amount of seconds before a password confirmation
|
||||
| window expires and users are asked to re-enter their password via the
|
||||
| confirmation screen. By default, the timeout lasts for three hours.
|
||||
|
|
||||
*/
|
||||
|
||||
'password_timeout' => env('AUTH_PASSWORD_TIMEOUT', 10800),
|
||||
|
||||
];
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Cache Store
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default cache store that will be used by the
|
||||
| framework. This connection is utilized if another isn't explicitly
|
||||
| specified when running a cache operation inside the application.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('CACHE_STORE', 'database'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cache Stores
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may define all of the cache "stores" for your application as
|
||||
| well as their drivers. You may even define multiple stores for the
|
||||
| same cache driver to group types of items stored in your caches.
|
||||
|
|
||||
| Supported drivers: "array", "database", "file", "memcached",
|
||||
| "redis", "dynamodb", "octane", "null"
|
||||
|
|
||||
*/
|
||||
|
||||
'stores' => [
|
||||
|
||||
'array' => [
|
||||
'driver' => 'array',
|
||||
'serialize' => false,
|
||||
],
|
||||
|
||||
'database' => [
|
||||
'driver' => 'database',
|
||||
'connection' => env('DB_CACHE_CONNECTION'),
|
||||
'table' => env('DB_CACHE_TABLE', 'cache'),
|
||||
'lock_connection' => env('DB_CACHE_LOCK_CONNECTION'),
|
||||
'lock_table' => env('DB_CACHE_LOCK_TABLE'),
|
||||
],
|
||||
|
||||
'file' => [
|
||||
'driver' => 'file',
|
||||
'path' => storage_path('framework/cache/data'),
|
||||
'lock_path' => storage_path('framework/cache/data'),
|
||||
],
|
||||
|
||||
'memcached' => [
|
||||
'driver' => 'memcached',
|
||||
'persistent_id' => env('MEMCACHED_PERSISTENT_ID'),
|
||||
'sasl' => [
|
||||
env('MEMCACHED_USERNAME'),
|
||||
env('MEMCACHED_PASSWORD'),
|
||||
],
|
||||
'options' => [
|
||||
// Memcached::OPT_CONNECT_TIMEOUT => 2000,
|
||||
],
|
||||
'servers' => [
|
||||
[
|
||||
'host' => env('MEMCACHED_HOST', '127.0.0.1'),
|
||||
'port' => env('MEMCACHED_PORT', 11211),
|
||||
'weight' => 100,
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
'redis' => [
|
||||
'driver' => 'redis',
|
||||
'connection' => env('REDIS_CACHE_CONNECTION', 'cache'),
|
||||
'lock_connection' => env('REDIS_CACHE_LOCK_CONNECTION', 'default'),
|
||||
],
|
||||
|
||||
'dynamodb' => [
|
||||
'driver' => 'dynamodb',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
'table' => env('DYNAMODB_CACHE_TABLE', 'cache'),
|
||||
'endpoint' => env('DYNAMODB_ENDPOINT'),
|
||||
],
|
||||
|
||||
'octane' => [
|
||||
'driver' => 'octane',
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Cache Key Prefix
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When utilizing the APC, database, memcached, Redis, and DynamoDB cache
|
||||
| stores, there might be other applications using the same cache. For
|
||||
| that reason, you may prefix every cache key to avoid collisions.
|
||||
|
|
||||
*/
|
||||
|
||||
'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache_'),
|
||||
|
||||
];
|
||||
@@ -0,0 +1,174 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Database Connection Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify which of the database connections below you wish
|
||||
| to use as your default connection for database operations. This is
|
||||
| the connection which will be utilized unless another connection
|
||||
| is explicitly specified when you execute a query / statement.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('DB_CONNECTION', 'sqlite'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Database Connections
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Below are all of the database connections defined for your application.
|
||||
| An example configuration is provided for each database system which
|
||||
| is supported by Laravel. You're free to add / remove connections.
|
||||
|
|
||||
*/
|
||||
|
||||
'connections' => [
|
||||
|
||||
'sqlite' => [
|
||||
'driver' => 'sqlite',
|
||||
'url' => env('DB_URL'),
|
||||
'database' => env('DB_DATABASE', database_path('database.sqlite')),
|
||||
'prefix' => '',
|
||||
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
|
||||
'busy_timeout' => null,
|
||||
'journal_mode' => null,
|
||||
'synchronous' => null,
|
||||
],
|
||||
|
||||
'mysql' => [
|
||||
'driver' => 'mysql',
|
||||
'url' => env('DB_URL'),
|
||||
'host' => env('DB_HOST', '127.0.0.1'),
|
||||
'port' => env('DB_PORT', '3306'),
|
||||
'database' => env('DB_DATABASE', 'laravel'),
|
||||
'username' => env('DB_USERNAME', 'root'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'unix_socket' => env('DB_SOCKET', ''),
|
||||
'charset' => env('DB_CHARSET', 'utf8mb4'),
|
||||
'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
'strict' => true,
|
||||
'engine' => null,
|
||||
'options' => extension_loaded('pdo_mysql') ? array_filter([
|
||||
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
|
||||
]) : [],
|
||||
],
|
||||
|
||||
'mariadb' => [
|
||||
'driver' => 'mariadb',
|
||||
'url' => env('DB_URL'),
|
||||
'host' => env('DB_HOST', '127.0.0.1'),
|
||||
'port' => env('DB_PORT', '3306'),
|
||||
'database' => env('DB_DATABASE', 'laravel'),
|
||||
'username' => env('DB_USERNAME', 'root'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'unix_socket' => env('DB_SOCKET', ''),
|
||||
'charset' => env('DB_CHARSET', 'utf8mb4'),
|
||||
'collation' => env('DB_COLLATION', 'utf8mb4_unicode_ci'),
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
'strict' => true,
|
||||
'engine' => null,
|
||||
'options' => extension_loaded('pdo_mysql') ? array_filter([
|
||||
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
|
||||
]) : [],
|
||||
],
|
||||
|
||||
'pgsql' => [
|
||||
'driver' => 'pgsql',
|
||||
'url' => env('DB_URL'),
|
||||
'host' => env('DB_HOST', '127.0.0.1'),
|
||||
'port' => env('DB_PORT', '5432'),
|
||||
'database' => env('DB_DATABASE', 'laravel'),
|
||||
'username' => env('DB_USERNAME', 'root'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'charset' => env('DB_CHARSET', 'utf8'),
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
'search_path' => 'public',
|
||||
'sslmode' => 'prefer',
|
||||
],
|
||||
|
||||
'sqlsrv' => [
|
||||
'driver' => 'sqlsrv',
|
||||
'url' => env('DB_URL'),
|
||||
'host' => env('DB_HOST', 'localhost'),
|
||||
'port' => env('DB_PORT', '1433'),
|
||||
'database' => env('DB_DATABASE', 'laravel'),
|
||||
'username' => env('DB_USERNAME', 'root'),
|
||||
'password' => env('DB_PASSWORD', ''),
|
||||
'charset' => env('DB_CHARSET', 'utf8'),
|
||||
'prefix' => '',
|
||||
'prefix_indexes' => true,
|
||||
// 'encrypt' => env('DB_ENCRYPT', 'yes'),
|
||||
// 'trust_server_certificate' => env('DB_TRUST_SERVER_CERTIFICATE', 'false'),
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Migration Repository Table
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This table keeps track of all the migrations that have already run for
|
||||
| your application. Using this information, we can determine which of
|
||||
| the migrations on disk haven't actually been run on the database.
|
||||
|
|
||||
*/
|
||||
|
||||
'migrations' => [
|
||||
'table' => 'migrations',
|
||||
'update_date_on_publish' => true,
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Redis Databases
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Redis is an open source, fast, and advanced key-value store that also
|
||||
| provides a richer body of commands than a typical key-value system
|
||||
| such as Memcached. You may define your connection settings here.
|
||||
|
|
||||
*/
|
||||
|
||||
'redis' => [
|
||||
|
||||
'client' => env('REDIS_CLIENT', 'phpredis'),
|
||||
|
||||
'options' => [
|
||||
'cluster' => env('REDIS_CLUSTER', 'redis'),
|
||||
'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
|
||||
'persistent' => env('REDIS_PERSISTENT', false),
|
||||
],
|
||||
|
||||
'default' => [
|
||||
'url' => env('REDIS_URL'),
|
||||
'host' => env('REDIS_HOST', '127.0.0.1'),
|
||||
'username' => env('REDIS_USERNAME'),
|
||||
'password' => env('REDIS_PASSWORD'),
|
||||
'port' => env('REDIS_PORT', '6379'),
|
||||
'database' => env('REDIS_DB', '0'),
|
||||
],
|
||||
|
||||
'cache' => [
|
||||
'url' => env('REDIS_URL'),
|
||||
'host' => env('REDIS_HOST', '127.0.0.1'),
|
||||
'username' => env('REDIS_USERNAME'),
|
||||
'password' => env('REDIS_PASSWORD'),
|
||||
'port' => env('REDIS_PORT', '6379'),
|
||||
'database' => env('REDIS_CACHE_DB', '1'),
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Filesystem Disk
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the default filesystem disk that should be used
|
||||
| by the framework. The "local" disk, as well as a variety of cloud
|
||||
| based disks are available to your application for file storage.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('FILESYSTEM_DISK', 'local'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Filesystem Disks
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Below you may configure as many filesystem disks as necessary, and you
|
||||
| may even configure multiple disks for the same driver. Examples for
|
||||
| most supported storage drivers are configured here for reference.
|
||||
|
|
||||
| Supported drivers: "local", "ftp", "sftp", "s3"
|
||||
|
|
||||
*/
|
||||
|
||||
'disks' => [
|
||||
|
||||
'local' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app/private'),
|
||||
'serve' => true,
|
||||
'throw' => false,
|
||||
'report' => false,
|
||||
],
|
||||
|
||||
'public' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app/public'),
|
||||
'url' => env('APP_URL').'/storage',
|
||||
'visibility' => 'public',
|
||||
'throw' => false,
|
||||
'report' => false,
|
||||
],
|
||||
'private' => [
|
||||
'driver' => 'local',
|
||||
'root' => storage_path('app/private'),
|
||||
'url' => env('APP_URL').'/storage',
|
||||
'visibility' => 'private',
|
||||
'throw' => false,
|
||||
'report' => false,
|
||||
],
|
||||
|
||||
's3' => [
|
||||
'driver' => 's3',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION'),
|
||||
'bucket' => env('AWS_BUCKET'),
|
||||
'url' => env('AWS_URL'),
|
||||
'endpoint' => env('AWS_ENDPOINT'),
|
||||
'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
|
||||
'throw' => false,
|
||||
'report' => false,
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Symbolic Links
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure the symbolic links that will be created when the
|
||||
| `storage:link` Artisan command is executed. The array keys should be
|
||||
| the locations of the links and the values should be their targets.
|
||||
|
|
||||
*/
|
||||
|
||||
'links' => [
|
||||
public_path('storage') => storage_path('app/public'),
|
||||
],
|
||||
|
||||
];
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
use Monolog\Handler\NullHandler;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Handler\SyslogUdpHandler;
|
||||
use Monolog\Processor\PsrLogMessageProcessor;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Log Channel
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option defines the default log channel that is utilized to write
|
||||
| messages to your logs. The value provided here should match one of
|
||||
| the channels present in the list of "channels" configured below.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('LOG_CHANNEL', 'stack'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Deprecations Log Channel
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the log channel that should be used to log warnings
|
||||
| regarding deprecated PHP and library features. This allows you to get
|
||||
| your application ready for upcoming major versions of dependencies.
|
||||
|
|
||||
*/
|
||||
|
||||
'deprecations' => [
|
||||
'channel' => env('LOG_DEPRECATIONS_CHANNEL', 'null'),
|
||||
'trace' => env('LOG_DEPRECATIONS_TRACE', false),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Log Channels
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure the log channels for your application. Laravel
|
||||
| utilizes the Monolog PHP logging library, which includes a variety
|
||||
| of powerful log handlers and formatters that you're free to use.
|
||||
|
|
||||
| Available drivers: "single", "daily", "slack", "syslog",
|
||||
| "errorlog", "monolog", "custom", "stack"
|
||||
|
|
||||
*/
|
||||
|
||||
'channels' => [
|
||||
|
||||
'stack' => [
|
||||
'driver' => 'stack',
|
||||
'channels' => explode(',', env('LOG_STACK', 'single')),
|
||||
'ignore_exceptions' => false,
|
||||
],
|
||||
|
||||
'single' => [
|
||||
'driver' => 'single',
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'daily' => [
|
||||
'driver' => 'daily',
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'days' => env('LOG_DAILY_DAYS', 14),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'slack' => [
|
||||
'driver' => 'slack',
|
||||
'url' => env('LOG_SLACK_WEBHOOK_URL'),
|
||||
'username' => env('LOG_SLACK_USERNAME', 'Laravel Log'),
|
||||
'emoji' => env('LOG_SLACK_EMOJI', ':boom:'),
|
||||
'level' => env('LOG_LEVEL', 'critical'),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'papertrail' => [
|
||||
'driver' => 'monolog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'handler' => env('LOG_PAPERTRAIL_HANDLER', SyslogUdpHandler::class),
|
||||
'handler_with' => [
|
||||
'host' => env('PAPERTRAIL_URL'),
|
||||
'port' => env('PAPERTRAIL_PORT'),
|
||||
'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'),
|
||||
],
|
||||
'processors' => [PsrLogMessageProcessor::class],
|
||||
],
|
||||
|
||||
'stderr' => [
|
||||
'driver' => 'monolog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'handler' => StreamHandler::class,
|
||||
'handler_with' => [
|
||||
'stream' => 'php://stderr',
|
||||
],
|
||||
'formatter' => env('LOG_STDERR_FORMATTER'),
|
||||
'processors' => [PsrLogMessageProcessor::class],
|
||||
],
|
||||
|
||||
'syslog' => [
|
||||
'driver' => 'syslog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'facility' => env('LOG_SYSLOG_FACILITY', LOG_USER),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'errorlog' => [
|
||||
'driver' => 'errorlog',
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'replace_placeholders' => true,
|
||||
],
|
||||
|
||||
'null' => [
|
||||
'driver' => 'monolog',
|
||||
'handler' => NullHandler::class,
|
||||
],
|
||||
|
||||
'emergency' => [
|
||||
'path' => storage_path('logs/laravel.log'),
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
];
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Mailer
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option controls the default mailer that is used to send all email
|
||||
| messages unless another mailer is explicitly specified when sending
|
||||
| the message. All additional mailers can be configured within the
|
||||
| "mailers" array. Examples of each type of mailer are provided.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('MAIL_MAILER', 'log'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Mailer Configurations
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure all of the mailers used by your application plus
|
||||
| their respective settings. Several examples have been configured for
|
||||
| you and you are free to add your own as your application requires.
|
||||
|
|
||||
| Laravel supports a variety of mail "transport" drivers that can be used
|
||||
| when delivering an email. You may specify which one you're using for
|
||||
| your mailers below. You may also add additional mailers if needed.
|
||||
|
|
||||
| Supported: "smtp", "sendmail", "mailgun", "ses", "ses-v2",
|
||||
| "postmark", "resend", "log", "array",
|
||||
| "failover", "roundrobin"
|
||||
|
|
||||
*/
|
||||
|
||||
'mailers' => [
|
||||
|
||||
'smtp' => [
|
||||
'transport' => 'smtp',
|
||||
'scheme' => env('MAIL_SCHEME'),
|
||||
'url' => env('MAIL_URL'),
|
||||
'host' => env('MAIL_HOST', '127.0.0.1'),
|
||||
'port' => env('MAIL_PORT', 2525),
|
||||
'username' => env('MAIL_USERNAME'),
|
||||
'password' => env('MAIL_PASSWORD'),
|
||||
'timeout' => null,
|
||||
'local_domain' => env('MAIL_EHLO_DOMAIN', parse_url(env('APP_URL', 'http://localhost'), PHP_URL_HOST)),
|
||||
],
|
||||
|
||||
'ses' => [
|
||||
'transport' => 'ses',
|
||||
],
|
||||
|
||||
'postmark' => [
|
||||
'transport' => 'postmark',
|
||||
// 'message_stream_id' => env('POSTMARK_MESSAGE_STREAM_ID'),
|
||||
// 'client' => [
|
||||
// 'timeout' => 5,
|
||||
// ],
|
||||
],
|
||||
|
||||
'resend' => [
|
||||
'transport' => 'resend',
|
||||
],
|
||||
|
||||
'sendmail' => [
|
||||
'transport' => 'sendmail',
|
||||
'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -bs -i'),
|
||||
],
|
||||
|
||||
'log' => [
|
||||
'transport' => 'log',
|
||||
'channel' => env('MAIL_LOG_CHANNEL'),
|
||||
],
|
||||
|
||||
'array' => [
|
||||
'transport' => 'array',
|
||||
],
|
||||
|
||||
'failover' => [
|
||||
'transport' => 'failover',
|
||||
'mailers' => [
|
||||
'smtp',
|
||||
'log',
|
||||
],
|
||||
'retry_after' => 60,
|
||||
],
|
||||
|
||||
'roundrobin' => [
|
||||
'transport' => 'roundrobin',
|
||||
'mailers' => [
|
||||
'ses',
|
||||
'postmark',
|
||||
],
|
||||
'retry_after' => 60,
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Global "From" Address
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| You may wish for all emails sent by your application to be sent from
|
||||
| the same address. Here you may specify a name and address that is
|
||||
| used globally for all emails that are sent by your application.
|
||||
|
|
||||
*/
|
||||
|
||||
'from' => [
|
||||
'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
|
||||
'name' => env('MAIL_FROM_NAME', 'Example'),
|
||||
],
|
||||
|
||||
];
|
||||
@@ -0,0 +1,202 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
'models' => [
|
||||
|
||||
/*
|
||||
* When using the "HasPermissions" trait from this package, we need to know which
|
||||
* Eloquent model should be used to retrieve your permissions. Of course, it
|
||||
* is often just the "Permission" model but you may use whatever you like.
|
||||
*
|
||||
* The model you want to use as a Permission model needs to implement the
|
||||
* `Spatie\Permission\Contracts\Permission` contract.
|
||||
*/
|
||||
|
||||
'permission' => Spatie\Permission\Models\Permission::class,
|
||||
|
||||
/*
|
||||
* When using the "HasRoles" trait from this package, we need to know which
|
||||
* Eloquent model should be used to retrieve your roles. Of course, it
|
||||
* is often just the "Role" model but you may use whatever you like.
|
||||
*
|
||||
* The model you want to use as a Role model needs to implement the
|
||||
* `Spatie\Permission\Contracts\Role` contract.
|
||||
*/
|
||||
|
||||
'role' => Spatie\Permission\Models\Role::class,
|
||||
|
||||
],
|
||||
|
||||
'table_names' => [
|
||||
|
||||
/*
|
||||
* When using the "HasRoles" trait from this package, we need to know which
|
||||
* table should be used to retrieve your roles. We have chosen a basic
|
||||
* default value but you may easily change it to any table you like.
|
||||
*/
|
||||
|
||||
'roles' => 'roles',
|
||||
|
||||
/*
|
||||
* When using the "HasPermissions" trait from this package, we need to know which
|
||||
* table should be used to retrieve your permissions. We have chosen a basic
|
||||
* default value but you may easily change it to any table you like.
|
||||
*/
|
||||
|
||||
'permissions' => 'permissions',
|
||||
|
||||
/*
|
||||
* When using the "HasPermissions" trait from this package, we need to know which
|
||||
* table should be used to retrieve your models permissions. We have chosen a
|
||||
* basic default value but you may easily change it to any table you like.
|
||||
*/
|
||||
|
||||
'model_has_permissions' => 'model_has_permissions',
|
||||
|
||||
/*
|
||||
* When using the "HasRoles" trait from this package, we need to know which
|
||||
* table should be used to retrieve your models roles. We have chosen a
|
||||
* basic default value but you may easily change it to any table you like.
|
||||
*/
|
||||
|
||||
'model_has_roles' => 'model_has_roles',
|
||||
|
||||
/*
|
||||
* When using the "HasRoles" trait from this package, we need to know which
|
||||
* table should be used to retrieve your roles permissions. We have chosen a
|
||||
* basic default value but you may easily change it to any table you like.
|
||||
*/
|
||||
|
||||
'role_has_permissions' => 'role_has_permissions',
|
||||
],
|
||||
|
||||
'column_names' => [
|
||||
/*
|
||||
* Change this if you want to name the related pivots other than defaults
|
||||
*/
|
||||
'role_pivot_key' => null, // default 'role_id',
|
||||
'permission_pivot_key' => null, // default 'permission_id',
|
||||
|
||||
/*
|
||||
* Change this if you want to name the related model primary key other than
|
||||
* `model_id`.
|
||||
*
|
||||
* For example, this would be nice if your primary keys are all UUIDs. In
|
||||
* that case, name this `model_uuid`.
|
||||
*/
|
||||
|
||||
'model_morph_key' => 'model_id',
|
||||
|
||||
/*
|
||||
* Change this if you want to use the teams feature and your related model's
|
||||
* foreign key is other than `team_id`.
|
||||
*/
|
||||
|
||||
'team_foreign_key' => 'team_id',
|
||||
],
|
||||
|
||||
/*
|
||||
* When set to true, the method for checking permissions will be registered on the gate.
|
||||
* Set this to false if you want to implement custom logic for checking permissions.
|
||||
*/
|
||||
|
||||
'register_permission_check_method' => true,
|
||||
|
||||
/*
|
||||
* When set to true, Laravel\Octane\Events\OperationTerminated event listener will be registered
|
||||
* this will refresh permissions on every TickTerminated, TaskTerminated and RequestTerminated
|
||||
* NOTE: This should not be needed in most cases, but an Octane/Vapor combination benefited from it.
|
||||
*/
|
||||
'register_octane_reset_listener' => false,
|
||||
|
||||
/*
|
||||
* Events will fire when a role or permission is assigned/unassigned:
|
||||
* \Spatie\Permission\Events\RoleAttached
|
||||
* \Spatie\Permission\Events\RoleDetached
|
||||
* \Spatie\Permission\Events\PermissionAttached
|
||||
* \Spatie\Permission\Events\PermissionDetached
|
||||
*
|
||||
* To enable, set to true, and then create listeners to watch these events.
|
||||
*/
|
||||
'events_enabled' => false,
|
||||
|
||||
/*
|
||||
* Teams Feature.
|
||||
* When set to true the package implements teams using the 'team_foreign_key'.
|
||||
* If you want the migrations to register the 'team_foreign_key', you must
|
||||
* set this to true before doing the migration.
|
||||
* If you already did the migration then you must make a new migration to also
|
||||
* add 'team_foreign_key' to 'roles', 'model_has_roles', and 'model_has_permissions'
|
||||
* (view the latest version of this package's migration file)
|
||||
*/
|
||||
|
||||
'teams' => false,
|
||||
|
||||
/*
|
||||
* The class to use to resolve the permissions team id
|
||||
*/
|
||||
'team_resolver' => \Spatie\Permission\DefaultTeamResolver::class,
|
||||
|
||||
/*
|
||||
* Passport Client Credentials Grant
|
||||
* When set to true the package will use Passports Client to check permissions
|
||||
*/
|
||||
|
||||
'use_passport_client_credentials' => false,
|
||||
|
||||
/*
|
||||
* When set to true, the required permission names are added to exception messages.
|
||||
* This could be considered an information leak in some contexts, so the default
|
||||
* setting is false here for optimum safety.
|
||||
*/
|
||||
|
||||
'display_permission_in_exception' => false,
|
||||
|
||||
/*
|
||||
* When set to true, the required role names are added to exception messages.
|
||||
* This could be considered an information leak in some contexts, so the default
|
||||
* setting is false here for optimum safety.
|
||||
*/
|
||||
|
||||
'display_role_in_exception' => false,
|
||||
|
||||
/*
|
||||
* By default wildcard permission lookups are disabled.
|
||||
* See documentation to understand supported syntax.
|
||||
*/
|
||||
|
||||
'enable_wildcard_permission' => false,
|
||||
|
||||
/*
|
||||
* The class to use for interpreting wildcard permissions.
|
||||
* If you need to modify delimiters, override the class and specify its name here.
|
||||
*/
|
||||
// 'permission.wildcard_permission' => Spatie\Permission\WildcardPermission::class,
|
||||
|
||||
/* Cache-specific settings */
|
||||
|
||||
'cache' => [
|
||||
|
||||
/*
|
||||
* By default all permissions are cached for 24 hours to speed up performance.
|
||||
* When permissions or roles are updated the cache is flushed automatically.
|
||||
*/
|
||||
|
||||
'expiration_time' => \DateInterval::createFromDateString('24 hours'),
|
||||
|
||||
/*
|
||||
* The cache key used to store all permissions.
|
||||
*/
|
||||
|
||||
'key' => 'spatie.permission.cache',
|
||||
|
||||
/*
|
||||
* You may optionally indicate a specific cache driver to use for permission and
|
||||
* role caching using any of the `store` drivers listed in the cache.php config
|
||||
* file. Using 'default' here means to use the `default` set in cache.php.
|
||||
*/
|
||||
|
||||
'store' => 'default',
|
||||
],
|
||||
];
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Queue Connection Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Laravel's queue supports a variety of backends via a single, unified
|
||||
| API, giving you convenient access to each backend using identical
|
||||
| syntax for each. The default queue connection is defined below.
|
||||
|
|
||||
*/
|
||||
|
||||
'default' => env('QUEUE_CONNECTION', 'database'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Queue Connections
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may configure the connection options for every queue backend
|
||||
| used by your application. An example configuration is provided for
|
||||
| each backend supported by Laravel. You're also free to add more.
|
||||
|
|
||||
| Drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null"
|
||||
|
|
||||
*/
|
||||
|
||||
'connections' => [
|
||||
|
||||
'sync' => [
|
||||
'driver' => 'sync',
|
||||
],
|
||||
|
||||
'database' => [
|
||||
'driver' => 'database',
|
||||
'connection' => env('DB_QUEUE_CONNECTION'),
|
||||
'table' => env('DB_QUEUE_TABLE', 'jobs'),
|
||||
'queue' => env('DB_QUEUE', 'default'),
|
||||
'retry_after' => (int) env('DB_QUEUE_RETRY_AFTER', 90),
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
'beanstalkd' => [
|
||||
'driver' => 'beanstalkd',
|
||||
'host' => env('BEANSTALKD_QUEUE_HOST', 'localhost'),
|
||||
'queue' => env('BEANSTALKD_QUEUE', 'default'),
|
||||
'retry_after' => (int) env('BEANSTALKD_QUEUE_RETRY_AFTER', 90),
|
||||
'block_for' => 0,
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
'sqs' => [
|
||||
'driver' => 'sqs',
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'),
|
||||
'queue' => env('SQS_QUEUE', 'default'),
|
||||
'suffix' => env('SQS_SUFFIX'),
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
'redis' => [
|
||||
'driver' => 'redis',
|
||||
'connection' => env('REDIS_QUEUE_CONNECTION', 'default'),
|
||||
'queue' => env('REDIS_QUEUE', 'default'),
|
||||
'retry_after' => (int) env('REDIS_QUEUE_RETRY_AFTER', 90),
|
||||
'block_for' => null,
|
||||
'after_commit' => false,
|
||||
],
|
||||
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Job Batching
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The following options configure the database and table that store job
|
||||
| batching information. These options can be updated to any database
|
||||
| connection and table which has been defined by your application.
|
||||
|
|
||||
*/
|
||||
|
||||
'batching' => [
|
||||
'database' => env('DB_CONNECTION', 'sqlite'),
|
||||
'table' => 'job_batches',
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Failed Queue Jobs
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| These options configure the behavior of failed queue job logging so you
|
||||
| can control how and where failed jobs are stored. Laravel ships with
|
||||
| support for storing failed jobs in a simple file or in a database.
|
||||
|
|
||||
| Supported drivers: "database-uuids", "dynamodb", "file", "null"
|
||||
|
|
||||
*/
|
||||
|
||||
'failed' => [
|
||||
'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'),
|
||||
'database' => env('DB_CONNECTION', 'sqlite'),
|
||||
'table' => 'failed_jobs',
|
||||
],
|
||||
|
||||
];
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Third Party Services
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This file is for storing the credentials for third party services such
|
||||
| as Mailgun, Postmark, AWS and more. This file provides the de facto
|
||||
| location for this type of information, allowing packages to have
|
||||
| a conventional file to locate the various service credentials.
|
||||
|
|
||||
*/
|
||||
|
||||
'postmark' => [
|
||||
'token' => env('POSTMARK_TOKEN'),
|
||||
],
|
||||
|
||||
'ses' => [
|
||||
'key' => env('AWS_ACCESS_KEY_ID'),
|
||||
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
||||
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
||||
],
|
||||
|
||||
'resend' => [
|
||||
'key' => env('RESEND_KEY'),
|
||||
],
|
||||
|
||||
'slack' => [
|
||||
'notifications' => [
|
||||
'bot_user_oauth_token' => env('SLACK_BOT_USER_OAUTH_TOKEN'),
|
||||
'channel' => env('SLACK_BOT_USER_DEFAULT_CHANNEL'),
|
||||
],
|
||||
],
|
||||
|
||||
'iranpayamak' => [
|
||||
'api_url' => env('IRANPAYAMAK_SMS_API_URL', 'https://api.iranpayamak.com/ws/v1/sms/pattern'),
|
||||
'line_number' => env('IRANPAYAMAK_SMS_API_URL', '50002178584000'),
|
||||
'api_key' => env('IRANPAYAMAK_SMS_API_URL', 'jnCyVq4ein7uGsgIGjHsVRrWz0112IA2v2qbZMHq0kHtEXubsh'),
|
||||
|
||||
|
||||
'patterns' => [
|
||||
'verify_code' => 'EvYDvfcUSk',
|
||||
],
|
||||
],
|
||||
|
||||
];
|
||||
@@ -0,0 +1,217 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Default Session Driver
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option determines the default session driver that is utilized for
|
||||
| incoming requests. Laravel supports a variety of storage options to
|
||||
| persist session data. Database storage is a great default choice.
|
||||
|
|
||||
| Supported: "file", "cookie", "database", "apc",
|
||||
| "memcached", "redis", "dynamodb", "array"
|
||||
|
|
||||
*/
|
||||
|
||||
'driver' => env('SESSION_DRIVER', 'database'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Lifetime
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may specify the number of minutes that you wish the session
|
||||
| to be allowed to remain idle before it expires. If you want them
|
||||
| to expire immediately when the browser is closed then you may
|
||||
| indicate that via the expire_on_close configuration option.
|
||||
|
|
||||
*/
|
||||
|
||||
'lifetime' => (int) env('SESSION_LIFETIME', 120),
|
||||
|
||||
'expire_on_close' => env('SESSION_EXPIRE_ON_CLOSE', false),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Encryption
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option allows you to easily specify that all of your session data
|
||||
| should be encrypted before it's stored. All encryption is performed
|
||||
| automatically by Laravel and you may use the session like normal.
|
||||
|
|
||||
*/
|
||||
|
||||
'encrypt' => env('SESSION_ENCRYPT', false),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session File Location
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When utilizing the "file" session driver, the session files are placed
|
||||
| on disk. The default storage location is defined here; however, you
|
||||
| are free to provide another location where they should be stored.
|
||||
|
|
||||
*/
|
||||
|
||||
'files' => storage_path('framework/sessions'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Database Connection
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When using the "database" or "redis" session drivers, you may specify a
|
||||
| connection that should be used to manage these sessions. This should
|
||||
| correspond to a connection in your database configuration options.
|
||||
|
|
||||
*/
|
||||
|
||||
'connection' => env('SESSION_CONNECTION'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Database Table
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When using the "database" session driver, you may specify the table to
|
||||
| be used to store sessions. Of course, a sensible default is defined
|
||||
| for you; however, you're welcome to change this to another table.
|
||||
|
|
||||
*/
|
||||
|
||||
'table' => env('SESSION_TABLE', 'sessions'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cache Store
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| When using one of the framework's cache driven session backends, you may
|
||||
| define the cache store which should be used to store the session data
|
||||
| between requests. This must match one of your defined cache stores.
|
||||
|
|
||||
| Affects: "apc", "dynamodb", "memcached", "redis"
|
||||
|
|
||||
*/
|
||||
|
||||
'store' => env('SESSION_STORE'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Sweeping Lottery
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Some session drivers must manually sweep their storage location to get
|
||||
| rid of old sessions from storage. Here are the chances that it will
|
||||
| happen on a given request. By default, the odds are 2 out of 100.
|
||||
|
|
||||
*/
|
||||
|
||||
'lottery' => [2, 100],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cookie Name
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here you may change the name of the session cookie that is created by
|
||||
| the framework. Typically, you should not need to change this value
|
||||
| since doing so does not grant a meaningful security improvement.
|
||||
|
|
||||
*/
|
||||
|
||||
'cookie' => env(
|
||||
'SESSION_COOKIE',
|
||||
Str::slug(env('APP_NAME', 'laravel'), '_').'_session'
|
||||
),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cookie Path
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| The session cookie path determines the path for which the cookie will
|
||||
| be regarded as available. Typically, this will be the root path of
|
||||
| your application, but you're free to change this when necessary.
|
||||
|
|
||||
*/
|
||||
|
||||
'path' => env('SESSION_PATH', '/'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Session Cookie Domain
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This value determines the domain and subdomains the session cookie is
|
||||
| available to. By default, the cookie will be available to the root
|
||||
| domain and all subdomains. Typically, this shouldn't be changed.
|
||||
|
|
||||
*/
|
||||
|
||||
'domain' => env('SESSION_DOMAIN'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| HTTPS Only Cookies
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| By setting this option to true, session cookies will only be sent back
|
||||
| to the server if the browser has a HTTPS connection. This will keep
|
||||
| the cookie from being sent to you when it can't be done securely.
|
||||
|
|
||||
*/
|
||||
|
||||
'secure' => env('SESSION_SECURE_COOKIE'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| HTTP Access Only
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Setting this value to true will prevent JavaScript from accessing the
|
||||
| value of the cookie and the cookie will only be accessible through
|
||||
| the HTTP protocol. It's unlikely you should disable this option.
|
||||
|
|
||||
*/
|
||||
|
||||
'http_only' => env('SESSION_HTTP_ONLY', true),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Same-Site Cookies
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| This option determines how your cookies behave when cross-site requests
|
||||
| take place, and can be used to mitigate CSRF attacks. By default, we
|
||||
| will set this value to "lax" to permit secure cross-site requests.
|
||||
|
|
||||
| See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#samesitesamesite-value
|
||||
|
|
||||
| Supported: "lax", "strict", "none", null
|
||||
|
|
||||
*/
|
||||
|
||||
'same_site' => env('SESSION_SAME_SITE', 'lax'),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Partitioned Cookies
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Setting this value to true will tie the cookie to the top-level site for
|
||||
| a cross-site context. Partitioned cookies are accepted by the browser
|
||||
| when flagged "secure" and the Same-Site attribute is set to "none".
|
||||
|
|
||||
*/
|
||||
|
||||
'partitioned' => env('SESSION_PARTITIONED_COOKIE', false),
|
||||
|
||||
];
|
||||
@@ -0,0 +1 @@
|
||||
*.sqlite*
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Document;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\DocumentAssignment>
|
||||
*/
|
||||
class DocumentAssignmentFactory extends Factory
|
||||
{
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'document_id' => Document::factory(),
|
||||
'user_id' => User::factory(),
|
||||
'role' => fake()->randomElement(['رادیولوژیست', 'پزشک', 'تکنسین', 'سرپرست']),
|
||||
];
|
||||
}
|
||||
|
||||
public function radiologist(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'role' => 'رادیولوژیست',
|
||||
]);
|
||||
}
|
||||
|
||||
public function doctor(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'role' => 'پزشک',
|
||||
]);
|
||||
}
|
||||
|
||||
public function technician(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'role' => 'تکنسین',
|
||||
]);
|
||||
}
|
||||
|
||||
public function supervisor(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'role' => 'سرپرست',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\DocumentStatusEnum;
|
||||
use App\Enums\DocumentPriorityEnum;
|
||||
use App\Models\Pet;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Document>
|
||||
*/
|
||||
class DocumentFactory extends Factory
|
||||
{
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'code' => fake()->unique()->numberBetween(100000, 999999),
|
||||
'modality' => fake()->randomElement(['CT', 'MRI', 'X-Ray', 'Ultrasound', 'PET']),
|
||||
'status' => fake()->randomElement(DocumentStatusEnum::cases()),
|
||||
'priority' => fake()->randomElement(DocumentPriorityEnum::cases()),
|
||||
'note' => fake()->optional()->sentence(),
|
||||
'submitted_at' => fake()->optional()->dateTimeBetween('-30 days', 'now'),
|
||||
'scan_date' => fake()->optional()->dateTimeBetween('-30 days', 'now'),
|
||||
'processing_deadline' => fake()->optional()->dateTimeBetween('now', '+30 days'),
|
||||
'finalized_at' => fake()->optional()->dateTimeBetween('-30 days', 'now'),
|
||||
'finalized_by' => fake()->optional()->randomElement(User::pluck('id')->toArray()),
|
||||
'rejection_reason' => fake()->optional()->sentence(),
|
||||
'pet_id' => Pet::factory(),
|
||||
'requester_id' => User::factory(),
|
||||
];
|
||||
}
|
||||
|
||||
public function registered(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => DocumentStatusEnum::Registered,
|
||||
'submitted_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function inProgress(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => DocumentStatusEnum::InProgress,
|
||||
'submitted_at' => fake()->dateTimeBetween('-7 days', 'now'),
|
||||
'scan_date' => fake()->dateTimeBetween('-7 days', 'now'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function completed(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => DocumentStatusEnum::Completed,
|
||||
'submitted_at' => fake()->dateTimeBetween('-30 days', '-7 days'),
|
||||
'scan_date' => fake()->dateTimeBetween('-30 days', '-7 days'),
|
||||
'finalized_at' => fake()->dateTimeBetween('-7 days', 'now'),
|
||||
'finalized_by' => User::factory(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function rejected(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => DocumentStatusEnum::Rejected,
|
||||
'submitted_at' => fake()->dateTimeBetween('-30 days', '-7 days'),
|
||||
'rejection_reason' => fake()->sentence(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function high(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'priority' => DocumentPriorityEnum::High,
|
||||
]);
|
||||
}
|
||||
|
||||
public function medium(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'priority' => DocumentPriorityEnum::Medium,
|
||||
'processing_deadline' => fake()->dateTimeBetween('now', '+3 days'),
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\MediaCollectionEnum;
|
||||
use App\Models\Document;
|
||||
use App\Models\Medium;
|
||||
use App\Models\Report;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\MediaAssignment>
|
||||
*/
|
||||
class MediaAssignmentFactory extends Factory
|
||||
{
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
$mediableType = fake()->randomElement([Document::class, Report::class]);
|
||||
|
||||
return [
|
||||
'media_id' => Medium::factory(),
|
||||
'mediable_id' => $mediableType::factory(),
|
||||
'mediable_type' => $mediableType,
|
||||
'collection' => fake()->randomElement(MediaCollectionEnum::cases()),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function forDocument(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'mediable_id' => Document::factory(),
|
||||
'mediable_type' => Document::class,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function forReport(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'mediable_id' => Report::factory(),
|
||||
'mediable_type' => Report::class,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function primary(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'collection' => MediaCollectionEnum::Primary,
|
||||
]);
|
||||
}
|
||||
|
||||
public function history(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'collection' => MediaCollectionEnum::History,
|
||||
]);
|
||||
}
|
||||
|
||||
public function attachments(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'collection' => MediaCollectionEnum::Attachments,
|
||||
]);
|
||||
}
|
||||
|
||||
public function thumbnails(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'collection' => MediaCollectionEnum::Thumbnails,
|
||||
]);
|
||||
}
|
||||
|
||||
public function documents(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'collection' => MediaCollectionEnum::Documents,
|
||||
]);
|
||||
}
|
||||
|
||||
public function images(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'collection' => MediaCollectionEnum::Images,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\MediaDiskEnum;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Medium>
|
||||
*/
|
||||
class MediumFactory extends Factory
|
||||
{
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
$filename = fake()->word() . '.' . fake()->fileExtension();
|
||||
$disk = fake()->randomElement(MediaDiskEnum::cases());
|
||||
$path = 'uploads/' . fake()->date('Y/m/d') . '/' . $filename;
|
||||
|
||||
return [
|
||||
'filename' => $filename,
|
||||
'disk' => $disk,
|
||||
'path' => $path,
|
||||
'size' => fake()->numberBetween(1024, 10485760),
|
||||
'url' => fake()->optional()->url(),
|
||||
'mime_type' => fake()->mimeType(),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function public(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'disk' => MediaDiskEnum::Public,
|
||||
'url' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function private(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'disk' => MediaDiskEnum::Private,
|
||||
'url' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function image(): static
|
||||
{
|
||||
$imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
|
||||
$extension = fake()->randomElement($imageExtensions);
|
||||
$filename = fake()->word() . '.' . $extension;
|
||||
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'filename' => $filename,
|
||||
'mime_type' => 'image/' . $extension,
|
||||
'size' => fake()->numberBetween(102400, 5242880),
|
||||
]);
|
||||
}
|
||||
|
||||
public function document(): static
|
||||
{
|
||||
$docExtensions = ['pdf', 'doc', 'docx', 'txt'];
|
||||
$extension = fake()->randomElement($docExtensions);
|
||||
$filename = fake()->word() . '.' . $extension;
|
||||
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'filename' => $filename,
|
||||
'mime_type' => $extension === 'pdf' ? 'application/pdf' : 'application/msword',
|
||||
'size' => fake()->numberBetween(51200, 10485760),
|
||||
]);
|
||||
}
|
||||
|
||||
public function small(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'size' => fake()->numberBetween(1024, 102400),
|
||||
]);
|
||||
}
|
||||
|
||||
public function large(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'size' => fake()->numberBetween(5242880, 52428800),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\PetTypeEnum;
|
||||
use App\Enums\PetGenderEnum;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Pet>
|
||||
*/
|
||||
class PetFactory extends Factory
|
||||
{
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->firstName(),
|
||||
'type' => fake()->randomElement(PetTypeEnum::cases()),
|
||||
'gender' => fake()->randomElement(PetGenderEnum::cases()),
|
||||
'breed' => fake()->word(),
|
||||
'weight' => fake()->numberBetween(1, 50),
|
||||
'sterilized' => fake()->boolean(),
|
||||
'birthday' => fake()->dateTimeBetween('-15 years', '-1 year'),
|
||||
'owner_id' => User::factory(),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function dog(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'type' => PetTypeEnum::Dog,
|
||||
'breed' => fake()->randomElement(['ژرمن شپرد', 'گلدن رتریور', 'لابادور', 'بولداگ', 'پودل']),
|
||||
]);
|
||||
}
|
||||
|
||||
public function cat(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'type' => PetTypeEnum::Cat,
|
||||
'breed' => fake()->randomElement(['پرشین', 'سیامی', 'مین کون', 'رگدال', 'بنگال']),
|
||||
]);
|
||||
}
|
||||
|
||||
public function male(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'gender' => PetGenderEnum::Male,
|
||||
]);
|
||||
}
|
||||
|
||||
public function female(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'gender' => PetGenderEnum::Female,
|
||||
]);
|
||||
}
|
||||
|
||||
public function sterilized(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'sterilized' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user