一键导入
php-guidelines-from-spatie
Describes PHP and Laravel guidelines provided by Spatie. These rules result in more maintainable, and readable code.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Describes PHP and Laravel guidelines provided by Spatie. These rules result in more maintainable, and readable code.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Manage email marketing with the Mailcoach CLI — email lists, subscribers, campaigns, transactional emails, templates, automations, tags, and segments.
Create, schedule, and manage social media posts via Typefully. ALWAYS use this skill when asked to draft, schedule, post, or check tweets, posts, threads, or social media content for Twitter/X, LinkedIn, Threads, Bluesky, or Mastodon.
Update Spatie package documentation on spatie.be by re-importing docs for a given repo. Use after merging a PR that touches docs/, or when the user says 'update docs for [package]', 'rebuild docs for [repo]', 'import docs for [repo]', or invokes /update-spatie-docs [repo-name]. Takes a repo name argument (e.g., 'backup', 'laravel-medialibrary', 'laravel-pdf').
When the user wants to generate, iterate, or scale ad creative — headlines, descriptions, primary text, or full ad variations — for any paid advertising platform. Also use when the user mentions 'ad copy variations,' 'ad creative,' 'generate headlines,' 'RSA headlines,' 'bulk ad copy,' 'ad iterations,' 'creative testing,' or 'ad performance optimization.' This skill covers generating ad creative at scale, iterating based on performance data, and enforcing platform character limits. For campaign strategy and targeting, see paid-ads. For landing page copy, see copywriting.
When the user wants to optimize content for AI search engines, get cited by LLMs, or appear in AI-generated answers. Also use when the user mentions 'AI SEO,' 'AEO,' 'GEO,' 'LLMO,' 'answer engine optimization,' 'generative engine optimization,' 'LLM optimization,' 'AI Overviews,' 'optimize for ChatGPT,' 'optimize for Perplexity,' 'AI citations,' 'AI visibility,' or 'zero-click search.' This skill covers content optimization for AI answer engines, monitoring AI visibility, and getting cited as a source. For traditional technical and on-page SEO audits, see seo-audit. For structured data implementation, see schema-markup.
When the user wants to reduce churn, build cancellation flows, set up save offers, recover failed payments, or implement retention strategies. Also use when the user mentions 'churn,' 'cancel flow,' 'offboarding,' 'save offer,' 'dunning,' 'failed payment recovery,' 'win-back,' 'retention,' 'exit survey,' 'pause subscription,' or 'involuntary churn.' This skill covers voluntary churn (cancel flows, save offers, exit surveys) and involuntary churn (dunning, payment recovery). For post-cancel win-back email sequences, see email-sequence. For in-app upgrade paywalls, see paywall-upgrade-cro.
| name | php-guidelines-from-spatie |
| description | Describes PHP and Laravel guidelines provided by Spatie. These rules result in more maintainable, and readable code. |
| license | MIT |
| metadata | {"author":"Spatie","tags":"php, laravel, best practices, coding standards"} |
Follow Laravel conventions first. If Laravel has a documented way to do something, use it. Only deviate when you have a clear justification.
?string not string|nullvoid return types when methods return nothingvoid?Type not Type|null/** @return Collection<int, User> */
public function getUsers(): Collection
use \Spatie\Url\Url;
/** @return Url */
/** @var string *//** @var Collection|SomeWeirdVendor\Collection */
/**
* @param array<int, MyObject> $myArray
* @param int $typedArgument
*/
function someFunction(array $myArray, int $typedArgument) {}
/** @return array{
first: SomeClass,
second: SomeClass
} */
if statements that use && into nested if statements for better readability// Happy path last
if (! $user) {
return null;
}
if (! $user->isActive()) {
return null;
}
// Process active user...
// Short ternary
$name = $isFoo ? 'foo' : 'bar';
// Multi-line ternary
$result = $object instanceof Model ?
$object->name :
'A default value';
// Ternary instead of else
$condition
? $this->doSomething()
: $this->doSomethingElse();
// Bad: compound condition with &&
if ($user->isActive() && $user->hasPermission('edit')) {
$user->edit();
}
// Good: nested ifs
if ($user->isActive()) {
if ($user->hasPermission('edit')) {
$user->edit();
}
}
/open-source)->name('openSource')){userId})[Controller::class, 'method']PostsController)index, create, store, show, edit, update, destroy)pdf-generator.php)chrome_path)config/services.php, don't create new filesconfig() helper, avoid env() outside config filesdelete-old-records)$this->comment('All ok!'))$items->each(function(Item $item) {
$this->info("Processing item id `{$item->id}`...");
$this->processItem($item);
});
$this->comment("Processed {$items->count()} items.");
Be very critical about adding comments as they often become outdated and can mislead over time. Code should be self-documenting through descriptive variable and function names.
Adding comments should never be the first tactic to make code readable.
Instead of this:
// Get the failed checks for this site
$checks = $site->checks()->where('status', 'failed')->get();
Do this:
$failedChecks = $site->checks()->where('status', 'failed')->get();
Guidelines:
{} bracketspublic function rules() {
return [
'email' => ['required', 'email'],
];
}
Validator::extend('organisation_type', function ($attribute, $value) {
return OrganisationType::isValid($value);
});
@if($condition)
Something
@endif
Gate::define('editPost', ...)view instead of show__() function over @lang:/errors/error-occurrences/error-occurrences/1
/errors/1/occurrences
it/test blocks (the tests should read first; helpers are support detail)UserController, OrderStatus)getUserName, $firstName)/open-source, /user-profile)pdf-generator.php)chrome_path)php artisan delete-old-records)Controller (PostsController)openSource.blade.php)CreateUser, SendEmailNotification)UserRegistering, UserRegistered)Listener suffix (SendInvitationMailListener)Command suffix (PublishScheduledPostsCommand)Mail suffix (AccountActivatedMail)Resource/Transformer (UsersResource)OrderStatus, BookingType)else statements when possibleif conditions using && into nested if statementsuse statements — never use inline fully qualified class names (e.g. \Exception, \Illuminate\Support\Facades\Http)$exception not $e, $request not $r)