Init
This commit is contained in:
9
Career/Others/AWS Cheatsheet.md
Normal file
9
Career/Others/AWS Cheatsheet.md
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
created: 2025-01-09 13:45
|
||||
updated: 2025-07-04 07:19
|
||||
---
|
||||
### Export a hosted zone from Route53
|
||||
```bash
|
||||
aws route53 list-resource-record-sets --hosted-zone-id {{zone-id}} --output json > zone.json
|
||||
```
|
||||
#Snippets #AWS
|
||||
7
Career/Others/Apache.md
Normal file
7
Career/Others/Apache.md
Normal file
@@ -0,0 +1,7 @@
|
||||
## Block Bots / User Agents
|
||||
```
|
||||
RewriteEngine On
|
||||
RewriteCond %{HTTP_USER_AGENT} (Amazonbot|SemrushBot|meta-externalagent|Bytespider) [NC]
|
||||
RewriteRule .* - [R=503,L]
|
||||
|
||||
```
|
||||
51
Career/Others/Audit Dependencies Command.md
Normal file
51
Career/Others/Audit Dependencies Command.md
Normal file
@@ -0,0 +1,51 @@
|
||||
---
|
||||
created: 2025-07-03 10:20
|
||||
updated: 2025-07-04 07:26
|
||||
tags:
|
||||
- Laravel
|
||||
- Snippets
|
||||
---
|
||||
|
||||
```bash
|
||||
php artisan make:command AuditDependenciesCommand
|
||||
```
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Process;
|
||||
use Spatie\FlareClient\Enums\MessageLevels;
|
||||
use Spatie\LaravelIgnition\Facades\Flare;
|
||||
|
||||
class AuditDependenciesCommand extends Command
|
||||
{
|
||||
protected $signature = 'app:audit-dependencies';
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$composer = Process::run('composer audit');
|
||||
|
||||
if (!blank($composer->output())) {
|
||||
$this->warn('Composer audit found vulnerabilities');
|
||||
Flare::glow('Composer audit found vulnerabilities', MessageLevels::WARNING, ['output' => $composer->output()]);
|
||||
Flare::report(new Exception('Composer audit found vulnerabilities'));
|
||||
}
|
||||
|
||||
$npm = Process::run('npm audit');
|
||||
|
||||
if (trim($npm->output()) !== "found 0 vulnerabilities") {
|
||||
$this->warn('NPM audit found vulnerabilities');
|
||||
Flare::glow('NPM audit found vulnerabilities', MessageLevels::WARNING, ['output' => $npm->output()]);
|
||||
Flare::report(new Exception('NPM audit found vulnerabilities'));
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```php in kernel
|
||||
$schedule->command(\App\Console\Commands\AuditDependenciesCommand::class)->daily();
|
||||
```
|
||||
47
Career/Others/Audit Dependencies/Audit Dependencies.md
Normal file
47
Career/Others/Audit Dependencies/Audit Dependencies.md
Normal file
@@ -0,0 +1,47 @@
|
||||
---
|
||||
created: 2025-07-09 10:20
|
||||
updated: 2025-07-09 10:20
|
||||
---
|
||||
```bash
|
||||
php artisan make:command AuditDependenciesCommand
|
||||
```
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Process;
|
||||
use Spatie\LaravelIgnition\Facades\Flare;
|
||||
|
||||
class AuditDependenciesCommand extends Command
|
||||
{
|
||||
protected $signature = 'app:audit-dependencies';
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$composer = Process::run('composer audit');
|
||||
|
||||
if (!blank($composer->output())) {
|
||||
$this->warn('Composer audit found vulnerabilities');
|
||||
Log::warning('Composer audit found vulnerabilities', ['output' => $composer->output()]);
|
||||
Flare::report(new Exception('Composer audit found vulnerabilities'));
|
||||
}
|
||||
|
||||
$npm = Process::run('npm audit');
|
||||
|
||||
if (trim($npm->output()) !== "found 0 vulnerabilities") {
|
||||
$this->warn('NPM audit found vulnerabilities');
|
||||
Log::warning('NPM audit found vulnerabilities', ['output' => $npm->output()]);
|
||||
Flare::report(new Exception('NPM audit found vulnerabilities'));
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```php kernel
|
||||
$schedule->command(\App\Console\Commands\AuditDependenciesCommand::class)->daily();
|
||||
```
|
||||
36
Career/Others/Css Stricksa.md
Normal file
36
Career/Others/Css Stricksa.md
Normal file
@@ -0,0 +1,36 @@
|
||||
|
||||
|
||||
h-[1lh]
|
||||
|
||||
Tap size target add absolute span in button next to the svg / icon
|
||||
``` html
|
||||
<span class="absolute top-1/2 left-1/2 -translate-1/2 size-12 [@media(pointer:fine)]:hidden"></span>
|
||||
```
|
||||
|
||||
scrollable table
|
||||
|
||||
``` html
|
||||
<div class="-mx-parent flex margin-whatever overflow-x-auto">
|
||||
<div class="px-parent grow">
|
||||
<table class="min-w-full whitescape-nowrap">
|
||||
// Bla
|
||||
<table/>
|
||||
</div>
|
||||
</div>
|
||||
```
|
||||
Easier if there is a css variable of page padding
|
||||
|
||||
Grid stuff
|
||||
|
||||
```html
|
||||
|
||||
<div class="grid grid-cols-[auto_1fr]">
|
||||
<a class="col-span-2 grid grid-cols-subgrid">
|
||||
<icon class="mr-2" />
|
||||
<label />
|
||||
</a>
|
||||
</div>
|
||||
|
||||
```
|
||||
|
||||
#css #frontend
|
||||
39
Career/Others/Css Tricks.md
Normal file
39
Career/Others/Css Tricks.md
Normal file
@@ -0,0 +1,39 @@
|
||||
---
|
||||
created: 2025-07-03 09:50
|
||||
updated: 2025-07-04 07:19
|
||||
---
|
||||
|
||||
|
||||
h-[1lh]
|
||||
|
||||
Tap size target add absolute span in button next to the svg / icon
|
||||
``` html
|
||||
<span class="absolute top-1/2 left-1/2 -translate-1/2 size-12 [@media(pointer:fine)]:hidden"></span>
|
||||
```
|
||||
|
||||
scrollable table
|
||||
|
||||
``` html
|
||||
<div class="-mx-parent flex margin-whatever overflow-x-auto">
|
||||
<div class="px-parent grow">
|
||||
<table class="min-w-full whitescape-nowrap">
|
||||
// Bla
|
||||
<table/>
|
||||
</div>
|
||||
</div>
|
||||
```
|
||||
Easier if there is a css variable of page padding
|
||||
|
||||
Grid stuff
|
||||
|
||||
```html
|
||||
|
||||
<div class="grid grid-cols-[auto_1fr]">
|
||||
<a class="col-span-2 grid grid-cols-subgrid">
|
||||
<icon class="mr-2" />
|
||||
<label />
|
||||
</a>
|
||||
</div>
|
||||
|
||||
```
|
||||
#Snippets #CSS
|
||||
51
Career/Others/Deployment Hooks.md
Normal file
51
Career/Others/Deployment Hooks.md
Normal file
@@ -0,0 +1,51 @@
|
||||
---
|
||||
created: 2025-02-24 13:13
|
||||
updated: 2025-07-04 07:20
|
||||
---
|
||||
|
||||
|
||||
### Clone New Release
|
||||
### Install Composer Dependencies
|
||||
|
||||
### NPM
|
||||
|
||||
```bash
|
||||
cd {{ release }}
|
||||
|
||||
echo {{ sha }} >> commit_hash.txt
|
||||
|
||||
php artisan ziggy:generate
|
||||
# php artisan translation:generate-vue
|
||||
|
||||
nice -n 19 npm ci
|
||||
nice -n 19 npm run build
|
||||
```
|
||||
|
||||
|
||||
### Activate New Release
|
||||
|
||||
### Artisan
|
||||
``` bash
|
||||
cd {{ release }}
|
||||
|
||||
php artisan optimize:clear
|
||||
php artisan horizon:terminate
|
||||
|
||||
php artisan migrate --force
|
||||
|
||||
php artisan optimize
|
||||
php artisan filament:optimize
|
||||
|
||||
# php artisan generate:sitemap
|
||||
# php artisan l5-swagger:generate
|
||||
```
|
||||
|
||||
### Purge Old Releases
|
||||
|
||||
### Run Deployment Operations
|
||||
```bash
|
||||
cd {{ release }}
|
||||
|
||||
php artisan operations
|
||||
```
|
||||
#Laravel #Deployments
|
||||
10
Career/Others/Deployment Operations.md
Normal file
10
Career/Others/Deployment Operations.md
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
created: 2025-02-24 09:57
|
||||
updated: 2025-07-04 07:24
|
||||
tags:
|
||||
- Laravel/Packages
|
||||
---
|
||||
```bash
|
||||
composer require dragon-code/laravel-deploy-operations && php artisan vendor:publish --tag=config --provider="DragonCode\LaravelDeployOperations\ServiceProvider"
|
||||
```
|
||||
#Laravel/Packages
|
||||
153
Career/Others/Eslint.md
Normal file
153
Career/Others/Eslint.md
Normal file
@@ -0,0 +1,153 @@
|
||||
---
|
||||
created: 2025-02-24 09:46
|
||||
updated: 2025-07-04 07:24
|
||||
tags:
|
||||
- BuildTools
|
||||
---
|
||||
|
||||
```bash
|
||||
npm uninstall @typescript-eslint/eslint-plugin eslint-plugin-unused-imports eslint-plugin-vue eslint eslint-plugin-tailwindcss eslint-plugin-vue eslint-plugin-no-relative-import-paths eslint-config-prettier prettier prettier-plugin-organize-imports prettier-plugin-tailwindcss typescript-eslint @vue/eslint-config-typescript @eslint/js
|
||||
```
|
||||
|
||||
|
||||
```bash
|
||||
npm install -D eslint @typescript-eslint/eslint-plugin eslint-plugin-no-relative-import-paths eslint-plugin-unused-imports eslint-plugin-tailwindcss eslint-plugin-vue globals @eslint/js @eslint/eslintrc @vue/eslint-config-typescript @eslint/js
|
||||
|
||||
```
|
||||
|
||||
```bash
|
||||
npx @eslint/migrate-config .eslintrc.json
|
||||
```
|
||||
|
||||
```js eslint.config.js
|
||||
import vue from "eslint-plugin-vue";
|
||||
import unusedImports from "eslint-plugin-unused-imports";
|
||||
import noRelativeImportPaths from 'eslint-plugin-no-relative-import-paths';
|
||||
import {defineConfigWithVueTs, vueTsConfigs} from '@vue/eslint-config-typescript';
|
||||
import tailwind from "eslint-plugin-tailwindcss";
|
||||
|
||||
export default defineConfigWithVueTs(
|
||||
vue.configs['flat/recommended'],
|
||||
tailwind.configs["flat/recommended"],
|
||||
vueTsConfigs.recommended,
|
||||
{
|
||||
ignores: ['vendor', 'node_modules', 'public', 'bootstrap/ssr', 'tailwind.config.js', 'resources/js/components/ui/*'],
|
||||
},
|
||||
{
|
||||
rules: {
|
||||
'vue/html-indent': ['error', 4, {
|
||||
attribute: 1,
|
||||
baseIndent: 1,
|
||||
closeBracket: 0,
|
||||
alignAttributesVertically: true,
|
||||
ignores: [],
|
||||
}],
|
||||
'vue/block-lang': 'off',
|
||||
'vue/multi-word-component-names': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
"linebreak-style": ["error", "unix"],
|
||||
"tailwindcss/no-custom-classname": "off",
|
||||
"vue/no-mutating-props": "off",
|
||||
"vue/prop-name-casing": "off",
|
||||
"vue/no-setup-props-destructure": "off",
|
||||
"vue/require-default-prop": "off"
|
||||
},
|
||||
},
|
||||
{
|
||||
plugins: {
|
||||
"unused-imports": unusedImports,
|
||||
},
|
||||
},
|
||||
{
|
||||
plugins: {
|
||||
'no-relative-import-paths': noRelativeImportPaths,
|
||||
},
|
||||
rules: {
|
||||
"no-relative-import-paths/no-relative-import-paths": [
|
||||
"warn",
|
||||
{
|
||||
"allowSameFolder": false,
|
||||
"rootDir": "resources/js",
|
||||
"prefix": "@"
|
||||
}
|
||||
],
|
||||
|
||||
},
|
||||
},
|
||||
{
|
||||
settings: {
|
||||
tailwindcss: {
|
||||
config: './tailwind.config.js',
|
||||
callees: ["classnames", "clsx", "ctl", 'twMerge'],
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
"tailwindcss/no-custom-classname": "off",
|
||||
}
|
||||
},
|
||||
);
|
||||
```
|
||||
|
||||
```js .eslintrc.json
|
||||
{
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es2021": true,
|
||||
"node": true
|
||||
},
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:vue/vue3-recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:tailwindcss/recommended"
|
||||
],
|
||||
"overrides": [],
|
||||
"parser": "vue-eslint-parser",
|
||||
"parserOptions": {
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"ecmaVersion": "latest",
|
||||
"sourceType": "module"
|
||||
},
|
||||
"plugins": [
|
||||
"vue",
|
||||
"@typescript-eslint",
|
||||
"unused-imports",
|
||||
"no-relative-import-paths"
|
||||
],
|
||||
"rules": {
|
||||
"linebreak-style": [
|
||||
"error",
|
||||
"unix"
|
||||
],
|
||||
"vue/multi-word-component-names": "off",
|
||||
"tailwindcss/no-custom-classname": "off",
|
||||
"vue/html-indent": [
|
||||
"error",
|
||||
4,
|
||||
{
|
||||
"attribute": 1,
|
||||
"baseIndent": 1,
|
||||
"closeBracket": 0,
|
||||
"alignAttributesVertically": true,
|
||||
"ignores": []
|
||||
}
|
||||
],
|
||||
"vue/require-default-prop": "off",
|
||||
"vue/no-mutating-props": "off",
|
||||
"no-relative-import-paths/no-relative-import-paths": [
|
||||
"warn",
|
||||
{
|
||||
"allowSameFolder": false,
|
||||
"rootDir": "resources/js",
|
||||
"prefix": "@"
|
||||
}
|
||||
],
|
||||
"vue/prop-name-casing": "off",
|
||||
"vue/no-setup-props-destructure": "off"
|
||||
},
|
||||
"ignorePatterns": [
|
||||
"**/vue-i18n-locales.generated.js",
|
||||
"**/ziggy.js"
|
||||
]
|
||||
}
|
||||
```
|
||||
108
Career/Others/Flare/Flare.md
Normal file
108
Career/Others/Flare/Flare.md
Normal file
@@ -0,0 +1,108 @@
|
||||
---
|
||||
created: 2025-02-12 12:01
|
||||
updated: 2025-07-04 07:27
|
||||
tags:
|
||||
- Laravel/Packages
|
||||
---
|
||||
# Install / update
|
||||
```bash
|
||||
npm uninstall @flareapp/flare-client @flareapp/flare-vue @flareapp/js @flareapp/vite @flareapp/vite-plugin-sourcemap-uploader @flareapp/vue
|
||||
```
|
||||
|
||||
```bash
|
||||
npm install @flareapp/js @flareapp/vue @flareapp/vite
|
||||
```
|
||||
|
||||
```bash
|
||||
composer require spatie/laravel-activitylog spatie/laravel-ignition
|
||||
```
|
||||
|
||||
```js flare.js
|
||||
import {flare} from "@flareapp/js";
|
||||
|
||||
flare.beforeSubmit = (report) => {
|
||||
|
||||
// Filter out errors that are not useful
|
||||
if ([
|
||||
'Request failed with status code 401',
|
||||
'Network Error',
|
||||
'Failed to fetch dynamically imported module',
|
||||
'is not a valid JavaScript MIME type',
|
||||
'Unable to preload CSS',
|
||||
'Request aborted',
|
||||
'Importing a module script failed.',
|
||||
].some(v => report.message.includes(v))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Filter silly bots
|
||||
if ([
|
||||
'adsbot',
|
||||
'googlebot'
|
||||
].some(v => report.context.request.useragent.includes(v))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return report;
|
||||
};
|
||||
|
||||
export default flare;
|
||||
```
|
||||
|
||||
```js app.js
|
||||
import {flareVue} from "@flareapp/vue";
|
||||
import flare from './plugins/flare';
|
||||
|
||||
if (import.meta.env.PROD) {
|
||||
flare.light();
|
||||
}
|
||||
|
||||
// createApp()
|
||||
.use(flareVue)
|
||||
//. .mount(el)
|
||||
```
|
||||
|
||||
```js vite.config.js
|
||||
import flareSourcemapUploader from '@flareapp/vite';
|
||||
return {
|
||||
plugins: [
|
||||
// bla
|
||||
flareSourcemapUploader({
|
||||
key: env.VITE_FLARE_KEY,
|
||||
}),
|
||||
],
|
||||
};
|
||||
```
|
||||
|
||||
```php AppServiceProvider
|
||||
private function versionStuff(): void
|
||||
{
|
||||
\Illuminate\Support\Facades\App::macro('getVersion', function () {
|
||||
if (app()->isLocal()) {
|
||||
return time();
|
||||
}
|
||||
|
||||
if (file_exists(base_path('commit_hash.txt'))) {
|
||||
return trim(file_get_contents(base_path('commit_hash.txt')));
|
||||
}
|
||||
|
||||
return md5(base_path());
|
||||
});
|
||||
|
||||
\Illuminate\Support\Facades\Cache::macro('getVersion', function () {
|
||||
return app()->isLocal() ? time() : \Illuminate\Support\Facades\Cache::remember('version', now()->addDay(), fn() => App::getVersion());
|
||||
});
|
||||
|
||||
\Spatie\LaravelIgnition\Facades\Flare::determineVersionUsing(function () {
|
||||
return \Illuminate\Support\Facades\Cache::getVersion();
|
||||
});
|
||||
}
|
||||
|
||||
private function startLogBatch(): void
|
||||
{
|
||||
if (!\Spatie\Activitylog\Facades\LogBatch::isOpen()) {
|
||||
\Spatie\Activitylog\Facades\LogBatch::startBatch();
|
||||
\Illuminate\Support\Facades\Context::add('batch_uuid', \Spatie\Activitylog\Facades\LogBatch::getUuid());
|
||||
}
|
||||
}
|
||||
```
|
||||
8
Career/Others/Formkit/Formkit.md
Normal file
8
Career/Others/Formkit/Formkit.md
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
created: 2025-07-09 10:20
|
||||
updated: 2025-07-09 10:20
|
||||
---
|
||||
|
||||
``` bash
|
||||
npm install @formkit/vue
|
||||
```
|
||||
92
Career/Others/Horizon.md
Normal file
92
Career/Others/Horizon.md
Normal file
@@ -0,0 +1,92 @@
|
||||
---
|
||||
created: 2025-03-13 14:23
|
||||
updated: 2025-07-04 07:23
|
||||
tags:
|
||||
- Laravel/Packages
|
||||
---
|
||||
|
||||
``` bash
|
||||
php artisan make:command CheckStatusCommand && php artisan make:notification HorizonIsInactiveNotification
|
||||
```
|
||||
|
||||
``` php CheckStatusCommand
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Notifications\HorizonIsInactiveNotification;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Laravel\Horizon\Contracts\MasterSupervisorRepository;
|
||||
|
||||
class CheckStatusCommand extends Command
|
||||
{
|
||||
protected $description = 'Command description';
|
||||
protected $signature = 'horizon:check-status';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
if (!$this->shouldBeActive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->isHorizonActive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->error('Horizon is inactive on: ' . config('app.name'));
|
||||
|
||||
Flare::report(new Exception('Horizon is inactive'));
|
||||
|
||||
Notification::route('mail', 'dev@strixi.nl')
|
||||
->notify(new HorizonIsInactiveNotification());
|
||||
}
|
||||
|
||||
protected function isHorizonActive(): bool
|
||||
{
|
||||
if (!$masters = app(MasterSupervisorRepository::class)->all()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return collect($masters)->some(fn($master): bool => $master->status !== 'paused');
|
||||
}
|
||||
|
||||
protected function shouldBeActive(): bool
|
||||
{
|
||||
return config('queue.default') === 'redis';
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
``` php HorizonIsInactiveNotification
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class HorizonIsInactiveNotification extends Notification
|
||||
{
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
public function toMail(object $notifiable): MailMessage
|
||||
{
|
||||
return (new MailMessage)
|
||||
->subject('Horizon is inactive on: ' . config('app.name'))
|
||||
->line('Horizon is inactive on: ' . config('app.name'))
|
||||
->action('Goto site', url(config('app.url')));
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
``` php kernel or bootstrap
|
||||
$schedule->command(\App\Console\Commands\CheckStatusCommand::class)->everyFifteenMinutes();
|
||||
```
|
||||
11
Career/Others/Laravel relationships.md
Normal file
11
Career/Others/Laravel relationships.md
Normal file
@@ -0,0 +1,11 @@
|
||||
---
|
||||
created: 2025-02-06 11:23
|
||||
updated: 2025-07-04 07:36
|
||||
---
|
||||
### belongsToMany
|
||||
|
||||
Argument query
|
||||
belongsToMany($related, $table = null, $foreignPivotKey = null, $relatedPivotKey = null, $parentKey = null, $relatedKey = null, $relation = null)
|
||||
```mysql
|
||||
select `related_table`.*, `table`.`foreignPivotKey` as `pivot_foreignPivotKey`, `table`.`relatedPivotKey` as `pivot_relatedPivotKey` from `networks` inner join `table` on `networks`.`relatedKey` = `table`.`relatedPivotKey` where `table`.`foreignPivotKey` in (?) and `related_table`.`deleted_at` is null
|
||||
```
|
||||
86
Career/Others/Laravel tips.md
Normal file
86
Career/Others/Laravel tips.md
Normal file
@@ -0,0 +1,86 @@
|
||||
---
|
||||
created: 2025-01-31 10:42
|
||||
updated: 2025-07-04 07:36
|
||||
---
|
||||
### Dynamic Tenancy Scoping
|
||||
|
||||
BelongsToRelation Trait
|
||||
```php
|
||||
trait BelongsToRelation
|
||||
{
|
||||
public static function bootBelongsToRelation(): void
|
||||
{
|
||||
if (static::belongsDirectlyToRelation()) {
|
||||
static::addGlobalScope(new RelationScope());
|
||||
return;
|
||||
}
|
||||
|
||||
static::addGlobalScope(new RelationThroughScope());
|
||||
}
|
||||
|
||||
public static function belongsDirectlyToRelation(): bool
|
||||
{
|
||||
return !static::getRelationThroughRelationship();
|
||||
}
|
||||
|
||||
abstract public static function getRelationThroughRelationship(): ?string;
|
||||
|
||||
public function relation(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Relation::class);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
RelationScope
|
||||
```php
|
||||
|
||||
class RelationScope implements Scope
|
||||
{
|
||||
public function apply(Builder $builder, Model $model): void
|
||||
{
|
||||
if (!Bouncer::inRelationScope()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$builder->where($model->qualifyColumn('relation_id'), Bouncer::getRelationId());
|
||||
|
||||
if (method_exists($model, 'modifyRelationScope')) {
|
||||
$model->modifyRelationScope($builder);
|
||||
}
|
||||
}
|
||||
|
||||
public function extend(Builder $builder): void
|
||||
{
|
||||
$builder->macro('withoutRelationScope', function (Builder $builder) {
|
||||
return $builder->withoutGlobalScope($this);
|
||||
});
|
||||
|
||||
$builder->macro('withOutsideRelationScope', function (Builder $builder, string $relations) {
|
||||
return $builder->with([$relations => fn($query) => $query->withoutWarehouseScope()]);
|
||||
});
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
RelationThroughScope
|
||||
```php
|
||||
class RelationThroughScope implements Scope
|
||||
{
|
||||
public function apply(Builder $builder, Model $model): void
|
||||
{
|
||||
if (!Bouncer::inRelationScope()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$builder->whereHas($builder->getModel()->getRelationThroughRelationship());
|
||||
}
|
||||
|
||||
public function extend(Builder $builder): void
|
||||
{
|
||||
$builder->macro('withoutRelationScope', function (Builder $builder) {
|
||||
return $builder->withoutGlobalScope($this);
|
||||
});
|
||||
}
|
||||
}
|
||||
```
|
||||
9
Career/Others/Max Children.md
Normal file
9
Career/Others/Max Children.md
Normal file
@@ -0,0 +1,9 @@
|
||||
---
|
||||
created: 2025-03-26 11:35
|
||||
updated: 2025-07-04 06:45
|
||||
---
|
||||
```bash
|
||||
sudo grep 'seems busy' /var/log/php8.3-fpm.log
|
||||
```
|
||||
|
||||
#PHP #bash #grep
|
||||
12
Career/Others/New Laravel.md
Normal file
12
Career/Others/New Laravel.md
Normal file
@@ -0,0 +1,12 @@
|
||||
- [ ] Change font
|
||||
- [ ] Add flare
|
||||
- [ ] Enforce morphmap
|
||||
- [ ] Add the mixins
|
||||
- [ ] Add laravel actions
|
||||
- [ ] Add eslint
|
||||
- [ ] Add laravel deployment actions
|
||||
- [ ] barryvdh/laravel-debugbar
|
||||
- [ ] driftingly/rector-laravel
|
||||
- [ ] staudenmeir/eloquent-has-many-deep
|
||||
- [ ] Add telescope
|
||||
|
||||
16
Career/Others/Nginx.md
Normal file
16
Career/Others/Nginx.md
Normal file
@@ -0,0 +1,16 @@
|
||||
---
|
||||
created: 2025-07-03 10:19
|
||||
updated: 2025-07-03 10:35
|
||||
---
|
||||
## Header to Big
|
||||
Add
|
||||
```bash
|
||||
location ~ \.php$ {
|
||||
include fastcgi_params;
|
||||
# Bla bla
|
||||
fastcgi_buffers 16 16k;
|
||||
fastcgi_buffer_size 32k;
|
||||
}
|
||||
```
|
||||
|
||||
After
|
||||
35
Career/Others/Nicer Maintenance Mode.md
Normal file
35
Career/Others/Nicer Maintenance Mode.md
Normal file
@@ -0,0 +1,35 @@
|
||||
---
|
||||
created: 2025-03-12 14:12
|
||||
updated: 2025-07-04 07:25
|
||||
tags:
|
||||
- Laravel
|
||||
---
|
||||
|
||||
|
||||
```bash
|
||||
php artisan down --render="errors::maintenance"
|
||||
```
|
||||
|
||||
```bash
|
||||
php artisan vendor:publish --tag=laravel-errors
|
||||
```
|
||||
|
||||
```
|
||||
touch ./resources/views/errors/maintenance.blade.php
|
||||
```
|
||||
|
||||
``` php maintenance.blade.php
|
||||
@extends('errors.minimal')
|
||||
|
||||
@section('title', __('Planned Maintenance'))
|
||||
@section('message', __('Planned Maintenance'))
|
||||
@section('description', __('We will be back in a few minutes.'))
|
||||
```
|
||||
|
||||
``` php minimal.blade.php
|
||||
@hasSection('code')
|
||||
<div class="px-4 text-lg text-gray-500 border-r border-gray-400 tracking-wider">
|
||||
@yield('code')
|
||||
</div>
|
||||
@endif
|
||||
```
|
||||
47
Career/Others/Rector.md
Normal file
47
Career/Others/Rector.md
Normal file
@@ -0,0 +1,47 @@
|
||||
---
|
||||
created: 2025-03-17 14:03
|
||||
updated: 2025-07-04 07:25
|
||||
tags:
|
||||
- Laravel/Packages
|
||||
---
|
||||
|
||||
|
||||
```bash
|
||||
composer require driftingly/rector-laravel && ./vendor/bin/rector
|
||||
```
|
||||
|
||||
```php. rector
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
|
||||
use Rector\Php83\Rector\ClassMethod\AddOverrideAttributeToOverriddenMethodsRector;
|
||||
use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector;
|
||||
use RectorLaravel\Set\LaravelSetList;
|
||||
|
||||
return RectorConfig::configure()
|
||||
->withPaths([
|
||||
// bla bla
|
||||
])
|
||||
->withPhpSets()
|
||||
->withSkip([
|
||||
ClosureToArrowFunctionRector::class,
|
||||
AddOverrideAttributeToOverriddenMethodsRector::class,
|
||||
AddVoidReturnTypeWhereNoReturnRector::class,
|
||||
])
|
||||
->withPreparedSets(
|
||||
deadCode : true,
|
||||
codeQuality : true,
|
||||
typeDeclarations: true,
|
||||
privatization : true,
|
||||
)
|
||||
->withSets([
|
||||
LaravelSetList::LARAVEL_110,
|
||||
LaravelSetList::LARAVEL_CODE_QUALITY,
|
||||
LaravelSetList::LARAVEL_ELOQUENT_MAGIC_METHOD_TO_QUERY_BUILDER,
|
||||
LaravelSetList::LARAVEL_CONTAINER_STRING_TO_FULLY_QUALIFIED_NAME,
|
||||
LaravelSetList::LARAVEL_COLLECTION,
|
||||
]);
|
||||
```
|
||||
43
Career/Others/Untitled.md
Normal file
43
Career/Others/Untitled.md
Normal file
@@ -0,0 +1,43 @@
|
||||
```bash
|
||||
php artisan make:command AuditDependenciesCommand
|
||||
```
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Process;
|
||||
use Spatie\FlareClient\Enums\MessageLevels;
|
||||
use Spatie\LaravelIgnition\Facades\Flare;
|
||||
|
||||
class AuditDependenciesCommand extends Command
|
||||
{
|
||||
protected $signature = 'app:audit-dependencies';
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$composer = Process::run('composer audit');
|
||||
|
||||
if (!blank($composer->output())) {
|
||||
$this->warn('Composer audit found vulnerabilities');
|
||||
Flare::glow('Composer audit found vulnerabilities', MessageLevels::WARNING, ['output' => $composer->output()]);
|
||||
Flare::report(new Exception('Composer audit found vulnerabilities'));
|
||||
}
|
||||
|
||||
$npm = Process::run('npm audit');
|
||||
|
||||
if (trim($npm->output()) !== "found 0 vulnerabilities") {
|
||||
$this->warn('NPM audit found vulnerabilities');
|
||||
Flare::glow('NPM audit found vulnerabilities', MessageLevels::WARNING, ['output' => $npm->output()]);
|
||||
Flare::report(new Exception('NPM audit found vulnerabilities'));
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```php in kernel
|
||||
$schedule->command(\App\Console\Commands\AuditDependenciesCommand::class)->daily();
|
||||
```
|
||||
Reference in New Issue
Block a user