My Netbeans Setup
Tags: beginners, programming, productivity, php
Published: 2023-05-26 01:21:57

## Short and brief
You can get up an running in 3 easy steps:

1. [Download] (https://netbeans.apache.org/download/)
2. Install
3. Run

But to make your productivity go up you need to adjust your settings. After you get it done, you can export this settings and share them with your colleagues or have it as a backup in the case you need to either reinstall or re-apply them to a known working state.

## My favorite customizations
I once read that if you want to be really productive, know your IDE, make it yours, let it be a part of you. And that's what I've done with NetBeans. Today I want to share these tips with you so you can create your best.

**Slow behavior in Laravel Projects**
NetBeans was not built with Laravel on top of their mind. Out of the box NetBeans behaves slow according to my standards, but I have found a solution for it. First, let me tell you what slows down NetBeans: vendor folder. It tries to analyze every single piece of code inside it and it's a lot.
How to prevent this from happening?
1- Per project
2- Globally (my preferred option)

Per project
Go to your project and right click it and select properties. Inside JavaScript/Ignored folders you have to add the vendor folder an I recommend also including storage folder.

![Folders Ignored per project](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6jhbyoxtqkb22pst5pr2.png)

Globally
- Go to Tools > Options
- Select Miscellaneous
- Select "files" tab
In the ignored files pattern include vendor and node_modules as folders. My ignored string looks like this:

```
^(CVS|SCCS|vssver.?\.scc|#.*#|%.*%|_svn|vendor|node_modules)$|~$|^\.(git|hg|svn|cache|gradle|DS_Store)$|^Thumbs.db$
```

![Files ignored globally](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/unyo0ssdqr24ty408y9m.png)

**Editor**
- Go to Tools > Options
- Select Editor
- Select Autosave

Check both options to save every 5 minutes (or your preferred amount of time) and every time you change focus to other window or tab.

![Editor Options - Autosave](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bi76e4mkxzcqewf1uelc.png)
This is very useful because your mind does not need to waste processing time getting your files saved. No Ctrl+S or click on the save icon means your brain doesn't need to shift gears so you can stay focused on building your solution.

**Code Templates**
This is no NetBeans exclusive. What do I mean? Use it. Regardless of the IDE of your choice. Learn on how to use them and use them. They can save you a lot of time by preventing you from typing every time or googling every you need to implement a block of code you use frequently.

To create your own or create new ones based on the examples I'm going to post below: 
- Go to Tools > options > Code templates
- Select the language and create new ones pressing on "New"
- Type an abbreviation
- Type your code
- Embrace them! Use your templates! Save time! Show yourself amazing while typing your code!

Here are some examples under PHP:

[Accesors](https://laravel.com/docs/10.x/eloquent-mutators#accessors-and-mutators)
I use the abbreviation "acc"
Usage: Inside Models, 
```
//In case you don't remember the complete class name
//use Illuminate\Database\Eloquent\Casts\Attribute;

protected function ${funcion}():Attribute{
    return Attribute::make(
        get:fn(string $value)=>${whatever_I_need},
    );
}
```

Anonymous function
Abbreviation: afun
Usage: every time I need to create an anonymous function
```
function() {
    ${cursor}
}
```

Array item => PHP variable
Abbreviation: key
Usage: To save keystrokes while assigning key-pair values in arrays where the value is the same name as the variable name.
Example:   'variableName' => $variableName,
$array = [
&nbsp;&nbsp;&nbsp;&nbsp;'variableName' => $variableName,
];
```
'${variable}${cursor}' => $$${variable},
```
Array item => PHP variable within class
Abbreviation: keyt
Usage: Same as previous, but within class so it has the $this->  as prefix.
Example:
$array = [
&nbsp;&nbsp;&nbsp;&nbsp;'variableName' => $this->variableName,
];

```
'${variable}${cursor}' => $this->${variable},
```

Where Code templates shine the most for me is in blade templates. **Remember from my last post I use Bootstrap** The Idea remains the same when using Tailwind CSS or your favorite CSS library.

This code templates need to be created under the HTML language. They work great in blade templates and more generally speaking, outside the php start tag.

Input Group - Bootstrap 5
Abbreviation: ig5

```
<div class="input-group mb-3">
    <span class="input-group-text icono fa-search"></span>
    <div class="form-floating flex-grow-1">
        <input type="text" class="form-control" name="${name}"${cursor} value="{{ old("${name}") ?? $$${name} ?? '' }}">
        <label>${label}</label>
    </div>
</div>
```

Container
Abbreviation: cont

```
<div class="container">
    <div class="row">
        <div class="col">
            ${cursor}
        </div>
    </div>
</div>
```

Bootstrap 5 Row
Abbreviation: row

```
<div class="row">
    <div class="col">
        ${cursor}
    </div>
</div>
```

Bootstrap 5 Column
Abbreviation: col

```
<div class="col">
    ${cursor}
</div>
```

Bootstrap 5 Card
(that .icono class is a Custom *me* thing)
```
<div class="card">
    <h5 class="card-header">${cursor}</h5>
    <div class="card-body">
        ${cursor}
    </div>
    <div class="card-footer">
        <a href="#" class="btn btn-secondary icono fa-ban">Cancelar</a>
        <button class="btn btn-primary icono fa-save">Guardar</button>
    </div>
</div>
```

Bootstrap 5 formatted table

```
<table class="table table-hover table-striped">
    <caption><h5></h5></caption>
    <thead>
    <tr>
        <th>${Header}</th>
        <th>${Header2}</th>
    </tr>
    </thead>
    
    <tbody>
                <tr>
                    <td>Cell1</td>
                    <td>Cell2</td>
                </tr>
                @forelse($datos as $k=>$v)
                <tr>
                    <td>{{ $v->id }}</td>
                    <td>{{ $v->campo }}</td>
                </tr>
                @empty
                <tr>
                    <td colspan="20"></td>
                </tr>
                @endforelse
            </tbody>
</table>
```

I may/will edit this post in the future to include a link to my [Github](https://github.com/jcrodsolutions/nbc) repo where you can download my code templates. Currently there's not much to see there... yet.

In case you are wondering, you can achieve the same in VSCode but I just prefer Netbeans. 
Have a quick look:
Under Blade user snippets you can define your templates. This is an example of the same ig5 template I already showed to you.

```
	"input group bs5": {
		"prefix": "ig5",
		"body": [
			"<div class=\"input-group mb-3\">",
			"<span class=\"input-group-text icono fa-search\"></span>",
			"<div class=\"form-floating flex-grow-1\">",
			"<input type=\"text\" class=\"form-control\" name=\"$name\" value=\"{{ old(\"$name\") ?? $$name ?? '' }} \">",
			"<label>${label}</label>",
			"</div>",
			"</div>",
		]
	},
```

**Remember: ** make it yours! You are the artisan and your IDE is your tool. Master it! Laravel is just a technique.