laravel.docx

11
The Blog that we will be creating has the following features :  twitter bootstrap layout implemented by bootstrapper bundle  user log in and authentification  display all posts in paginated view  create new posts  delete posts Building with Laravel is very easy. When you know the basics, it will take only 10-15 minutes to build a blog like this from scratch! First, when creating even such a simple application as a three page blog, it is important to have an idea and a plan before even starting to write any code. There are a lot of questions that need to be tackled before coding, such as : how the application will look, which actions can it take and which data it will operate with, what are good practices out there for this kind of application, etc. Before I sat down to write any code for the blog application, I first sketched things on paper   this is called wireframing. Wireframing is very helpful when you are designing an application. It gives a visual idea of how to position things on each page, and what elements will be used on each page   forms, labels, buttons, etc. I provide you with an example sketch I did on a Sticky and the one I would refer to while I was building the blog application. I drew three views of the blog  the index page with all posts, the login page and the page where the user would create new posts. I drew the views having in mind CSS/HTML framework that I use for quick applications  Twitter Bootstrap (http://twitter.github.com/bootstrap/ ), it makes great use of the grid-based layout and speeds up development. This was an extremely helpful first step because when I build a layout and views for my application I already know where things should go and how they will be placed. I encourage you to sketch your web apps before you get to coding them. Sometimes going through many iterations on paper can bring clarity to your project. When the sketches were done, I needed to think what data will my application use and how that data is related to other data in the application, which brings us to the next part of the tutorial where we will learn how to derive a data model and plan our database as a part of building a blog.  A little side topic : If you haven‘t had much experience with Databases, don‘t worry, I will guide you through the process for right now. But I do highly encourage you to take a database design class or at least become a database design freak by talking a walk around where you liv, looking at objects thinking that they are entities, taking them apart in your mind. For example look at the street, what does it have? Houses, roads, cars, people, light poles, etc. Break down every object even further : House consists of windows, walls, doors, roof, paint, etc. Cars consist of shell, wheels, glass, engine, seats, dashboard, lights, exhaust, transmission, etc. I‘m not going to tell you which body parts humans consist of, you know that yourself. This simple exercise makes you into a better database designer, when building an application you will have to break data up into smaller pieces to make it usable.

description

laravel

Transcript of laravel.docx

The Blog that we will be creating has the following features : twitter bootstrap layout implemented by bootstrapper bundle user log in and authentification display all posts in paginated view create new posts delete posts

Building with Laravel is very easy. When you know the basics, it will take only 10-15 minutes to build a blog like this from scratch!

First, when creating even such a simple application as a three page blog, it is important to have an idea and a plan before even starting to write any code. There are a lot of questions that need to be tackled before coding, such as : how the application will look, which actions can it take and which data it will operate with, what are good practices out there for this kind of application, etc.Before I sat down to write any code for the blog application, I first sketched things on paper this is called wireframing. Wireframing is very helpful when you are designing an application. It gives a visual idea of how to position things on each page, and what elements will be used on each page forms, labels, buttons, etc. I provide you with an example sketch I did on a Sticky and the one I would refer to while I was building the blog application.I drew three views of the blog the index page with all posts, the login page and the page where the user would create new posts. I drew the views having in mind CSS/HTML framework that I use for quick applications Twitter Bootstrap (http://twitter.github.com/bootstrap/), it makes great use of the grid-based layout and speeds up development.This was an extremely helpful first step because when I build a layout and views for my application I already know where things should go and how they will be placed. I encourage you to sketch your web apps before you get to coding them. Sometimes going through many iterations on paper can bring clarity to your project.When the sketches were done, I needed to think what data will my application use and how that data is related to other data in the application, which brings us to the next part of the tutorial where we will learn how to derive a data model and plan our database as a part of building a blog.

A little side topic : If you havent had much experience with Databases, dont worry, I will guide you through the process for right now. But I do highly encourage you to take a database design class or at least become a database design freak by talking a walk around where you liv, looking at objects thinking that they are entities, taking them apart in your mind. For example look at the street, what does it have? Houses, roads, cars, people, light poles, etc. Break down every object even further : House consists of windows, walls, doors, roof, paint, etc. Cars consist of shell, wheels, glass, engine, seats, dashboard, lights, exhaust, transmission, etc. Im not going to tell you which body parts humans consist of, you know that yourself. This simple exercise makes you into a better database designer, when building an application you will have to break data up into smaller pieces to make it usable.Lets do that with our blog application. First ask questions, What kind of data are we operating with? What attributes does the data have? How is the data interconnected? Think about that for a minute, please.In a blog there is an author, lets call him/her a user. The user publishes posts, right? So that means we have two kinds of data that should be somehow related: users and posts. Now lets break down each kind further : which attributes do these kinds of data have? In most cases every kind of data has id by default, then users have these attributes: username and password for logging in the system, some kind of name or alias to be displayed (who published the post?), and timestamps information about when the user was created or when the user was updated (in case we want to see history of our applications growth). Lets do the same with Posts, every post has an id, some kind of title, the body of the post (text) and some kind of way of telling by which author the post was published, lets have that as an integer that is taken from Users id, and timestamps that tell us when the post was published and updated.So that structure of our data brings us to the following database design, two tables named Posts and Users with the attributes I described above. Heres the visual representation of the blog tables:

Now using the knowledge that we have learned inpart 3 of the tutorialwe need to build models to relate the database tables to each other.In Laravel models reside in your application/models folder and for clearer code I suggest you separate your models into files corresponding to your database tables. For our blog application we have created two tables by running our migrations,PostsandUsersso now we just need to create two models, User and Post (please note singular, not plural),create two empty files in yourapplication/modelsfolder:user.phppost.phpput [sourcecode]