PHPackages                             install/leggo - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. install/leggo

ActiveLibrary

install/leggo
=============

A MVC based framework for web artist

00[1 issues](https://github.com/thecodestuff/leggo/issues)HTML

Since May 25Pushed 6y agoCompare

[ Source](https://github.com/thecodestuff/leggo)[ Packagist](https://packagist.org/packages/install/leggo)[ RSS](/packages/install-leggo/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

leggo
=====

[](#leggo)

A MVC based framework written in php

Table of content

- About Leggo
- Installing Leggo
- Architecture of leggo framework
- Working of leggo
- Directory Hierarchy of leggo
- Defining your web route
- Creating a controller for you web route
- Creating a view
- Creating a model
- **Database:Migrations**
- What is database migration
- Generating a migration
- Migration structur
- Running a migration
- **Database:Seeders**
- what is seeders
- Writing a seeder
- Running a seeder
- **Framework dependencies**

About Leggo
-----------

[](#about-leggo)

Leggo is a lite MVC based framework which is written in PHP.It is comes with a CLI client to faciliate the rapid development. It is for developers who want to customize the code without worring about what undergoing the hood. Leggo provide you a simple directory hierarchy which you can work with easily. Unlike another heavy weight framework like Laravel, symphony, cakePHP there are not lot of files included in a a single script. A developers can easily figure out which framework file is used by the current scipt/code.The main advantage of this is customization. Now when developers know what going in background they can easily customize the code according to them self. By default a data abstraction layer is provided to intract with database and handle all the sql transactions dynamically. If a developers want to integrate ORM they can integrate ORM of there choice. Leggo uses the concept of template, we can define a template for particular route in templates directory. To access the template we only have to provide a $template\_name variable with the the name of template .Currently it did not uses any template engine . But in later version of leggo developers can eaisly integrate template engine of there choice. Leggo is a pure MVC based framework in which all the data is handle by its views . It provide the power to develop a powerfull, scalable yet secure webapp without hassling with logic part. It facilitate its user to integrate ORM(object relational mapper ) like propel , doctrine etc and template engines of there choice. It did not force user to use any particular

Installing Leggo
----------------

[](#installing-leggo)

You can download leggo to your machine by two ways

### Install from github

[](#install-from-github)

 To install run following command into your git bash shell

 ` $ > git clone https://github.com/thecodestuff/leggo.git `

### Install using package manager

[](#install-using-package-manager)

To install using composer run following command

` $ > require install/leggo `Architecture of leggo framework
-------------------------------

[](#architecture-of-leggo-framework)

artictech image here

Leggo uses MVC design pattern under the hood.MVC stand for model view controller. In a typical MVC framework all the logic is handle by the controller, database interaction is handled by the its respective model and all the front-end code is stored in its respective template which is fetched by its respective view.

Working of leggo
----------------

[](#working-of-leggo)

 In leggo all start with defining a web route in *vendor/app/route/web.php*. our *.htaccess* is configured in a such a way that every request from the client is route to the **index.php** file in root directory. Index file call the in which all web route are written.Framework checks weather a web route/url is valid or not. If request is not valid a error message is shown to the user else controller is evoked by the leggo. Once controller is evoked its view and model are also evoked. View check for the template mention in *$template\_name variable* in view class in *leggo/template* directory.

Directory Hierarchy of leggo
----------------------------

[](#directory-hierarchy-of-leggo)

[![](screenshots/dh.PNG)](screenshots/dh.PNG)

Defining your web route
------------------------

[](#defining-your-web-route-)

 A web is a URL which evokes a particuallar controller . To define a web route navigate to  ***/vendor/route/web.php***  file

```
Route::get('helloworld/' , 'HelloWorldController@index') ;
```

Route::get function accept to parameter .First parameter is the name of your route and the second parameter is the name of controller and the name of function.

Creating a controller for you web route
---------------------------------------

[](#creating-a-controller-for-you-web-route)

Leggo comes with its CLI tool, using this you can create controller file for your route. To create a controller file use below command.

```
$ > php console make::controller HelloWorldController
```

navigate to your */vendor/app/controllers* directory you will find that your controller created with some code already added for you to get start with .

Your typicall controller file looks like this

```

```

Here HelloWorldController class extends to base controller class. Base controller hava a function name view() which evokes the view of particullar route A typicall controller.php file look like this

```

```

Now you have created a controller for your web route , its time to create a view for your controller

Creating a view
---------------

[](#creating-a-view)

 A view contain a logic which enable user to transport the data fetch by the model from the database to the template. It work in hand with templates which are nothing more than HTML file. To create a view using CLI tool , hit below command in your console.

```
$ > php console make:view HelloWorldView
```

A view class template looks like this.

```

```

In ***$template\_name*** we can mention the template which we want to use for the particular view class. You have to create a template name ***helloWorld.blade.html*** in a */templates* directory in your root folder .

Creating a model
----------------

[](#creating-a-model)

A model is script which contains the logic to interact with the database table. A single model is associate with a single table in a database.Model uses the data abstraction layer to interact with the database. To create a model in leggo using as CLI tool, you just need to hit below command.

```
$ > php console make:model HelloWorldModel  -t helloWorldTable
```

A typical a model look like this

```

```

A HelloWorldModel inhert functionalities from the base model model.php . Here **model.php** look like :

```

```

\[2\] Database:Migrations
=========================

[](#2-databasemigrations)

2.1 What is Migrations ?
------------------------

[](#21-what-is-migrations-)

Migrations are like version control for your database, allowing your team to easily modify and share the application's database schema. Migrations are typically paired with leggo’s schema builder to easily build your application's database schema. If you have ever had to tell a teammate to manually add a column to their local database schema, you've faced the problem that database migrations solve.

2.2 Generating a migration
--------------------------

[](#22-generating-a-migration)

To create a migration, use the make:migration

```
$ > php console make:migration createTagTable
```

the new migration will be placed in your ***vendor/migrations*** directory. Each migration file name contains a timestamp which allows leggo to determine the order of the migrations. The ***--table*** options may also be used to indicate the name of the table and whether the migration will be creating a new table. These options pre-fill the generated migration stub file with the specified table.

2.3 Migration Structure
-----------------------

[](#23-migration-structure)

A migration class contains two methods: up and down. The up method is used to add new tables, columns, or indexes to your database, while the down method should reverse the operations performed by the up method. Within both of these methods you may use the leggo schema builder to expressively create and modify tables. To learn about all of the methods available on the *Schema* builder.

For example this migration creates a tag table .
***creatTagTable.php***

```
