Contributing to Laravel: A Practical Guide to Your First Pull Request
Mastering the Laravel Contribution Workflow
Contributing to a massive ecosystem like the
Setting Up for Success: Forking and Cloning
You must work on the correct branch to ensure your code is even considered. For the 11.x. Start by forking the official repository to your own account and then cloning it locally. To test your changes within a real-world context, link your local fork to a fresh composer.json of a test project to point its repository source to your local path. This setup allows you to see how your changes affect the
The TDD Approach to Framework Features
When modifying internal commands like make:notification, a Test-Driven Development (TDD) workflow is your best friend. Start by identifying the relevant test class, such as NotificationMakeCommandTest. Write a failing test that simulates a user calling the command without arguments and then answering prompts.
public function test_it_prompts_for_markdown_template()
{
$this->artisan('make:notification')
->expectsQuestion('What should the notification be named?', 'ExportFinished')
->expectsConfirmation('Would you like to create a markdown view?', 'yes')
->expectsQuestion('What should the markdown view be named?', 'export-finished')
->assertExitCode(0);
}
By defining the expected interaction first, you create a roadmap for your implementation. This ensures that the new feature behaves exactly as intended before you touch the core logic.
Implementing Interactive Prompts
To add interactive prompts to a command, you need to hook into the afterPromptingForMissingArguments method. This method runs after the basic arguments (like the class name) are collected. You can use the setOption method to inject user input into the command's existing logic.
protected function afterPromptingForMissingArguments(InputInterface $input, OutputInterface $output)
{
if ($this->didReceiveOptions($input)) {
return;
}
$markdown = confirm('Would you like to create a markdown view?');
if ($markdown) {
$input->setOption('markdown', text(
label: 'What should the markdown view be named?',
placeholder: 'mail.invoice-paid'
));
}
}
Using the
Common Gotchas and the PR Process
Even with passing local tests, $files property of the test class so they are deleted after the test run.
When submitting the PR, provide a descriptive title and a screenshot of the CLI interaction. Explain the benefit to the end-user clearly. Remember that
