-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from binafy/complete-readme
[0.x] Complete readme
- Loading branch information
Showing
1 changed file
with
189 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,43 @@ | |
[](https://packagist.org/packages/binafy/laravel-stub) | ||
[](https://github.com/binafy/laravel-stub/actions/workflows/tests.yml) | ||
|
||
- [Introduction](#introduction) | ||
- [Requirements](#requirements) | ||
- [Installation](#installation) | ||
- [Usage](#usage) | ||
- [Create a stub file](#create-a-stub-file) | ||
- [How using Laravel Stub](#how-using-laravel-stub) | ||
- [`from`](#from) | ||
- [`to`](#to) | ||
- [`name`](#name) | ||
- [`ext`](#ext) | ||
- [`replace`](#replace) | ||
- [`replaces`](#replaces) | ||
- [`download`](#download) | ||
- [`generate`](#generate) | ||
- [Contributors](#contributors) | ||
- [Security](#security) | ||
- [Changelog](#changelog) | ||
- [License](#license) | ||
|
||
<a name="introduction"></a> | ||
## Introduction | ||
|
||
The Laravel-Stub package enhances the development workflow in Laravel by providing a set of customizable stubs. Stubs are templates used to scaffold code snippets for various components like models, controllers, and migrations. With Laravel-Stub, developers can easily tailor these stubs to match their project's coding standards and conventions. This package aims to streamline the code generation process, fostering consistency and efficiency in Laravel projects. Explore the customization options and boost your development speed with Laravel-Stub. | ||
|
||
<a name="requirements"></a> | ||
## Requirements | ||
|
||
*** | ||
- ```PHP >= 8.0``` | ||
- ```Laravel >= 9.0``` | ||
|
||
|
||
| Version/Laravel | L9 | L10 | | ||
|-----------------|--------------------|--------------------| | ||
| 1.0 | :white_check_mark: | :white_check_mark: | | ||
|
||
<a name="installation"></a> | ||
## Installation | ||
|
||
You can install the package with Composer: | ||
|
@@ -22,8 +55,11 @@ composer require binafy/laravel-stub | |
|
||
You don't need to publish anything. | ||
|
||
<a name="usage"></a> | ||
## Usage | ||
|
||
<a name="create-a-stub-file"></a> | ||
### Create a stub file | ||
First of all, create a stub file call `model.stub`: | ||
|
||
```bash | ||
|
@@ -35,11 +71,163 @@ Add some code to that, like this: | |
```php | ||
<?php | ||
|
||
namespace {{ NAMESPACE }} | ||
namespace {{ NAMESPACE }}; | ||
|
||
class {{ CLASS }} | ||
{ | ||
|
||
} | ||
``` | ||
|
||
<a name="how-using-laravel-stub"></a> | ||
### How using Laravel Stub | ||
|
||
You may to use Laravel Stub, you need to use `LaravelStub` facade: | ||
|
||
```php | ||
namespace Binafy\LaravelStub\Facades\LaravelStub; | ||
|
||
LaravelStub::class; | ||
``` | ||
|
||
<a name="from"></a> | ||
### `from` | ||
|
||
First thing, you need to use `from` method to give the stub path: | ||
|
||
```php | ||
LaravelStub::from(__DIR__ . 'model.stub'); | ||
``` | ||
|
||
<a name="to"></a> | ||
### `to` | ||
|
||
So, you need to determine the destination path of the stub file: | ||
|
||
```php | ||
LaravelStub::from(__DIR__ . 'model.stub') | ||
->to(__DIR__ . '/App'); | ||
``` | ||
|
||
<a name="name"></a> | ||
### `name` | ||
|
||
You can determine the stub file but also attention don't write the stub extension: | ||
|
||
```php | ||
LaravelStub::from(__DIR__ . 'model.stub') | ||
->to(__DIR__ . '/App') | ||
->name('new-model'); | ||
``` | ||
|
||
<a name="ext"></a> | ||
### `ext` | ||
|
||
You can determine the stub extension: | ||
|
||
```php | ||
LaravelStub::from(__DIR__ . 'model.stub') | ||
->to(__DIR__ . '/App') | ||
->name('new-model') | ||
->ext('php'); | ||
``` | ||
|
||
<a name="replace"></a> | ||
### `replace` | ||
|
||
The `replace` method take two params, first one is the key (variable) and second one is value. The value will replace with variable: | ||
|
||
```php | ||
LaravelStub::from(__DIR__ . 'model.stub') | ||
->to(__DIR__ . '/App') | ||
->name('new-model') | ||
->ext('php') | ||
->replace('NAMESPACE', 'App'); | ||
``` | ||
|
||
<a name="replaces"></a> | ||
### `replaces` | ||
|
||
The `replaces` method take an array. If you want to replace multi variables you can use this method: | ||
|
||
```php | ||
LaravelStub::from(__DIR__ . 'model.stub') | ||
->to(__DIR__ . '/App') | ||
->name('new-model') | ||
->ext('php') | ||
->replaces([ | ||
'NAMESPACE' => 'App', | ||
'CLASS' => 'Milwad' | ||
]); | ||
``` | ||
|
||
<a name="download"></a> | ||
### `download` | ||
|
||
If you may to download the stub file, you can use `download` method: | ||
|
||
```php | ||
LaravelStub::from(__DIR__ . 'model.stub') | ||
->to(__DIR__ . '/App') | ||
->name('new-model') | ||
->ext('php') | ||
->replaces([ | ||
'NAMESPACE' => 'App', | ||
'CLASS' => 'Milwad' | ||
]) | ||
->download(); // Return download response | ||
``` | ||
|
||
<a name="generate"></a> | ||
### `generate` | ||
|
||
The important method is `generate`. For generate the stub file at the end you need to use `generate` method to generate stub file: | ||
|
||
```php | ||
LaravelStub::from(__DIR__ . 'model.stub') | ||
->to(__DIR__ . '/App') | ||
->name('new-model') | ||
->ext('php') | ||
->replaces([ | ||
'NAMESPACE' => 'App', | ||
'CLASS' => 'Milwad' | ||
]) | ||
->generate(); | ||
``` | ||
|
||
> **_NOTE:_** Don't use `download` and `generate` method in one chain. | ||
The final file will be like this (`new-model.php`): | ||
|
||
```php | ||
<?php | ||
|
||
namespace App; | ||
|
||
class Milwad | ||
{ | ||
|
||
} | ||
``` | ||
|
||
<a name="contributors"></a> | ||
## Contributors | ||
|
||
Thanks to all the people who contributed. [Contributors](https://github.com/binafy/laravel-stub/graphs/contributors). | ||
|
||
<a href="https://github.com/binafy/laravel-stub/graphs/contributors"><img src="https://opencollective.com/laravel-stub/contributors.svg?width=890&button=false" /></a> | ||
|
||
<a name="security"></a> | ||
## Security | ||
|
||
If you discover any security-related issues, please email `[email protected]` instead of using the issue tracker. | ||
|
||
<a name="chanelog"></a> | ||
## Changelog | ||
|
||
The changelog can be found in the `CHANGELOG.md` file of the GitHub repository. It lists the changes, bug fixes, and improvements made to each version of the Laravel User Monitoring package. | ||
|
||
<a name="license"></a> | ||
## License | ||
|
||
The MIT License (MIT). Please see [License File](https://github.com/binafy/laravel-stub/blob/1.x/LICENSE) for more information. |