Create A Self-destructing, Encrypted Message App In Laravel Part 2

Posted on · Tagged in

The first thing we’ll need to do is create a default layout. This is the layout that the rest of our views will extend. Let’s save it as ‘app/views/layouts/default.blade.php’.

<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Burnmsg - Self-desctructing, encrypted messages</title>

    <!-- Bootstrap core CSS -->
    <link href="{{ asset('css/styles.css') }}" rel="stylesheet">

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src=""></script>
      <script src=""></script>


    <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
      <div class="container">
        <div class="navbar-header">
          <a class="navbar-brand" href="{{ route('messages.create') }}">Burnmsg</a>

    <div class="container">
    </div><!-- /.container -->

    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src=""></script>
    <script src="{{ asset('js/bootstrap.min.js') }}></script>

Now we need to make sure that Twitter Bootstrap is accessible. Bootstrap is installed into the ‘vendor’ folder of our project by composer. First let’s copy the Javascript libraries.

$ cp vendor/twitter/bootstrap/dist/js/bootstrap.min.js public/js  

We also need the CSS stylesheet but we are going to need to tweak some of the styles. We are going to do this using LESS.

$ touch public/css/styles.less  

In our newly created LESS file we will import the original stylesheet and make our tweaks as needed.

@import "../../vendor/twitter/bootstrap/less/bootstrap";

body {
    padding-top: 65px; /* bring body to bottom of navbar */

article {
    white-space: pre-wrap;

LESS makes it easy to work with CSS but it needs to be “compiled” in order for the browser to understand it.

$ lessc public/css/styles.less > public/css/styles.css  

I use ‘lessc’ which is a Ruby gem but you can use any LESS compiler. Google should bring up a handful of options.

Now all that is left is to create our various views which correspond to the different actions involved in our application. Let’s save these views in ‘app/views/messages’.

The first view ‘create.blade.php’ will represent our message creation form. Notice that it ‘@extends’ our default layout and renders the form within the ‘content’ section which is referenced in the default layout.


    {{ Form::open(['method' => 'post', 'route' => '', 'class' => 'form']) }}
    <div class="form-group">
            <div class="alert alert-danger">
                {{ $errors->first() }}
        {{ Form::label('body', 'Message') }}
        {{ Form::textarea('body', null, ['class' => 'form-control']) }}
    <div class="form-group">
        {{ Form::submit('Submit', ['class' => 'btn btn-primary']) }}
        {{ Form::close() }}

Once the message is submitted our ‘store.blade.php’ view will display a link for the user to copy and give to whomever they wish for later reading.


    <div class="alert alert-success">
        Your message has been saved.
        Here is the URL <a href="{{ route('', [$url, $key]) }}">{{ route('', [$url, $key]) }}</a>

Lastly the ‘show.blade.php’ view will display the message for the user once they decide to read it.


    {{{ $body }}}

Now we should have a pretty sweet messaging app that destroys your message upon reading. Keep in mind that I am no cryptography or digital forensics expert so rely on this application at your own risk. Go ahead and modify it to make it more secure if you like. Leave any suggestions you may have in the comments.


comments powered by Disqus
Subscribe to my newsletter and get a free copy of my book, Aspect Oriented Programming in PHP.