### Install Composer Dependencies Source: https://github.com/animethemes/animethemes-server/wiki/Installation Installs all vendor dependencies required by the project using Composer. ```bash composer install ``` -------------------------------- ### Seed Database Source: https://github.com/animethemes/animethemes-server/wiki/Installation Runs the database seeders to populate the database with initial data. ```bash php artisan db:seed --class=DatabaseSeeder ``` -------------------------------- ### Clone Repository Source: https://github.com/animethemes/animethemes-server/wiki/Installation Clones the AnimeThemes server repository into the webserver's document root and navigates into the project directory. ```bash git clone git@github.com:AnimeThemes/animethemes-server.git cd animethemes-server ``` -------------------------------- ### Migrate Database Source: https://github.com/animethemes/animethemes-server/wiki/Installation Applies pending database migrations to update the database schema. ```bash php artisan migrate ``` -------------------------------- ### Elasticsearch Index Migrations Source: https://github.com/animethemes/animethemes-server/wiki/Installation Applies migrations specific to Elasticsearch indexing, ensuring the search indices are set up correctly. ```bash php artisan elastic:migrate ``` -------------------------------- ### Synchronize Database and Run Seeders Source: https://github.com/animethemes/animethemes-server/wiki/Installation Automatically imports database dumps, runs migrations, and executes seeders for initial data population. ```bash php artisan db:sync ``` -------------------------------- ### Generate Application Key Source: https://github.com/animethemes/animethemes-server/wiki/Installation Generates the application key required for Laravel applications, which is stored in the .env file. ```bash php artisan key:generate ``` -------------------------------- ### Configure Local Storage Disks (.env) Source: https://github.com/animethemes/animethemes-server/wiki/Installation Sets default and available local disks for various media types (audio, video, dumps, images, scripts) by defining environment variables in the .env file. ```sh AUDIO_DISK_DEFAULT=audios_local AUDIO_DISKS=audios_local DUMP_DISK=dumps_local IMAGE_DISK=images_local VIDEO_DISK_DEFAULT=videos_local VIDEO_DISKS=videos_local SCRIPT_DISK=scripts_local ``` -------------------------------- ### Configure Local Storage Root Paths (.env) Source: https://github.com/animethemes/animethemes-server/wiki/Installation Specifies the root directory for each local storage disk, allowing media to be stored in external locations. Requires proper escaping for Windows paths. ```sh AUDIO_DISK_ROOT="E:\\animethemes-audios\\ DUMP_DISK_ROOT="E:\\animethemes-db-dumps\\ IMAGE_DISK_ROOT="E:\\animethemes-images\\ SCRIPT_DISK_ROOT="E:\\animethemes-scripts\\ VIDEO_DISK_ROOT="E:\\animethemes-videos\\" ``` -------------------------------- ### Import Models into Elasticsearch Source: https://github.com/animethemes/animethemes-server/wiki/Installation Imports various application models into Elasticsearch indices for searching. This can be done via a seeder or individual commands. ```bash # Import Models with a seeder php artisan db:seed --class="Database\Seeders\Scout\ImportModelsSeeder" # or # Import Models manually php artisan scout:import "App\Models\List\Playlist" php artisan scout:import "App\Models\Wiki\Anime" php artisan scout:import "App\Models\Wiki\Anime\AnimeSynonym" php artisan scout:import "App\Models\Wiki\Anime\AnimeTheme" php artisan scout:import "App\Models\Wiki\Anime\Theme\AnimeThemeEntry" php artisan scout:import "App\Models\Wiki\Artist" php artisan scout:import "App\Models\Wiki\Series" php artisan scout:import "App\Models\Wiki\Song" php artisan scout:import "App\Models\Wiki\Studio" php artisan scout:import "App\Models\Wiki\Video" ``` -------------------------------- ### PHP Configuration for Uploads Source: https://github.com/animethemes/animethemes-server/wiki/Installation Configures PHP settings to allow large file uploads, specifically for video uploads. These settings are typically found in the php.ini file. ```ini post_max_size = "200M" upload_max_filesize = "200M" ``` -------------------------------- ### Video Configuration Properties Source: https://github.com/animethemes/animethemes-server/wiki/Configuration Properties for managing video file storage, serving, and streaming. ```APIDOC Video Configuration: VIDEO_DEFAULT_DISK: string Description: The primary filesystem disk for video storage and validation. Example: VIDEO_DEFAULT_DISK=s3 VIDEO_DISKS: array Description: A list of filesystems hosting video, typically per server region. For local environments, can match VIDEO_DEFAULT_DISK. Example: VIDEO_DISKS=["s3", "local"] VIDEO_URL: string | null Description: Sets the base URL if video is served from a subdomain (e.g., v.animethemes.test). Leave null if not applicable. Example: VIDEO_URL=v.animethemes.test VIDEO_PATH: string | null Description: Sets the path if video is served from the top-level domain (e.g., animethemes.test/video). Leave null if not applicable. Example: VIDEO_PATH=/video ``` -------------------------------- ### Create Storage Symbolic Links Source: https://github.com/animethemes/animethemes-server/wiki/Installation Generates symbolic links for the storage directory, making public assets accessible. This command is part of the Laravel framework. ```php php artisan storage:link ``` -------------------------------- ### Image Configuration Properties Source: https://github.com/animethemes/animethemes-server/wiki/Configuration Properties for managing image file storage. ```APIDOC Image Configuration: IMAGE_DISK: string Description: The filesystem disk where images are stored and served. Example: IMAGE_DISK=s3 ``` -------------------------------- ### Wiki Route Configuration Source: https://github.com/animethemes/animethemes-server/wiki/Configuration Specifies the addresses for key wiki pages, such as the login and password reset pages, for integration with animethemes-web. ```APIDOC WIKI_LOGIN: Description: The URL address of the Wiki Login Page. Example: WIKI_LOGIN=https://wiki.animethemes.test/login WIKI_RESET_PASSWORD: Description: The URL address of the Wiki Reset Password Page. Example: WIKI_RESET_PASSWORD=https://wiki.animethemes.test/reset-password ``` -------------------------------- ### Dump Configuration Properties Source: https://github.com/animethemes/animethemes-server/wiki/Configuration Properties for managing dump file storage and serving. ```APIDOC Dump Configuration: DUMP_DISK: string Description: The filesystem disk where dump files are stored and served. Example: DUMP_DISK=local DUMP_URL: string | null Description: Sets the base URL if dumps are served from a subdomain (e.g., dump.animethemes.test). Leave null if not applicable. Example: DUMP_URL=dump.animethemes.test DUMP_PATH: string | null Description: Sets the path if dumps are served from the top-level domain (e.g., animethemes.test/dump). Leave null if not applicable. Example: DUMP_PATH=/dump ``` -------------------------------- ### Audio Configuration Properties Source: https://github.com/animethemes/animethemes-server/wiki/Configuration Properties for managing audio file storage, serving, and streaming methods. ```APIDOC Audio Configuration: AUDIO_DEFAULT_DISK: string Description: The primary filesystem disk for audio storage and validation. Example: AUDIO_DEFAULT_DISK=s3 AUDIO_DISKS: array Description: A list of filesystems hosting audio, typically per server region. For local environments, can match AUDIO_DEFAULT_DISK. Example: AUDIO_DISKS=["s3", "local"] AUDIO_URL: string | null Description: Sets the base URL if audio is served from a subdomain (e.g., a.animethemes.test). Leave null if not applicable. Example: AUDIO_URL=a.animethemes.test AUDIO_PATH: string | null Description: Sets the path if audio is served from the top-level domain (e.g., animethemes.test/audio). Leave null if not applicable. Example: AUDIO_PATH=/audio AUDIO_STREAMING_METHOD: "response" | "nginx" Description: Method for streaming audio. 'response' for local, 'nginx' for production. Example: AUDIO_STREAMING_METHOD=response AUDIO_NGINX_REDIRECT: string Description: The Nginx location directive used to serve audio requests. Example: AUDIO_NGINX_REDIRECT=/audio ``` -------------------------------- ### Create and Switch to Feature Branch Source: https://github.com/animethemes/animethemes-server/wiki/Contributing Creates a new branch for your feature development, named descriptively, and then switches your working directory to that new branch. ```git git branch new-feature-branch git checkout new-feature-branch ``` -------------------------------- ### Services Configuration Properties Source: https://github.com/animethemes/animethemes-server/wiki/Configuration Properties for storing credentials for third-party services like MyAnimeList and DigitalOcean. ```APIDOC Services Configuration: MAL_CLIENT_ID: string | null Description: Token to identify AnimeThemes to the MyAnimeList API for backfilling actions. Leave null if not performing these actions. Example: MAL_CLIENT_ID=your_mal_client_id DO_BEARER_TOKEN: string | null Description: Bearer token for DigitalOcean API calls, used for the transparency page. Leave null if not working on this feature. Example: DO_BEARER_TOKEN=your_do_bearer_token ``` -------------------------------- ### Configure SQLite Database Connection (.env) Source: https://github.com/animethemes/animethemes-server/wiki/Database-Setup Sets up the database connection parameters for SQLite in the `.env` file. Requires SQLite version 3.32.0+ and the `pdo_sqlite` PHP extension. This configuration specifies the absolute path to the database file. SQLite files are ignored by git. ```env DB_CONNECTION=sqlite DATABASE_URL= DB_HOST= DB_PORT= DB_DATABASE=/absolute/path/to/database.sqlite DB_USERNAME= DB_PASSWORD= DB_SOCKET= MYSQL_ATTR_SSL_CA=null ``` -------------------------------- ### API Configuration Properties Source: https://github.com/animethemes/animethemes-server/wiki/Configuration Properties related to interacting with the AnimeThemes API, including base URL and path configurations. ```APIDOC API Configuration: API_URL: string | null Description: Sets the base URL if the API is served from a subdomain (e.g., api.animethemes.test). Leave null if not applicable. Example: API_URL=api.animethemes.test API_PATH: string | null Description: Sets the path if the API is served from the top-level domain (e.g., animethemes.test/api). Leave null if not applicable. Example: API_PATH=/api ``` -------------------------------- ### Web URL Configuration Source: https://github.com/animethemes/animethemes-server/wiki/Configuration Configures the base URL for web routes. Allows setting a subdomain or a path for serving web applications. ```APIDOC WEB_URL: Description: Sets the base URL for web routes, typically a subdomain. Example: WEB_URL=app.animethemes.test WEB_PATH: Description: Sets the path for web routes if served from the top-level domain. Example: WEB_PATH=app ``` -------------------------------- ### Configure PostgreSQL Database Connection (.env) Source: https://github.com/animethemes/animethemes-server/wiki/Database-Setup Sets up the database connection parameters for PostgreSQL in the `.env` file. Requires PostgreSQL version 9.6+ and the `pdo_pgsql` PHP extension. This configuration specifies the host, port, database name, username, and password for local access. ```env DB_CONNECTION=pgsql DATABASE_URL= DB_HOST=127.0.0.1 DB_PORT=5432 DB_DATABASE=animethemes DB_USERNAME=root DB_PASSWORD= DB_SOCKET= MYSQL_ATTR_SSL_CA=null ``` -------------------------------- ### Set Up Upstream Remote Source: https://github.com/animethemes/animethemes-server/wiki/Contributing Configures the 'upstream' remote to point to the main AnimeThemes repository, allowing you to fetch updates. This is crucial for keeping your fork synchronized. ```git git remote add upstream git@github.com:AnimeThemes/animethemes-server.git ``` -------------------------------- ### Create User via Artisan Tinker Source: https://github.com/animethemes/animethemes-server/wiki/Getting-Started Creates a new user record in the AnimeThemes database using the factory pattern within Artisan Tinker. This command allows specifying the user's name, email, and password. ```sh php artisan tinker App\Models\Auth\User::factory()->create(['name' => 'User Name', 'email' => 'example@example.com', 'password' => 'password']); ``` -------------------------------- ### Configure MySQL Database Connection (.env) Source: https://github.com/animethemes/animethemes-server/wiki/Database-Setup Sets up the database connection parameters for MySQL in the `.env` file. Requires MySQL version 5.7+ and the `pdo_mysql` PHP extension. This configuration specifies the host, port, database name, username, and password for local access. ```env DB_CONNECTION=mysql DATABASE_URL= DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=animethemes DB_USERNAME=root DB_PASSWORD= DB_SOCKET= MYSQL_ATTR_SSL_CA=null ``` -------------------------------- ### Assign Admin Role to User Source: https://github.com/animethemes/animethemes-server/wiki/Getting-Started Assigns the 'Admin' role to an existing user, typically identified by ID 1. It also includes an optional step to set the email verified timestamp for Filament access. Ensure permission tables are seeded before running. ```sh $user = App\Models\Auth\User::find(1); $user->update(['email_verified_at' => now()]); // If you want to access Filament $user->assignRole('Admin'); ``` -------------------------------- ### Video Streaming Configuration Source: https://github.com/animethemes/animethemes-server/wiki/Configuration Defines how video content is streamed. Supports 'response' for local environments and 'nginx' for production, specifying the nginx redirect directive. ```APIDOC VIDEO_STREAMING_METHOD: Description: Specifies the method for streaming video content. Supported Values: - "response": Suitable for local development environments. - "nginx": Recommended for staging and production environments with high traffic. Example: VIDEO_STREAMING_METHOD=response VIDEO_NGINX_REDIRECT: Description: The location directive used by nginx to handle video requests and serve content. Example: VIDEO_NGINX_REDIRECT=/videos/ ``` -------------------------------- ### Stage and Commit Changes Source: https://github.com/animethemes/animethemes-server/wiki/Contributing Stages all modified files and commits them with a descriptive message following Semantic Commit Message conventions, including issue IDs. ```git git add . git commit -m "feat: Add new feature (closes #123)" ``` -------------------------------- ### Checkout and Update Release Branch Source: https://github.com/animethemes/animethemes-server/wiki/Contributing Switches to the main release branch (e.g., 'main') and pulls the latest changes from the upstream repository to ensure your local branch is up-to-date. ```git git checkout main git pull upstream main ``` -------------------------------- ### Fetch and Merge Upstream Release Branch Source: https://github.com/animethemes/animethemes-server/wiki/Contributing Fetches the latest changes from the upstream release branch and merges them into your local release branch. This is a preparatory step before rebasing. ```git git fetch upstream main git checkout main git merge upstream/main ``` -------------------------------- ### Push Feature Branch to Remote Source: https://github.com/animethemes/animethemes-server/wiki/Contributing Pushes your local feature branch to your origin (forked) remote repository. This makes your changes available for creating a pull request. ```git git push --set-upstream origin new-feature-branch ``` -------------------------------- ### Run Tests and Static Analysis Source: https://github.com/animethemes/animethemes-server/wiki/Contributing Executes project tests in parallel using PHP Artisan and performs static code analysis for type checking. These steps ensure code quality before committing. ```php php artisan config:clear && php artisan test --parallel ``` ```php composer test:types ``` -------------------------------- ### Push Upstream Changes Source: https://github.com/animethemes/animethemes-server/wiki/Contributing Pushes any fetched upstream changes to your forked remote repository's main branch. This keeps your fork synchronized with the official repository. ```git git push ``` -------------------------------- ### Define Model Namespace Source: https://github.com/animethemes/animethemes-server/wiki/Coding-Conventions-&-Standards Models are namespaced by concern to organize code effectively. This example shows the `Anime` model residing within the `App\Models\Wiki` namespace, inheriting from `BaseModel`. ```PHP namespace App\Models\Wiki; ... class Anime extends BaseModel ``` -------------------------------- ### Delete Remote Feature Branch Source: https://github.com/animethemes/animethemes-server/wiki/Contributing Removes the feature branch from your remote repository (origin) after it has been merged into the main branch. ```git git push origin --delete new-feature-branch ``` -------------------------------- ### Delete Local Feature Branch Source: https://github.com/animethemes/animethemes-server/wiki/Contributing After a feature branch has been merged, this command checks out the main branch and then deletes the local feature branch. ```git git checkout main git branch --delete new-feature-branch ``` -------------------------------- ### Suffix Notification Class Source: https://github.com/animethemes/animethemes-server/wiki/Coding-Conventions-&-Standards Notification class names must suffix with `Notification`. This example shows `DiscordNotification` adhering to this convention. ```PHP namespace App\Notifications; ... class DiscordNotification extends Notification implements ShouldQueue ``` -------------------------------- ### PHP Model Event Namespacing Source: https://github.com/animethemes/animethemes-server/wiki/Coding-Conventions-&-Standards Establishes that model events in PHP should be namespaced according to the model they relate to. For example, events for the `Anime` model should be in `App\Events\Wiki\Anime`. ```php namespace App\Events\Wiki\Anime; class AnimeCreated extends WikiCreatedEvent implements UpdateRelatedIndicesEvent ``` -------------------------------- ### Apache VirtualHost Configuration Source: https://github.com/animethemes/animethemes-server/wiki/Server-Setup Configures Apache VirtualHost entries in `httpd-vhosts.conf` to serve the animethemes-server application. This allows defining custom `ServerName` and `DocumentRoot` for different virtual hosts, enabling local development or specific domain hosting. ```apache DocumentRoot "/path/to/htdocs" ServerName localhost DocumentRoot "/path/to/htdocs/animethemes-server/public" ServerName animethemes.test ``` -------------------------------- ### Rebase Feature Branch Source: https://github.com/animethemes/animethemes-server/wiki/Contributing Rebases your feature branch onto the updated main branch. This ensures your feature branch contains the latest changes from main and avoids merge commits. ```git git checkout new-feature-branch git rebase main ``` -------------------------------- ### PHPDoc Block Structure Source: https://github.com/animethemes/animethemes-server/wiki/Coding-Conventions-&-Standards Illustrates the required PHPDoc structure for functions and properties, including the necessity of a short description for each. This standardizes documentation within the project. ```php /** * The array of embed fields. * * @var DiscordEmbedField[] */ protected array $embedFields = []; ... /** * Add discord embed field. * * @param DiscordEmbedField $embedField * @return void */ protected function addEmbedField(DiscordEmbedField $embedField) ``` -------------------------------- ### Admin Exception List Page PHP Implementation Source: https://github.com/animethemes/animethemes-server/blob/main/app/Filament/Resources/Admin/Exception/Pages/ListExceptions.txt This PHP code defines the `ListExceptions` page for the admin exception resource. It extends a base class from the `FilamentExceptions` package, linking it to the `Exception` resource. ```PHP mock(DigitalOceanBalanceRepository::class); $mock->shouldReceive('all') ->once() ->andReturn(Collection::make()); // bind the mocked instance into the container so that the mock is returned when we ask for this class to be initialized $this->app->instance(DigitalOceanBalanceRepository::class, $mock); $this->artisan(BalanceReconcileCommand::class, ['service' => Service::DIGITALOCEAN()->key])->expectsOutput('No Balances created or deleted or updated'); } // Don't do this public function testNoResults() { // The service will be invoked because we do not have a binding for the service repository $this->artisan(BalanceReconcileCommand::class, ['service' => Service::DIGITALOCEAN()->key])->expectsOutput('No Balances created or deleted or updated'); } ``` -------------------------------- ### PHP: Prefer Anonymous Classes for Interfaces/Abstracts Source: https://github.com/animethemes/animethemes-server/wiki/Coding-Conventions-&-Standards When testing interfaces or abstract classes, it is preferred to use anonymous classes directly within the test rather than creating separate concrete test classes. This simplifies test setup. ```php // Do this $event = new class implements DiscordMessageEvent { ... }; $job = new SendDiscordNotification($event); // Don't do this $event = new TestDiscordMessageEvent(); $job = new SendDiscordNotification($event); ``` -------------------------------- ### Nginx Server Block Configuration Source: https://github.com/animethemes/animethemes-server/wiki/Server-Setup Sets up an Nginx server block to serve the animethemes-server application, typically using PHP-FPM. It defines listening ports, server names, document root, index files, and location blocks for handling requests, including PHP processing and denying access to hidden files. ```nginx server { listen 80; listen [::]:80; server_name animethemes.test; root /var/www/animethemes-server/public; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.0-fpm.sock; } location ~ /\.ht { deny all; } } ``` -------------------------------- ### Get Monthly Resource Counts with Filament Trend Source: https://github.com/animethemes/animethemes-server/blob/main/app/Filament/Widgets/BaseChartWidget.txt Retrieves the count of resources created per month for a specified Eloquent model using the Flowframe\Trend package. Results are cached for performance. It takes a model class string and returns a Collection of monthly counts. ```PHP protected function perMonth(string $model): Collection { return Cache::flexible("filament_chart_$model", [300, 1200], function () use ($model) { return Trend::model($model) ->between(now()->addMonths(-11)->startOfMonth(), now()->endOfMonth()) ->perMonth() ->count(); }); } ``` -------------------------------- ### PHP Namespacing Convention Source: https://github.com/animethemes/animethemes-server/wiki/Coding-Conventions-&-Standards Explains the convention of matching namespaces to the most common canonical path of usages. This helps in organizing classes logically within the project structure. ```php // App\Contracts\Events\DiscordMessageEvent.php // DiscordMessageEvent is used by many classes in the App\Event namespace namespace App\Contracts\Events; ``` ```php // App\Events\Wiki\Anime\AnimeCreated.php namespace App\Events\Wiki\Anime; ... class AnimeCreated extends AnimeEvent implements DiscordMessageEvent, UpdateRelatedIndicesEvent ``` ```php // App\Events\Billing\Balance\BalanceCreated.php namespace App\Events\Billing\Balance; ... class BalanceCreated extends BalanceEvent implements DiscordMessageEvent ``` -------------------------------- ### Filament Exception View Page Source: https://github.com/animethemes/animethemes-server/blob/main/app/Filament/Resources/Admin/Exception/Pages/ViewException.txt Defines the `ViewException` page for the Filament admin panel within the animethemes-server project. This class extends `BaseViewException` and specifies its associated resource as `App\Filament\Resources\Admin\Exception`. ```php Exception::class, 'slug' => 'exceptions', /** Show or hide in navigation/sidebar */ 'navigation_enabled' => false, /** Sort order, if shown. No effect, if navigation_enabled it set to false. */ 'navigation_sort' => -1, /** Whether to show a navigation badge. No effect, if navigation_enabled it set to false. */ 'navigation_badge' => true, /** Whether to scope exceptions to tenant */ 'is_scoped_to_tenant' => true, /** Icons to use for navigation (if enabled) and pills */ 'icons' => [ 'navigation' => 'heroicon-o-cpu-chip', 'exception' => 'heroicon-o-cpu-chip', 'headers' => 'heroicon-o-arrows-right-left', 'cookies' => 'heroicon-o-circle-stack', 'body' => 'heroicon-s-code-bracket', 'queries' => 'heroicon-s-circle-stack', ], 'is_globally_searchable' => false, /**------------------------------------------------- * Change the default active tab * * Exception => 1 (Default) * Headers => 2 * Cookies => 3 * Body => 4 * Queries => 5 */ 'active_tab' => 5, /**------------------------------------------------- * Here you can define when the exceptions should be pruned * The default is 7 days (a week) * The format for providing period should follow carbon's format. i.e. * 1 day => 'subDay()', * 3 days => 'subDays(3)', * 7 days => 'subWeek()', * 1 month => 'subMonth()', * 2 months => 'subMonths(2)', * */ 'period' => now()->subWeek(), ]; ``` -------------------------------- ### PHP Job Middleware and Retry Configuration Source: https://github.com/animethemes/animethemes-server/wiki/Coding-Conventions-&-Standards Shows how to explicitly define middleware for a job and set a sensible retry time limit using the `middleware` and `retryUntil` methods. ```php namespace App\Jobs; use App\Jobs\Middleware\RateLimited; use DateTime; class SendDiscordNotificationJob implements ShouldQueue { // define middleware public function middleware(): array { return [new RateLimited()]; } // define sensible retry limit public function retryUntil(): DateTime { return now()->addMinutes(15); } } ``` -------------------------------- ### PHP Controller Method Naming for Resource Actions Source: https://github.com/animethemes/animethemes-server/wiki/Coding-Conventions-&-Standards Instructs PHP controllers to name their methods according to standard resource actions: `index`, `create`, `store`, `show`, `edit`, `update`, `destroy`. This aligns with RESTful principles. ```php // Do this public function show() // Don't do this public function do() // Don't do this public function encoding() ``` -------------------------------- ### PHP Policy Dependency Injection Best Practice Source: https://github.com/animethemes/animethemes-server/wiki/Coding-Conventions-&-Standards Policy functions should only inject the necessary objects as parameters. This principle of minimal dependency reduces coupling and improves testability. ```php namespace App\Policies\Wiki; ... // The policy class for the Anime model class AnimePolicy { ... // Neither a User or Anime object is needed public function view(): bool { return true; } ... // A User object is needed but not an Anime object public function update(User $user): bool { return $user->hasCurrentTeamPermission('anime:update'); } // All injectible objects are needed public function attachSeries(User $user, Anime $anime, Series $series): bool { if (AnimeSeries::where($anime->getKeyName(), $anime->getKey())->where($series->getKeyName(), $series->getKey())->exists()) { return false; } return $user->hasCurrentTeamPermission('anime:update'); } } ``` -------------------------------- ### PHP Namespace Usage Preference Source: https://github.com/animethemes/animethemes-server/wiki/Coding-Conventions-&-Standards Illustrates the preference for using `use` statements to import classes rather than fully qualified names directly in the code. This promotes cleaner and more readable code. ```php // Do this use App\Http\Api\Filter\Wiki\Anime\AnimeSeasonFilter; ... public static function filters(): array { return [ AnimeSeasonFilter::class, ... ]; } // Don't do this public static function filters(): array { return [ \App\Http\Api\Filter\Wiki\Anime\AnimeSeasonFilter::class, ... ]; } ``` -------------------------------- ### PHP Middleware Implementation Source: https://github.com/animethemes/animethemes-server/wiki/Coding-Conventions-&-Standards Demonstrates the structure of a PHP middleware class, including the handle method which processes requests and decides whether to pass control to the next middleware in the chain or return a response. ```php namespace App\Http\Middleware; use Closure; use Illuminate\Http\Request; use Illuminate\Support\Facades\Config; class IsVideoStreamingAllowed { // If video streaming is not allowed, redirect the user. // Otherwise, continue to the next middleware in the chain public function handle(Request $request, Closure $next): mixed { if (! Config::get('app.allow_video_streams', false)) { return redirect(route('welcome')); } return $next($request); } } ``` -------------------------------- ### Registering PHP Middleware Source: https://github.com/animethemes/animethemes-server/wiki/Coding-Conventions-&-Standards Shows how to register custom middleware in the application's HTTP kernel, making it available for use in routes via a short alias. ```php // App\Http\Kernel.php protected $routeMiddleware = [ ... 'is_video_streaming_allowed' => IsVideoStreamingAllowed::class, ... ]; ``` -------------------------------- ### Filament ExceptionsTableWidget PHP Class Source: https://github.com/animethemes/animethemes-server/blob/main/app/Filament/Widgets/Admin/ExceptionsTableWidget.txt Defines the `ExceptionsTableWidget` for Filament, which displays a table of exceptions. It leverages the `App\Filament\Resources\Admin\Exception` resource and sets a localized heading for the table. ```PHP heading(__('filament-exceptions::filament-exceptions.labels.model_plural')); } } ``` -------------------------------- ### PHP: PlaylistChart Widget Configuration Source: https://github.com/animethemes/animethemes-server/blob/main/app/Filament/Widgets/List/PlaylistChart.txt Defines a Filament widget (`PlaylistChart`) to visualize monthly playlist creation trends. It uses ApexCharts for rendering an area chart, fetching data via a `perMonth` method and mapping it to chart series and categories. Requires the `Playlist` model and `Flowframe\Trend` package. ```PHP */ protected function getOptions(): array { $data = $this->perMonth(Playlist::class); return [ 'chart' => [ 'type' => 'area', 'height' => 300, ], 'series' => [ [ 'name' => $this->getHeading(), 'data' => $data->map(fn (TrendValue $value) => $value->aggregate), ], ], 'xaxis' => [ 'categories' => $data->map(fn (TrendValue $value) => $this->translateDate($value->date)), 'labels' => [ 'style' => [ 'fontFamily' => 'inherit', ], ], ], 'yaxis' => [ 'labels' => [ 'style' => [ 'fontFamily' => 'inherit', ], ], ], 'colors' => ['#71E9C5'], 'stroke' => [ 'curve' => 'smooth', ], 'dataLabels' => [ 'enabled' => false, ], ]; } } ``` -------------------------------- ### Use Model Factories Source: https://github.com/animethemes/animethemes-server/wiki/Coding-Conventions-&-Standards Models should have factories to facilitate testing and development. The `BaseModel` abstract class utilizes the `HasFactory` trait, enabling the creation of model instances through factories. ```PHP namespace App\Models; ... abstract class BaseModel extends Model implements Nameable { ... use HasFactory; ... } ``` -------------------------------- ### PHP Resource Class Wrap Definition Source: https://github.com/animethemes/animethemes-server/wiki/Coding-Conventions-&-Standards Demonstrates how to define a 'wrap' property within a resource class to specify a sensible JSON root key for the resource's data. ```php namespace App\Http\Resources\Wiki\Resource; class EntryResource extends BaseResource { // A sensible wrap // We need this property for scoping public static $wrap = 'animethemeentry'; // ... } ``` -------------------------------- ### PHP Pascal Case for Classes Source: https://github.com/animethemes/animethemes-server/wiki/Coding-Conventions-&-Standards Illustrates the requirement for class names in PHP to use Pascal casing. This standard applies to all class definitions within the project. ```php // Do this class SendInvitationMail implements ShouldQueue // Don't do this class Send_Invitation_Email implements ShouldQueue ```