Mittwoch, 20. August 2014

Laravel Notes

Details here:


1- Install Composer for Windows

2 - Install Laravel in your project folder

composer create-project laravel/laravel --prefer-dist

laravel is the target folder name

3 - Work with the laravel files

4 - Add in .htaccess after  RewriteEngine On, following line:
     RewriteBase /laravel/public

5 - Contet of routes.php will be appear on the public page

6 - Access the public page like this:
http://127.0.0.1/laravel/public

7 - If you have a line like this in routes.php:
Route::resource('tasks', 'TasksController');
Access to the folder tasks like this:
http://127.0.0.1/laravel/public/tasks

8 - For Database settings see the database.php

9 - Some commands for creating tables in MySQL

php artisan migrate:make create_tasks_table --table tasks --create  (tasks is the table name)

10 - then change the content of file like this: 2014-08-20-...-table.php like this:

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTasksTable extends Migration {

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('tasks', function($table)
{
$table->increments('id');
$table->string('title');
$table->boolean('completed')->default(0);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('tasks', function(Blueprint $table)
{
//
});
}

}

11 - Run folloing command to create table elements in database:
php artisan migrate

12 - For seeding the table, put in the DatabaseSeeder.php like this:

<?php

class DatabaseSeeder extends Seeder {

/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Eloquent::unguard();

$this->call('UserTableSeeder');
}

}
class UserTableSeeder extends Seeder {

    public function run()
    {
        DB::table('tasks')->delete();
        DB::table('tasks')->insert(array(
                'id' => 1,
                'title' => 'Go to the store',
        ));
        DB::table('tasks')->insert(array(
                'id' => 2,
                'title' => 'Finish Backbone cource',
        ));
        DB::table('tasks')->insert(array(
                'id' => 3,
                'title' => 'Get some sleep.',
          ));
    }
}

13 - After that run the following command:
php artisan db:seed

14 - For fetching data from database we need kind of Controller:
php artisan controller:make TsksController and function index like this:

public function index()
{
return Task::all();
}

15 - For autoloading of changes:
composer dump-autoload



















Keine Kommentare:

Kommentar veröffentlichen