0

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...............

Pooja Krishna
  • 193
  • 1
  • 5
  • 26

1 Answers1

0

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?

tabacitu
  • 6,047
  • 1
  • 23
  • 37
  • i just want reviews based on each Ads, – Pooja Krishna Oct 03 '16 at 11:14
  • I don't need a select column , i need to list my database review details on a view which is based on the Ads id.. that Ads id has to be passed from another view which can be accessed in my review controller. For this what should i do ?? – Pooja Krishna Oct 03 '16 at 12:06
  • I'm sorry, I'm afraid I still don't understand. Could you please rephrase your question and/or include an example? In principle, passing a variable from view_1 to view_2 is only possible if the view_2 @includes view_1. Passing a variable from a view to a controller is impossible and does not follow MVC principles. – tabacitu Oct 04 '16 at 05:51
  • I actually need the concept as same as edit code, where depending upon the id the contents are beinging updated. – Pooja Krishna Oct 04 '16 at 06:37
  • I'm sorry, I'm afraid I don't understand you, so I can't help you. I'll ask someone else to review your question, maybe they will. Cheers! – tabacitu Oct 04 '16 at 07:01