Nasrul Hazim Bin Mohamad

Migrate from WordPress to Laravel – Part 1

Dec
22

Assalamualaikum / Hi,

I’ve been using WordPress, since 2012 – 5 years, of service. I think it’s time to migrate to another platform – Laravel. I’ve been reading how murze.be did.

Basically, I got the idea how he did. But, as my sense of explorer, want to learn something new, I read few more articles, packages available out there for migrate from WordPress to Laravel.

I ended up with my own solution.

The idea – use the WordPress REST API.

Of course, I need to prepare my database schema, but I left that part later. What’s important is to grab all the contents from my blog – posts, pages, comments, media, tags, categories and users(since i’m the only author, I don’t have to fetch the user).

Here what I did:

Create the service to call WordPress REST API.

Create an artisan command to fetch all contents.

Do register the artisan command in `Kernel.php`

Then create a `wp` directory in `storage` directory.

So, what I need to do, just call php artisan import:wp http://blog.nasrulhazim.com and I will get as following, store in storage/wp in JSON Pretty Format.

And that’s it for Part 1.

Next, I need to grab all the media, download it to my storage directory.

See you guys on next post.

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

How to Use Lumen in Laravel

Oct
10

You love the speed of Lumen but you want to have the features of Laravel? No problem, just include Lumen inside Laravel!

Below are the steps to include Lumen inside of the Laravel

Please ensure to create an empty Laravel and Lumen project because you need to copy some files from Lumen to Laravel

Here the working sample of the Lumen in Laravel – Lumen in Laravel

Laravel: How to Create Custom Artisan Command

Aug
16

There’s only 3 steps required to setting up new Artisan command.

1. Step 1 – Create a new console file

php artisan make:console CommandName

2. Step 2 – Open up `app/Console/Commands/CommandName.php` and update the signature and the description property.

     /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'env:db';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Configure database settings';

3. Step 3 – Register your new Artisan command in `app/Console/Kernel.php`

    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        // Commands\Inspire::class,
        Commands\DatabaseEnvironment::class
    ];

Now you’re ready with your new artisan command. Check your command with `php artisan`. It should have something like this one.

Screen Shot 2016-08-16 at 6.05.26 PM

Here the a sample code.

Reference

Artisan

Laravel: How to Install Laravel’s Artisan in Windows

Aug
20
$ composer create-project laravel/laravel --pref-dist
$ cd laravel
$ composer install
$ php artisan list

Following are the result

Laravel Artisan List

Laravel Artisan List