Configuring Kai Sassnowski Laravel Shareable Models Package on Laravel 5.5

Sometimes we want to share our application resource with an authorized person only not publically. Laravel Shareable Models Package helps us to do so.It allows us to set a resource publically available or restricted. In this tutorial, we are going to create an application to generate sharable links using Laravel Shareable Models Package written by Kai Sassnowski.The Complete source code of this package is available at package allows you to generate shareable links from your Eloquent Models.

ksassnowski laravel shareable models Create shareable links from your eloquent models.

Requirements to install Laravel Shareable Models Package

Laravel Shareable Models Package required PHP ^5.6.4|^7.0.8 and Laravel >= 5.4 .In this tutorial we are using Laravel 5.5.

Step1: Creating Laravel 5.5 Project

In order to install Laravel on your server, please run follwing commands

composer create-project –prefer-dist laravel/laravel Laravel5.5

It will take few minutes to install a brand new laravel framework on your server. Once installation process is completed. Open your terminal or command promt change your present working directory to your project’s root folder and type php artisan serve on your terminal.You get output something like below

Laravel development server started: 

Step2: Setting up you Database

In this step I can show you how to setup or configure database in Laravel.Setting up database in laravel is very easy task.Just goto your projects root folder and open your .env file and change below configrations and save it.

DB_HOST= // your host
DB_PORT=3306 // your mysql port
DB_DATABASE=homestead // your database name
DB_USERNAME=homestead // your database user name
DB_PASSWORD=secret // your database password.

Step3 : Installing Laravel Shareable Models Pacakage

You can install above package by running below command on terminal

 composer require sassnowski/laravel-shareable-models 

Register the Service Provider

In laravel 5.5 package auto discovery support is introduced you don’t need to register it manually in Config/app.php.But if you are running Laravel 5.4 you need register it in you config/app.php

// app/config.php

'providers' => [

Step4 : Running Table migrations to create the shareable_links table

Please run below command on terminal to create table migrations for LaravelShareableModel Package

php artisan migrate
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated:  2014_10_12_000000_create_users_table
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated:  2014_10_12_100000_create_password_resets_table
Migrating: 2017_05_21_232515_create_shareable_links_table
Migrated:  2017_05_21_232515_create_shareable_links_table
Migrating: 2017_08_30_200213_add_should_notify_column_to_shareable_links_table
Migrated:  2017_08_30_200213_add_should_notify_column_to_shareable_links_table

Step 5 : Registering the middleware

open your app/Http/Kernel.php and add the following line to the $routeMiddleware array in order to register the middleware that comes with this package.

protected $routeMiddleware = [
    'shared' => \Sassnowski\LaravelShareableModel\Http\Middleware\ValidateShareableLink::class,

Now we have successfully installed and configured Laravel Shareable Models Package with Laravel 5.5.In next tutorial we are going to create a real world application to make sharable or locked urls using this package.


Leave a Reply

Your email address will not be published. Required fields are marked *