Puti’s Update — Week 9

Puti Larasati
Inspire Crawler
Published in
4 min readApr 24, 2016

This week I am continuing to finish my task. Previously i have done contact page and FAQ page. But I am making some changes to make the page integrate with Laravel.

FAQ Page

I am finalizing the FAQ page by inserting some question and answer. I am developing this pages on localhost and push the source code to our repository.

Preview FAQ page

Contact Page

I’ve encountered lots of troubleshooting problem for this task. And I haven’t finished this task yet, because of this troubleshooting problem. It’s taking a lot of my time to develop this page. Let me breakdown the problem to you.

Form class Not Found

While making the view of this page, I am using this code below

{!! Form::open(array(‘url’ => ‘contact_request’)) !!}<div class=”form-group”>
{!! Form::label(‘name’, ‘Name:’, [‘class’ => ‘control-label’]) !!}
{!! Form::text(‘name’, null, [‘class’ => ‘form-control’]) !!}
</div>
<div class=”form-group”>
{!! Form::label(‘email’, ‘Email:’, [‘class’ => ‘control-label’]) !!}
{!! Form::text(‘email’, null, [‘class’ => ‘form-control’]) !!}
</div>
<div class=”form-group”>
{!! Form::label(‘message’, ‘Message:’, [‘class’ => ‘control-label’]) !!}
{!! Form::textarea(‘message’, null, [‘class’ => ‘form-control’]) !!}
</div>
{!! Form::submit(‘Submit’, [‘class’ => ‘btn btn-primary’]) !!}{!! Form::close() !!}

The syntax I am using is supposed to be provided by Laravel. But for the current version it needed to be embedded manually. Then i google and found the solution. First you need to add text below to your composer.json file.

“laravelcollective/html”: “^5.2”

Then you need to run

composer update

After that, you can add text below to your app.php file

// to providers
Collective\Html\HtmlServiceProvider::class
// to aliases
‘Form’ => Collective\Html\FormFacade::class,
‘Html’ => Collective\Html\HtmlFacade::class,

Then the problem is solved. Below are the screenshots of the page,

Preview of Contact Page

Sending mail from Form input

In order to send mail we need a third party application name Mailgun. By mailgun we are going to send mail to our developer email (currently my email) which filled with question from users. First we need to add text below to composer.json file.

“guzzlehttp/guzzle”: “~4.0”

Then run composer update. And sign up at mailgun.com. After making an account i am going to use sandbox for this purpose. Then edit your .env file to

MAIL_DRIVER= mailgun 
MAILGUN_DOMAIN = sandbox……..mailgun.org
MAIL_HOST = smtp.mailgun.org
MAIL_PORT =587
MAIL_USERNAME = postmaster@sandbox……….mailgun.org
MAIL_PASSWORD = 0maigunpassword
MAILGUN_SECRET = key-………..
MAIL_FROM = ticket@sandbox……….mailgun.org
MAIL_ENCRYPTION=tls

then edit your services.php file to

‘mailgun’ => array( 
‘domain’ => ‘sandboxXXXXXXXXXXXXXXXXXXXXXXXXXXXX.mailgun.org’, ‘secret’ => ‘key-65c33f1xxxxxxxxxxxxxxxxxxxx’,
),

and then edit your mail.php file into

‘driver’ => ‘mailgun’, 
‘host’ => ‘smtp.mailgun.org’,
‘port’ => 587,
‘from’ => array(‘address’ => ‘mail@xxxxxx.com’, ‘name’ => ‘Xxxxxxxx’),
‘encryption’ => ‘tls’,
‘username’ => null,
‘password’ => null,
‘sendmail’ => ‘/usr/sbin/sendmail -bs’,
‘pretend’ => false

Then you can test it by using

Mail::raw(‘test’, function($message) { 
$message->to(‘foo@example.com’);
});

But i am still getting an error, and i haven’t been able to fix this issues.

API Overview

To make documentation page we’re using tools called APIdocs. By using this tools we can easily generate documentation of the API. First of all we need to give comment for each method we’re using on API. Below are some comment I’ve made

/** 
* @api {get} /api/getQuote/:jumlah Mendapatkan quote dari database secara acak sesuai jumlah
* @apiName GetQuote
* @apiGroup Quote
*
* @apiParam {Jumlah} jumlah Banyak quote yang ingin didapatkan
*
* @apiSuccess {String} _id id dari quotenya
* @apiSuccess {String} quote Isi dari quotenya
* @apiSuccess {String} author Pencetus quotenya
* @apiSuccess {String} category Kategori dari authornya, jika belum * dikategorisasi, maka null
* @apiSuccess {String} language Bahasa dari quote tersebut
* @apiSuccess {String} source Sumber website quote tersebut
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK
* {
* “_id”: {
* “$oid”: “57164739be1b0517794090ec”
* },
* “quote”: “We know what we are, but know not what we may be”,
* “author”: “William Shakespeare”,
* “category”: null, * “language”: English,
* “source”: “http://www.brainyquote.com/quotes/authors/w/william_shakespeare.html”
* }
*
*/

After making the command we’re going to run

apidoc -i app/ -o apidoc/

And voila, the documentation are made!

Preview of API Documentation
Unlisted

--

--