机场表:
Schema::create('airports', function(Blueprint $table)
{
$table->increments('id');
$table->string('code');
$table->string('name');
$table->string('city');
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
航班表:
Schema::create('flights', function(Blueprint $table)
{
$table->increments('id');
$table->integer('number');
$table->integer('origin')->unsigned();
$table->foreign('origin')->references('id')->on('airports');
$table->integer('destination')->unsigned();
$table->foreign('destination')->references('id')->on('airports');
$table->integer('price');
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
飞行模型:
<?php
class Flight extends \Eloquent {
protected $fillable = ['number', 'origin', 'destination'];
public function origin(){
return $this->belongsTo('Airport');
}
public function destination(){
return $this->belongsTo('Airport');
}
}
Run Code Online (Sandbox Code Playgroud)
飞行控制器@索引:
public function index()
{
$flights = Flight::with('origin')->with('destination')->get();
return Response::json($flights, 200);
}
Run Code Online (Sandbox Code Playgroud)
部分回复:
[
{
"id": "1",
"number": "112",
"origin": null,
"destination": null,
"price": "232",
"created_at": "2014-12-28 11:49:44",
"updated_at": …Run Code Online (Sandbox Code Playgroud) 我正在尝试在Laravel 5中构建一个新的自定义命令,如下所示:
php artisan make:console Tenant --command=tenant:do
Run Code Online (Sandbox Code Playgroud)
它在App\Console\Commands中创建了类,如下所示:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class Tenant extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'tenant:do';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Run commands for all tenants.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command. …Run Code Online (Sandbox Code Playgroud) 所以我有一个BaseValuation抽象类及其实现示例FooValuation和BarValuation.
我想根据使用输入来实例化Foo或实现。Bar所以我自己创建了一个简单的类,Valuation它的作用是:
<?php
namespace App\Valuation;
class Valuation
{
public $class;
public function __construct($id, $type = 'basic')
{
$class = 'App\Valuation\Models\\' . ucfirst($type) . 'Valuation';
$this->class = new $class($id);
}
public function make()
{
return $this->class;
}
}
Run Code Online (Sandbox Code Playgroud)
使用这个我可以简单地做到这一点(new App\Valuation\Valuation($id, $type))->make(),我将根据用户的要求获得所需的实现。
但我知道 laravel 的容器很强大,必须允许我以某种方式做到这一点,但我不明白这是如何完成的。有人有什么想法吗?
我正在尝试学习和使用新的实用程序框架,这些实用程序框架最近变得越来越流行。尾风CSS
当我按照文档中的说明编译CSS时,我看到很多CSS类名中都带有冒号:,并且前面加反斜杠\
这是为什么?这是为了使CSS理解那里:存在而不是逃避它吗?