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