curl -sS https://getcomposer.org/installer | php2. Create laravel project
mv composer.phar /usr/local/bin/composer
composer create-project laravel/laravel your-project-name --prefer-distApache config
DocumentRoot your-project-location/public3. Route setting
vi app/routes.php
Route::get('users', function()
{
return 'Users!';
});
4. Testhttp://your-address/index.php/users [ OK ]5. If not OK, set apache config
http://your-address/users [ Should be OK ]
<VirtualHost *:80>6. Create view
ServerName your-address
DocumentRoot your-project-location/public
<Directory "your-project-location/public">
Require all granted
AllowOverride all // to allow .htaccess
</Directory>
</VirtualHost>
cd app/views7. Set routes
vi layout.blade.php
<html>
<body>
<h1>Laravel Quickstart</h1>
@yield('content')
</body>
</html>
vi users.blade.php
@extends('layout')
@section('content')
Users!
@stop
vi app/routes.php8. Set database
Route::get('users', function()
{
return View::make('users');
});
vi app/config/database.php9. Set to make user ORM
php artisan migrate:make create_users_table
cd app/database/migrations10. Migrate
vi *_create_users_table.php
public function up()
{
Schema::create('users', function($table)
{
$table->increments('id');
$table->string('email')->unique();
$table->string('name');
$table->timestamps();
});
}
public function down()
{
Schema::drop('users');
}
php artisan migrateCheck
vi app/models/User.php
class User extends Eloquent {}
11. Set routes
Route::get('users', function()
{
$users = User::all();
return View::make('users')->with('users', $users);
});
12. Set viewvi users.blade.php
@extends('layout')
@section('content')
@foreach($users as $user)
<p>{{ $user->name }}</p>
@endforeach
@stop
No comments:
Post a Comment