{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.1.*",
"way/generators": "dev-master",
"twitter/bootstrap": "*",
"itsgoingd/clockwork": "1.*"
},
"require-dev": {
"mockery/mockery": "dev-master"
},
key:generate Generate a secure application key.
# Seeding of the DB
db:seed
#Create a new resourceful controller
controller:make
# Migrations
migrate:install Create the Laravel migration table.
migrate:make Create a migration.
migrate Run outstanding migrations.
migrate:rollback Roll back the most recent migration.
migrate:reset Roll back all migrations.
generate:controller Generate a new controller.
generate:form Dump form HTML for a model
generate:migration Generate a new migration.
generate:model Generate a new model.
generate:pivot Generate a pivot table
generate:resource Generate a resource.
generate:scaffold Generate scaffolding for a resource.
generate:seed Generate a seed file.
generate:test Generate a PHPUnit test class.
generate:view Generate a new view.
php artisan list
Schema::create('posts', function($table)
{
$table->increments('id');
$table->string('title');
$table->string('tagline', 64); // constraint as second argument
$table->text('body');
$table->integer('category_id')
->unsigned() // chain methods for other options
->nullable(); // for optional fields
$table->softDeletes();
$table->timestamps();
});
works with MySQL, PostgreSQL, SQLite, SQL Server
class Company extends Eloquent {}
$company = Company::create(array(
'address' => '155 Harbor Blvd',
'city' => 'Fullerton'
));
$company = Company::find(1);
echo $company->address; // 155 Harbor Blvd
$company = Company::where('city', "Fullerton")->first();
$companies = Company::orderBy('city', 'desc')->take(10)->get();
Pagination built in! Example:
$companies = Company::orderBy('city', 'desc')->paginate(10);
function comments()
{
return $this->hasMany('Comment');
}
class Company extends Eloquent {
public function salesperson()
{
return $this->hasOne('Salesperson');
}
}
$salesperson = Company::find(1)->salesperson->name;
class Company extends Eloquent {
public function customers()
{
return $this->hasMany('Customer');
}
}
$customers = Company::find(1)->customers;
function friends()
{
return $this->belongsToMany('User');
}
<a href="<?php echo $post->link; ?>">
<?php echo $post->title; ?>
</a>
<a href="{{ $post->link }}">
{{ $post->title }}
</a>
@if( $a > 3 )
{{ $a }} @endif
@foreach ($users as $user) <p>This is user {{ $user->id }}</p> @endforeach
@section('content')
<p>This is my body content.</p>
@stop
@yield('content')
Form::open(); Form::text('username'); Form::password('password'); Form::checkbox('name', 'value', true); Form::file('image'); Form::select('size', array('L' => 'Large', 'S' => 'Small')); Form::submit('Click Me!'); Form::close();
Route::get('/posts/{post}', function($post)
{
return "Post title: $post!";
});
Route::get('user/{id}/{name}', function($id, $name)
{
//
})
->where(array('id' => '[0-9]+', 'name' => '[a-z]+'))
Route::get('home', ['as' => 'home', 'uses' => 'SiteController@index']);
Route::controller('/', 'SiteController');
/* In SiteController.php */
public function getIndex() { return ''; }
public function postIndex() { return ''; }
Route::resource('post', 'PostController');
Route::get('create', array('before' => 'auth|csrf', function()
{
//
}));
Route::group(['prefix' => 'post'], function() {
Route::get('{post-slug}', function($post) { return 'the post'; });
Route::get('{post-slug}/edit', function($post) { return 'edit post'; });
Route::post('{post-slug}/edit', function($post) {
// Validate
// Save
return Redirect::route('blog.post');
});
});
Route::get('posts', ['as' => 'posts.list', function()
{
return 'list of posts';
}]);
Redirect::route('posts.list);
URL::route('posts.list');
URL::route('posts.show', ['post-slug' => $post->slug]);
$credentials = array(
'username' => 'example@gmail.com',
'password' => 'secret'
);
if (Auth::attempt($credentials))
{
return Redirect::to('user/profile');
}
Get user's info :
$email = Auth::user()->email;
Logout:
Auth::logout();
$name = Input::get('name', 'Sally');
$input = Input::only('username', 'password'); $input = Input::except('credit_card');
$input = Input::get('products.0.name');
Session::put('key', 'value'); Session::flash('key', 'value'); $value = Session::get('key'); Session::forget('key'); Session::flush();
$value = Cookie::get('name');
$cookie = Cookie::forever('name', 'value');
$input = Input::all();
$rules = array(
'name' => 'required|min:3|max:32|alpha',
'age' => 'required|integer',
'image'=> 'image|max:1500',
'password' => 'confirmed'
);
$v = Validator::make($input, $rules);
if( $v->fails() ){
// code for validation failure :(
}else{
// code for validation success!
}
+ 14 more types(including RegEx)
$env = $app->detectEnvironment(array(
'local' => array('http://localhost*', '*.dev'),
'test' => array('http://test.mywebsite.com*'),
'production' => array('http://mywebsite.com*'),
));
app
- config
- test
- database.php
- session.php
- production
- database.php
...
$response = $this->call('GET', 'user/profile');
$this->assertCount(1, $crawler->filter('h1:contains("Hello World!")'));
http://laravel.comhttp://github.com/laravel/laravelhttp://docs.laravel.com http://forums.laravel.comhttp://builtwithlaravel.com - list of sites using Laravelhttp://laravel-tricks.com - tips and tricks for Laravel users