Laravel Stub

binafy/laravel-stub image

Laravel Stub stats

Downloads
1
Stars
6
Open Issues
0
Forks
0

View on GitHub →

Generate stub files easy

Laravel Stub

laravel-stub-banner

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.

Requirements


  • PHP >= 8.0
  • Laravel >= 9.0
Version/Laravel L9 L10 L11
1.0 :white_check_mark: :white_check_mark: :white_check_mark:

Installation

You can install the package with Composer:

composer require binafy/laravel-stub

You don't need to publish anything.

Usage

Create a stub file

First of all, create a stub file called model.stub:

touch model.stub

Add some code to that, like this:

<?php
 
namespace {{ NAMESPACE }};
 
class {{ CLASS }}
{
 
}

How to use Laravel Stub

You may use Laravel Stub, you need to use the LaravelStub facade:

use Binafy\LaravelStub\Facades\LaravelStub;
 
LaravelStub::class;

from

First thing, you need to use the from method to give the stub path:

LaravelStub::from(__DIR__ . 'model.stub');

to

So, you need to determine the destination path of the stub file:

LaravelStub::from(__DIR__ . 'model.stub')
->to(__DIR__ . '/App');

name

You can determine the stub file but also attention don't write the stub extension:

LaravelStub::from(__DIR__ . 'model.stub')
->to(__DIR__ . '/App')
->name('new-model');

ext

You can determine the stub extension:

LaravelStub::from(__DIR__ . 'model.stub')
->to(__DIR__ . '/App')
->name('new-model')
->ext('php');

replace

The replace method takes two parameters, the first one is the key (variable) and the second one is the value. The value will be replaced with the variable:

LaravelStub::from(__DIR__ . 'model.stub')
->to(__DIR__ . '/App')
->name('new-model')
->ext('php')
->replace('NAMESPACE', 'App');

replaces

The replaces method takes an array. If you want to replace multiple variables you can use this method:

LaravelStub::from(__DIR__ . 'model.stub')
->to(__DIR__ . '/App')
->name('new-model')
->ext('php')
->replaces([
'NAMESPACE' => 'App',
'CLASS' => 'Milwad'
]);

download

If you want to download the stub file, you can use the download method:

LaravelStub::from(__DIR__ . 'model.stub')
->to(__DIR__ . '/App')
->name('new-model')
->ext('php')
->replaces([
'NAMESPACE' => 'App',
'CLASS' => 'Milwad'
])
->download(); // Return download response

generate

The important method is generate. To generate the stub file at the end you need to use the generate method to generate stub file:

LaravelStub::from(__DIR__ . 'model.stub')
->to(__DIR__ . '/App')
->name('new-model')
->ext('php')
->replaces([
'NAMESPACE' => 'App',
'CLASS' => 'Milwad'
])
->generate();

NOTE: Don't use the download and generate methods in one chain.

The final file will be like this (new-model.php):

<?php
 
namespace App;
 
class Milwad
{
 
}

Contributors

Thanks to all the people who contributed. Contributors.

Security

If you discover any security-related issues, please email binafy23@gmail.com instead of using the issue tracker.

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.

License

The MIT License (MIT). Please see License File for more information.

binafy photo

We are helping to open-source world

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Binafy Laravel Stub Related Articles

SQLite Studio is a SQLite Database Explorer image

SQLite Studio is a SQLite Database Explorer

Read article
Homestead V5.0.0 Is Released image

Homestead V5.0.0 Is Released

Read article
Tighten logo

Tighten

We help companies turn great ideas into amazing apps, products, and services.

Tighten
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Securing Laravel logo

Securing Laravel

The essential security resource for Laravel devs, covering everything you need to keep your apps secure. Sign up to receive weekly security tips and monthly in depth articles, diving deep into security concepts you need to know!

Securing Laravel
The Certification of Competence for Laravel logo

The Certification of Competence for Laravel

A community-driven, proctored assessment across 4 levels designed to validate real-world Laravel knowledge, from Junior to mastery-level Artisan. Official Vue.js, Official Nuxt, Angular, React, JS certifications also available.

The Certification of Competence for Laravel
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum