How to get started with Laravel Wink.

Posted 17th Dec 2018

I have used a lot of blogging platforms or content management systems in the past. Up until a few years ago I was a very big WordPress user, I used it for almost everything.

Then I fell more in love with back-end programming, specifically PHP and the Laravel framework. Since then I've been looking for a blogging alternative that's a good as WordPress but that allows as much customisation as I need.

Then a few weeks ago, one of the main developers of the Laravel framework came out with his own. Wink.

Wink is great becuase it gives you all the back-end features you need to get up and running in minutes, but allows you the flexibility to do whataver you want with the front-end. This was a perfect fit for me. Here's how I went about using Laravel Wink.

I want to start by mentioning that Laravel Wink is still quite new, and will probably continue to have regular updates over the next few months. That doesn’t mean to say that we shouldn’t start using it now.

I’m going to assume here that you’re already familiar with Laravel, and that you already have your Laravel application ready. If you’re not, you should head on over to their documentation and check it out

Adding Wink to your Laravel app 

As Laravel Wink is a composer package, installing it requires only a few commands.

composer require writingink/wink
php artisan wink:install

Once you've done that, you'll need to migrate all the databaase tables that come with Laravel Wink.

php artisan wink:migrate

That's all there is to installing Wink. Now you should be able to navigate to /wink, use the username and password it generated for you and log in.

However, that's just the backend. What about displaying those posts and pages you've created? This is how I went about it.

Firstly you'll need a new controller to handle the blog index page, the individual post page and the custom pages that you might make.

php artisan make:controller WinkController

Within your controller, you'll need to create 3 different methods to handle the different content generated by Wink.

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Wink\WinkPost;
use Wink\WinkPage;

class WinkController extends Controller
{
  public function index()
  {
		$posts = WinkPost::with('tags')
			->live()
			->orderBy('publish_date', 'DESC')
			->simplePaginate(12);

		return view('blog.index', compact('posts'));
  }

  public function show($slug)
  {
		$post = WinkPost::with('tags')
			->live()
			->whereSlug($slug)
			->firstOrFail();

		return view('blog.show', compact('post'));
  }

  public function page($slug)
  {
		$page = WinkPage::whereSlug($slug)
			->firstOrFail();

		return view('page.show', compact('page'));
  }
}

Now you'll need to create the routes that pair up with these methods. Open up your routes file, and add these 3 routes.

Route::get('/blog', 'WinkController@index')->name('blog.index');
Route::get('/blog/{slug}', 'WinkController@show')->name('blog.show');
Route::get('/{slug}', 'WinkController@page')->name('page.show');

That's it for the routes and controller. Now all you need to do is create some views to display your content. Here's something simple to get you started.

blog/index.blade.php

@foreach($posts as $post)
	<h2><a href="{{ route('post.show', $post->slug) }}">{{ $post->title }}</a><h2>
	<span>Posted on {{ $post->publish_date->format('dS M Y') }}</span>
	<p>{{ $post->excerpt }}</p>
@endforeach

{{ $posts->links() }}

blog/show.blade.php

<h1>{{ $post->title }}</h1>
{{ $post->body }}

page/show.blade.php

<h1>{{ $page->title }}</h1>
{{ $page->body }}

That's it, that's all you need to start working with Laravel Wink.

To make it easier for you, I've added all this to a public github repo so you can clone it and have a dig around for yourself.

Check out the repo here.