Laravel migrations are a type of version control for your database. They allow a team to modify the database schema and stay up to date on the current schema state. Migrations are typically paired with the Schema Builder to easily manage your application’s scheme. In my last laravel post, I talked about laravel models. I also promised to show you how to create tables that you will need to store your blog posts(models) in your next blogging platform. Let us do this.
At this point, I assume that you already have a working database and you have configured it in your laravel application under app/config/database.php. Now we can move on.
A Laravel Model makes it very easy to store, read (retrieve), update and delete (CRUD) a resource in a Laravel application. In this post, I am going to show you how to use a laravel model to manage blog posts. I touched on this in my previous post when I talked about using laravel resource controllers here. The Eloquent ORM included with Laravel provides a beautiful, simple ActiveRecord implementation for working with your database. Each database table has a corresponding “Model” which is used to interact with that table.
A Laravel resource controller makes it easier to build RESTful controllers around resources. For instance, you may wish to create a controller that manages “blog posts” stored by your application. Normally, you use a laravel resource controller to group common routes in one class. In this post, I will show you how to create a resource controller that we will, in the future, use to manage blog posts in a demo application. Let us do it!
In your routes.php, you would add routes like this:
$posts = Post::all();
return View::make('posts')->with('posts', $posts);
$post = Post:find($id);
return View::make('posts')->with('post', $post);
//add like 20 more routes here and you start to see a problem creep in
Anatomy of a blog post
The Response::download buffer problem is an issue that causes the output buffer to not be discarded and buffering is not turned off in PHP. Figuring out that you have this problem is not an easy task – Scott and I spent quite some time trying to find out why our images were not being rendered by our browser while working on a laravel project. That being said, we went to work – really went to town and tried to solve this issue. After a significant amount of caffeine, we found the solution – thanks in part to Scott’s relentless effort (I know he is reading this). So, here is the workaround.
Laravel Framework is a popular PHP framework that is taking the web development community by storm. Heck, I never thought I would ever use PHP until I started using Laravel. So what made me give it a shot? I will make this short; we had to take over a laravel project from another guy at work! After a couple of months of using it, I was so impressed that I started using it on my major project that I initially wanted to write in Python. Yeah, so you can take me up on that because it is pretty damn cool. Anyway, in this post, I will just touch on a few things to prepare for further posts where we will create a simple web application using the awesome Laravel framework.