In this case, you’ll build a link preview and an URL shortener modules that run behind the scene.

In the previous part, you built the timeline. You’ve crafted the Tweet table right. It is ready for the heavy job.

You allow your user to create a tweet. Like I mentioned before, creating a tweet is easy, it is an insert query. Behind this simple feature, you’ll add two features to make the tweet becomes more interactive and meaningful.

Alright, let’s summarise your planning,

Create a post box on Home page to tweet Generate link preview for the URL user tweeted Shorten the URL tweeted by user

Rebuild Twitter with Laravel was started before the Laravel 5.4 was released. This project is based on Laravel 5.3. It is been awhile and this project is going to left behind very soon (5.5 is coming soon).

So, let’s update to 5.4.

3 steps to upgrade to 5.4 from 5.3

It is easy to upgrade the project, it needs only 3 steps.

Step 1 — composer update

Update your project’s dependency of laravel/framework from 5.3.* to 5.4.* and phpunit/phpunit to ~5.7 in composer.json.

// composer.json

"require": {

"php": ">=5.6.4",

"laravel/framework": "5.4.*"

},

"require-dev": {

"fzaninotto/faker": "~1.4",

"mockery/mockery": "0.9.*",

"phpunit/phpunit": "~5.7",

"symfony/css-selector": "3.1.*",

"symfony/dom-crawler": "3.1.*"

},

Perform composer update.

// Terminal

composer update

Step 2 — Reinstall Laravel Tinker

Somehow, in the Laravel upgrade guide, it recommends reinstalling Laravel Tinker.

// Terminal

composer require laraval/tinker

Add TinkerServiceProvider in config/app.php.

// config/app.php

'providers' => [ ...

Laravel\Tinker\TinkerServiceProvider::class, ],

Step 3 — Clear cache

Once you’ve upgraded the project, the application may still cache the compiled services from the previous version.

Remove compiled services file bootstrap/cache/compiled.php

After that, flush the view cache.

// Terminal

php artisan view:clear

Compiled views cleared!

Alright, these are the basic instructions to update from 5.3 to 5.4. If you want more in detail, check it out here.

Migration

Create a new table for storing the links from the tweets. Whenever user tweet with a link in the body, extract the link and insert into the Link table.

// Terminal

php artisan make:model Link -m

Model created successfully.

Created Migration: 2017_05_23_031547_create_links_table

// database/migrations/2017_05_23_031547_create_links_table.php

class CreateLinksTable extends Migration

{

/**

* Run the migrations.

*

*

*/

public function up()

{

// Create Links table

Schema::create('links', function (Blueprint $table) {

$table->increments('id');

$table->string('url')->unique();

$table->string('cover')->nullable();

$table->string('title')->nullable();

$table->text('description')->nullable();

$table->string('short_url')->nullable();

$table->timestamps();

});

} // database/migrations/2017_05_23_031547_create_links_table.phpclass CreateLinksTable extends Migration/*** Run the migrations. @return void*/public function up()// Create Links tableSchema::create('links', function (Blueprint $table) {$table->increments('id');$table->string('url')->unique();$table->string('cover')->nullable();$table->string('title')->nullable();$table->text('description')->nullable();$table->string('short_url')->nullable();$table->timestamps();});

* Reverse the migrations.

*

*

*/

public function down()

{

Schema::dropIfExists('links');

}

} /*** Reverse the migrations. @return void*/public function down()Schema::dropIfExists('links');

// Terminal

php artisan migrate

Migrated: 2017_05_23_031547_create_links_table

// app/Link.php

class Link extends Model

{

protected $fillable = [

'url', 'cover', 'title', 'description',

]; public function tweets()

{

return $this->hasMany('App\Tweet', 'link_id');

}

}

Alright, let’s craft the view.

Craft the view

Sample first is a very good framework on knowing what kind of information you need to pass to the view.

You build a sample link preview layout on the Home page.