简体   繁体   中英

Laravel 5.2 backpack get the parameter from url

I am stuck with a problem that don't know how to get the value from url. I am new in backpack. please help me with this.....

I want my details on a view based on the id that is passed from another view, how to implement this?? this is my code

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(model)

 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();
    }

}

"I want to display the reviews based on each Ads now it display all the reviews from the review table, where should i write the condition???" Waiting for a response...............

I presume you have one-to-one or one-to-many relationships between AdReview and Review, defined both in your Review model and your AdReview model.

If so, you can add:

That will show the entity it's "connected" with and allow the user to edit it.

Is this what you were trying to achieve?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM