class Order extends Eloquent {}
Order::all();
$orders = Order::orderBy('release_date', 'desc')->get();
$order = new Order;
$order->title = 'Xbox One';
$order->save();
Route::get('orders', function()
{
return View::make('orders.index')
->with('orders', Order::all());
});
Route::get('orders', 'OrdersController@index');
class Task extends Eloquent {
public function user()
{
return $this->belongsTo('User');
}
}
class User extends Eloquent {
public function tasks()
{
return $this->hasMany('Task');
}
}
$user = User::find(1);
$tasks = $user->tasks;
$task = Task::find(1);
$user = $task->user;
{{ Form::model($order) }}
<div>
{{ Form::label('title', 'Title:') }}
{{ Form::text('title') }}
</div>
<div>
{{ Form::label('description', 'Description:') }}
{{ Form::textarea('description') }}
</div>
{{ Form::close() }}
$questions = Question::remember(60)->get();
View::composer('layouts.nav', function($view)
{
$view->with('tags', ['tag1', 'tag2']);
});
$user = [
'email' => 'email',
'password' => 'password'
];
if (Auth::attempt($user))
{
//
}
Route::get('logout', function()
{
Auth::logout();
return Redirect::home();
});
Route::resource('orders', 'OrdersController');
php artisan controller:make OrdersController
@if ($orders->count())
<ul>
@foreach($orders as $order)
<li>{{ $order->title }}</li>
@endforeach
</ul>
@endif
public function test_home_page()
{
$this->call('GET', '/');
$this->assertResponseOk();
}
public function test_contact_page_redirects_user_to_home_page()
{
$postData = [
'name' => 'Joe Example',
'email' => 'email-address',
'message' => 'I love your website'
];
$this->call('POST', '/contact', $postData);
$this->assertRedirectedToRoute('home', null, ['flash_message']);
}
SSH::into('production')->run([
'cd /var/www',
'git pull origin master'
]);
php artisan command:make DeployCommand
fire() .Event::listen('user.signUp', function()
{
// , ,
//
});
Event::listen('user.signUp', 'UserEventHandler');
php artisan routes
Queue::push('SignUpService', compact('user'));
$order = [
'title' => 'Wii U',
'description' => 'Game console from Nintendo'
];
$rules = [
'title' => 'required',
'description' => 'required'
];
$validator = Validator::make($order, $rules);
if ($validator->fails())
{
var_dump($validator->messages()); // validation errors array
}
$ php artisan tinker
> $order = Order::find(1);
> var_dump($order->toArray());
> array(...)
php artisan migrate:make create_users_table
public function up()
{
Schema::create('faqs', function(Blueprint $table) {
$table->integer('id', true);
$table->text('question');
$table->text('answer');
$table->timestamps();
});
}
public function down()
{
Schema::drop('faqs');
}
php artisan generate:migration create_users_table --fields="username:string, password:string"
php artisan command:make MyCustomCommand
protected $name = 'command:name';
protected $description = 'Command description.';
Artisan::add(new MyCustomCommand);
Validator::shouldReceive('make')->once();
{{ Form::open() }}
{{ Form::text('name') }}
{{ Form::textarea('bio') }}
{{ Form::selectYear('dob', date('Y') - 80, date('Y')) }}
{{ Form::close() }}
public function __construct(MyDependency $thing)
{
$this->thing = $thing;
}
$myClass = App::make('MyClass');
$env = $app->detectEnvironment(array(
'local' => array('your-machine-name'),
));
$env = $app->detectEnvironment(function()
{
return getenv('ENV_NAME') ?: 'local';
});
<?php // app/config/development/billing.php
return [
'api_key' => 'your-development-mode-api-key'
];
Config::get(‘billing.api_key’)
Laravel , .Source: https://habr.com/ru/post/222453/
All Articles