Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change controller model template in Laravel

Tags:

laravel

I'd like to know if there is any way to change the basic template for the controller and the model in laravel5.4. I mean when I run:

php artisan make:controller ControllerName --resource

it will generate this:

<?php
 namespace App\Http\Controllers;
 use Illuminate\Http\Request;
 class UsersController extends Controller
{
public function index()
{
    return view('users.index');
}
public function create()
{

}
public function store(Request $request)
{

}
public function show($id)
{

}
public function edit($id)
{

}
public function update(Request $request, $id)
{

}
public function destroy($id)
{

}
}

I need to change this template for anything I want to change the model as well.

like image 511
Awar Pulldozer Avatar asked Nov 15 '25 18:11

Awar Pulldozer


1 Answers

There was no way in Laravel 5, but from laravel 7 you can customize the stubs

Execute this command to publish all available stubs for customization

php artisan stub:publish

When we publish stub then all files of stub will be located within a stubs directory in the root of your application.

You can now edit all .stub files and customize your project files

I also suggest you read this blog post:

https://arievisser.com/blog/how-to-use-stub-customization-in-laravel/

like image 111
Erfan Bahramali Avatar answered Nov 18 '25 11:11

Erfan Bahramali