Nasrul Hazim Bin Mohamad

4 Essential Laravel Packages for Your Web Application Development

Dec
20

Assalamualaikum,

Recently I’ve been working with developing Laravel packages for my own use and Laravel’s community. It’s quite fun and interesting how you can separate the modules or features from Laravel’s main application and make it as a package, which later on you can reuse it over and over again.

Here are some of the packages I’ve created so far. You may want to try it out, and please do make a report if there’s any issues.

  1. Artisan Extended – this package mainly to add more artisan commands to simplify and speed up your development progress. Here the list of commands available:
    1. clear:cache – Put application under maintenance, clear common caches files, and put the application up again
    2. clear:serve – Run clear:cache and serve the application
    3. make:route – Create a new route
    4. make:view – Create a new plain view or resourceful view
    5. make:resourceful – Create a new resourceful controller
    6. make:scaffold – Create a new model, migration, resourceful controller and views (but still, need to enhance to accept columns details)
    7. secure:cookie – Secure your cookie
  2. Themer – The package main purpose to support theming in Laravel’s applications. It’s provide a middleware, and an artisan command(make:theme) to create a new theme.
  3. Setting – A simple helper to have a setting for your application.
  4. Subscriptions – The package is used for SaaS based applications. It’s allow you to add new package services, and enable your customers to subscribe to your SaaS application.
Sample Subscription Implementation in SaaS Application

Sample Subscription Implementation in SaaS Application

Do play around with the packages, and do report issues if there’s any, or if you think there’s need enhancement, do submit your proposal.

Laravel: Artisan Extended – make:route

Dec
14

Assalamualaikum,

Yesterday, I’ve shared ideas on how to manage your Laravel’s route in Laravel: Managing Routes post.

Today, I want to share with you guys how to create easily the resourceful route, with or without prefix (yes, you can make route version too!).

First thing first, let’s create a new Laravel project and require the Artisan Extended package to your Laravel Project.

Once you’re done with installation of Artisan Extended package, you may run now in terminal the following commands:

php artisan make:route Post

This will create a new Routes directory in your app folder, and a file named Post.php(app/Routes/Post.php), and you will have \App\Routes\Post::routes(); in your routes/web.php. You may run php artisan route:list to check the route created just now.

Now, let say you want to add prefix to your route:

php artisan make:route -p v1 Post

Then, you will have \App\Routes\V1\Post::routes(); in your routes/web.php

How about I want a prefix of V1, but I want to differentiate between admin and normal user? Here how you can do it:

php artisan make:route -p v1 Admin/User && php artisan make:route -p v1 User

Now you should have \App\Routes\V1\Admin\User::routes(); and \App\Routes\V1\User::routes(); in your routes/web.php.

That’s it. It’s easy now to manage your routes.

All your routes will be store in app/Routes directory from now on and you just need to update your route files manually in case you need some extra routes in the class.

Here are some other tricks you may use:

php artisan make:route -m web,auth -p v1 Post

This will create a route in app/Routes/V1/Post.php and having middlewares of web & auth in routes/web.php

php artisan make:route -m auth:api,jwt -p v1 -a Post

This will create a route in app/Routes/API/V1/Post.php and having middlewares of auth:api & jwt in routes/api.php

Please take note that, the make:route is intended for resourceful route.

There’s some other useful Artisan commands available in Artisan Extended package, you may want to read here.

More test & result:

Create Routes

Create Routes

The Routes Structure

The Routes Structure Generated

Resourceful Controllers Automatically Created If Not Exist

Resourceful Controllers Automatically Created If Not Exist

Routes for Web

Routes for Web

Routes for API

Routes for API

Laravel: Managing Routes

Dec
13

Assalamualaikum,

Recently I’ve meet some of my friends, and clients working with Laravel projects. It’s seems that, Route, managing routes is quiet painful when your application become bigger and you have to handle a lots of routes.

So, what’s come out of my mind was, how to manage Laravel’s routes more efficient?

I’ve come up with few possible options:

  1. Define more map methods in RouteServiceProvider, and call them – but this will make the RouteServiceProvider full with map methods, which I don’t prefer it that way – to many mapping routes method.
  2. Then I’ve come up with ideas having route trait, then you just need to attach it to any classes which you prefer, then call it any RouteServiceProvider or in routes/web.php. But having trait just to manage the routes, it’s like overkill (up till now), so I skip creating the trait.
  3. Then I’ve come up with having another route folder, purposely to serve the routes – I’ve named it Routes, in app directory. In the Routes directory, you create a class,  and have a method routes. In that method you just need to define your route – but of course, you need to import Route facade. Below is an example of implementation.

Now you should have much cleaner codes in your routes/web.php. You just need to include the route namespace, and call the className::routes() to load the routes.

That will be much cleaner routes. You may want to structure your app/Routes directory to support route’s version, or prefix, etc.

Hopes the idea will help out developers to easily manage their projects.

Hope the approach won’t break the incoming Laravel releases! ^_^

I think that’s what I want to share for now. Thanks for reading!

7 Essential Sublime Text Plugins

Dec
08

Asssalamualaikum,

screen-shot-2016-12-08-at-12-26-58-pm

I’ve been using Sublime Text, quiet sometimes for web applications development. Below are the list of packages installed on my Sublime Text:

  1. SideBarEnhancements – Add more context menu on right click to file or folders
  2. phpfmt – Use for Auto Format to PSR-2
  3. Material Theme – Better UI
  4. Emmet – HTML Helpers
  5. Git – Git Commands
  6. GitGutter – Display changes icon beside line numbers
  7. Markdown Extended

And following are my Sublime Text settings:

{
	"bold_folder_labels": true,
	"color_scheme": "Packages/Material Theme/schemes/Material-Theme.tmTheme",
	"font_size": 23,
	"format_on_save": true,
	"highlight_line": true,
	"ignored_packages":
	[
		"Vintage"
	],
	"line_padding_bottom": 10,
	"line_padding_top": 10,
	"php_bin": "/replace/with/path/to/your/php/bin",
	"show_panel_on_build": true,
	"theme": "Material-Theme.sublime-theme",
	"use_simple_full_screen": true
}

Continuous Integration (CI)

Dec
04

Assalamualaikum,

Yesterday (Dec 3rd, 2016), I’ve a day trip to Kempas, Johor to attend to a monthly event by JomWeb Johor, listening to a talk on Continuous Integration by Kamal Mustafa.

Here the summary from the talk and definitely I need a look into test the application cycle before release it – which usually I don’t.  ^_^

Development without Continuous Integration:

  1. Hard to track down the bugs
  2. Infrequent Commits
  3. Difficult Integration
  4. Infrequent Release
  5. Testing Happens Late

CI Tools / Software

  1. Travis
  2. Jenkins
  3. Gitlab
  4. BitBucket

Travis is an online service to provide the CI process while Jenkins is desktop application.

While Gitlab and BitBucket, both are Git Platform but providing a tool named Pipelines which enabled developers to do the CI process.

Notes on Test

  1. End-to-end testing
  2. Transaction, Non-transaction
  3. Unit Test – doesn’t mean require a database for testing
  4. Always drop the test database after testing
  5. Alway automate the test
  6. Code Linting
  7. Deployment test can be on local, staging or  production.