Skip to content

Instantly share code, notes, and snippets.

@syads321
Last active December 9, 2016 07:43
Show Gist options
  • Save syads321/8b18045007bce40196645df18fd94f0b to your computer and use it in GitHub Desktop.
Save syads321/8b18045007bce40196645df18fd94f0b to your computer and use it in GitHub Desktop.
Laravel command list
php artisan make:controller BookController
php artisan make:model --migration Post
//Make migration template and model named Post at same time
Route::get($uri, $callback);
Route::post($uri, $callback);
//Scope Model
class User extends Model {
public function scopePopular($query)
{
return $query->where('votes', '>', 100);
}
public function scopeWomen($query)
{
return $query->whereGender('W');
}
}
$users = User::popular()->women()->orderBy('created_at')->get();
One to Many
class User extends Model {
public function phone()
{
return $this->hasOne('App\Phone');
}
}
$phone = User::find(1)->phone;
select * from users where id = 1
select * from phones where user_id = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment