Eric Barnes

Eric Barnes

CodeIgniter, Development, Life, and Whatever else

Laravel Blade

Laravel Blade

Mar 25

Blade is the simple template/theme system built into Laravel and up until this point it has been very basic. It supported most of the simple things such as variables {{ $var }}, @if @else, @section, and finally a thing called @yield.

Because of the simplicity of it on a new project I thought we would need something more advanced and went with Twig. Twig had more features and was more powerful but it also didn't really fit into my workflow. The biggest problem was working with Eloquent results and twig doesn't like calling results like this:

foreach (Book::with('author')->get() as $book)
{
    echo $book->author->name;
}

I asked Taylor about it and he did a few changes to get that working but then I had troubles with other calls. So it just felt like it was more of a fight than what it was worth. After discussing this, last week Taylor and Shawn McCool really made Blade awesome. First Shawn recommended a "render_each" method. Which is an excellent feature in my opinion. It works my including a looped view:

<ul>
    {{ render_each('categories.list', $categories, 'cat') }}
</ul>

// categories/list.blade.php
<li>{{ $cat->name }}</li>

As you can see that is a big time saver. But it doesn't stop there. Now Blade can have layouts inheritance and several other really useful goodies:

@layout('layouts.common')

@section('content')

    <p>My content</p>

@endsection

Then inside layouts.common:

<html>
<head>
    <title>Test</title>
</head>
<body>
    @yield('content')
</body>
</html>

This is just some of the basics of the new features and it does a lot more. Although I don't consider it a full replacement for Twig it has 90% or more of the features I wanted to use. The biggest missing feature (depending on your needs) is that Blade still just parses as php. So it can call things that are not assigned and doesn't prevent you from using php code in your views. Personally I like that feature but if you are really wanting to limit what people can do in the views then this may not be ideal. So use what is best for the task at hand.

For a video overview of what is coming please watch this:

Learning from source code

Learning from source code

Mar 14

Shawn McCool over at Big Name posted a video discussing learning from the source code. This video is Laravel specific but it does hit on the point that the docs are almost never 100% complete compared to the actual source code. So by spending that extra few minutes reading that you can understand exactly what is going on.

While you are on his site check out his other great Laravel videos.

Switched to Kudos

Switched to Kudos

Mar 13

This site is now powered by Kudos a markdown based personal publishing platform created by Ian Landsman.

At it's core it is a simple text based blog engine but I was really drawn in because managing everything in my normal work flow just makes sense.

I use Sublime Text to write my posts, then a simple git push to Pagodabox auto deploys and everything is great. What I really like is all my content is stored in git with a full backup at any time. Instead of relying on the third party I was before.

The Kudos script does have a WIP branch where I have made all the changes I needed for this site. Basically it is allows a text based Tumblr clone. Since that is what I am coming from.

Future Changes

Although I really like the setup I have I am not entirely happy with the way Kudos has you write and publish articles. I am thinking for my work flow it would be easier to use artisan to create your new post. Then open it, write your content, verify locally, and finally push. Of course I do every thing locally before pushing so I probably have a different workflow than most.

Comments?

Kudos does allow for disqus but I have decided I am just not going to use comments any more. I really didn't get that many and one less hassle to deal with. With twitter, email, and every other communication medium if you have something to say let me know and I will update the post.

Laravel Sublime Text Snippets

Laravel Sublime Text Snippets

Mar 09

If you use the Laravel php framework and Sublime Text I highly recommend you try the new snippets Dayle Rees created. It really does speed up your development and is really nice.

You can get all the code from GitHub: https://github.com/laravel/sublime-snippets

Laravel Bundle Assets

Laravel Bundle Assets

Feb 25

The past few weeks I have been building a few Laravel bundles and one of the features of bundles is the ability to have assets that are moved to your public folder during install. This is great when your bundle has css, js, images, etc..

The downside to this though is that while building the actual bundle it is a pain to keep having to run the following command each time you change a file:

php artisan bundle:publish

I have came up with a few different options to make this easier for developers. The first method which I believe would be supported across every os is to symlink the assets to public/bundles/folder/. However the down side to this is you have to add new symlinks when you add new files. So not ideal for the way I typically develop.

The second option is specific to mac but it works wonderfully. What I have done is purchase live reload and use it to run the bundle publish command. The reason I originally purchased the app was because I am using less for my css and I liked the fact that it would compile the css and also refresh your browser so you can see changes instantly.

The bigger benefit is live reload allows you to run terminal commands after you save and before it refreshes your browser. So all you have to do is add in your artisan command and not have to worry about it again. Here is a screenshot showing this:

Hopefully this will help you if you are building bundles with public assets. If you have any other tips please post them in the comments.

Sublime Text - Shell Turtlestein

Sublime Text - Shell Turtlestein

Feb 23

The Sublime Text plugin allows you to run shell commands directly in the editor. I have found this to be a wonderful plugin and a huge time saver.

If you are a Sublime user go and install this now. You will thank me later.

Safari Extensions

Safari Extensions

Feb 19

I decided I am going to finally give Safari a real trial. Previously I was using Firefox then switched to chrome and now ready for something different.

The two things that has always bothered me about Safari is the tab switching and the view source. I found two extensions to fix these issues:

The tab switching is great but I am still not completely happy with the better source. When I view source I like to be able to click asset links from viewing the source. From what I have seen this just isn’t possible in Safari.

New Laravel Bundle App

New Laravel Bundle App

Jan 23

Since starting at UserScape I have been tasked with building a new bundle application for the Laravel framework. So far all the work has been done “behind the scenes” but I wanted to share a few screenshots of what I have completed so far.

Home Page

This is a temporary home page which showcases the latest and the most popular. Currently the most popular will be determined by number of installs but I have some ideas for better stats and filtering that will come later.

Bundle Grid

This is the grid list. I tried keeping it simple so you can quickly scan the titles and also show each users gravatar for branding.

I am really happy with what I have completed so far and it should be a simple and effective way for users of the framework to find pre-built code to put in their applications.

If you are interested in seeing how to create a bundle check out Taylor’s Videos

Kudos. Markdown based personal publishing.

Kudos. Markdown based personal publishing.

Jan 22

A nice and simple flat file markdown based blog application built by Ian Landsman for use on his site. The description says:

I built this to run ianlandsman.com over a weekend :) It may not work for you. I’m posting it up in case anyone else may find it useful. It might also be useful to those interested in working with the PHP Laravel framework.

Although he states it isn’t complete yet from my tests it works like it supposed to but still missing a few small features. I like the setup and the use of the command line to publish the posts and clear the cache.

The Api And Plug In Architectures Are The Highest Jan 07
The API and plug-in architectures are the highest priority. Another way of putting that is: never build anything in-house if you can expose a basic API and get those high-value users (the ones who are getting the most value out of the platform) to build it for you. On the Trello team, any feature that can be provided by a plug-in must be provided by a plug-in.

Joel Spolsky