小编Roh*_*han的帖子

Laravel 急切加载不起作用?

机场表:

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)

eager-loading laravel eloquent laravel-4

0
推荐指数
1
解决办法
5260
查看次数

在laravel 5中没有注册命令?

我正在尝试在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)

php laravel laravel-5

0
推荐指数
1
解决办法
1747
查看次数

Laravel 中如何根据类型实例化类?

所以我有一个BaseValuation抽象类及其实现示例FooValuationBarValuation.

我想根据使用输入来实例化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 的容器很强大,必须允许我以某种方式做到这一点,但我不明白这是如何完成的。有人有什么想法吗?

php laravel laravel-5 laravel-ioc

0
推荐指数
1
解决办法
2164
查看次数

为什么顺风CSS类名称中会有反斜杠?

我正在尝试学习和使用新的实用程序框架,这些实用程序框架最近变得越来越流行。尾风CSS

当我按照文档中的说明编译CSS时,我看到很多CSS类名中都带有冒号:,并且前面加反斜杠\

这是为什么?这是为了使CSS理解那里:存在而不是逃避它吗?

css tailwind-css

0
推荐指数
1
解决办法
278
查看次数