Laravel 5.2背包从url获取参数

时间:2016-10-03 06:41:56

标签: php laravel-5.2 backpack-for-laravel

我遇到了一个不知道如何从网址获取价值的问题。我是背包里的新手。请帮帮我......

我希望我的视图基于从另一个视图传递的id的视图,如何实现这个?这是我的代码

Adcontroller.php

 public $crud = array(
            "model" => "App\Larapen\Models\Ad",
            "entity_name" => "ad",
            "entity_name_plural" => "ads",
            "route" => "admin/ad",
            "reorder" => false,
            "add_permission" => false,
    "columns" => [
                [
                    'name' => 'reviewed',
                    'label' => "Reviewed",
                    'type' => "model_function",
                    'function_name' => 'getReviewedHtml',
                ],
             ],
    "fields" =>[
                    [   // Hidden
                            'name' => 'id',
                            'label' => "id",
                            'type' => 'hidden'
                        ],
            ],

        );

Ad.php(模型)

 public function getReviewedHtml()
    {
        if ($this->reviewed == 1) {
             return '<i class="fa fa-check-square-o" aria-hidden="true"></i><a href="reviews/'.$this->id.'"><span> Reviews</span></a>';
        } else {
            return '<i class="fa fa-square-o" aria-hidden="true"></i>';
        }
    }

route.php

CRUD::resource('ad', 'AdController');
   CRUD::resource('reviews', 'AdReviewController');

AdReviewController.php

public $crud = array(
        "model" => "App\Larapen\Models\AdReviews",
        "entity_name" => "Reviews",
        "entity_name_plural" => "Reviews",
        "route" => "admin/reviews",
        "reorder" => false,
        "add_permission" => false,

        // *****
        // COLUMNS
        // *****
        "columns" => [
            [
                'name' => 'created_at',
                'label' => "Date",
            ],
            [
                'name' => 'user',
                'label' => "User",
                'type' => "model_function",
                'function_name' => 'getuser',
            ],
            [
                'name' => 'review',
                'label' => "Review",
            ],

        ],
  "fields" => [

             [
                'name' => 'review',
                'label' => "Review",
            ],


        ],
    );
public function __construct()
    {
        //$this->crud['update_fields'][1]['options'] = $this->adType();
       // $this->crud['update_fields'][2]['options'] = $this->categories();

        parent::__construct();
    }
     public function store(StoreRequest $request)
    {
        return parent::storeCrud();
    }

    public function update(UpdateRequest $request)
    {
        return parent::updateCrud();
    }

}

&#34;我想显示基于每个广告的评论,现在它显示评论表中的所有评论,我应该在哪里写条件???&#34; 等待回应...............

1 个答案:

答案 0 :(得分:0)

我认为您在评论模型和AdReview模型中定义的AdReview和评论之间存在one-to-oneone-to-many关系。

如果是,您可以添加:

这将显示它与之“连接”的实体并允许用户编辑它。

这是你想要达到的目标吗?