0

In laravel 5.1 it is giving en error UNDEFINED INDEX::cost_group

I want to show courses table's column name by drop down in another payments view page and store it into another table(payments) when one of them is selected

My PaymentsController.php:

public function index(Request $request) {
        $filter = $request->input();
        $sort = $request->query();
        $payments = Payment::filter($filter)->sort($sort)->paginate(10);

        foreach(Course::all() as $course) {
            $data['courses'][$course->id] = $course->name;
            $data['courses'][$course->cost_group]=$course->course_cost;
            $data['courses'][$course->cost_minigroup]=$course->course_name;
            $data['courses'][$course->cost_individual]=$course->course_name;

        }

        return view('payments.index', compact('payments', 'data'));
    }

My form.blade.php (of payments)

<div class="ui form">
             <div class="field">
                 <div class="ui selection dropdown">
                     <input type="hidden" name="amount" id="course_val" />
                     <i class="dropdown icon"></i>
                     <div class="default text">Course type</div>
                     <div class="menu">
                         <div class="item course_val" data-value="{{$data['cost_group']}}">Group</div>
                         <div class="item course_val" data-value="{{$data['cost_minigroup']}}">Minigroup</div>
                         <div class="item course_val" data-value="{{$data['cost_individual']}}">Individual</div>
                     </div>
                 </div>
             </div>
         </div>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Armani
  • 49
  • 8
  • `var_dump($data)` I bet it's not holding what you think it's holding. – aynber Apr 26 '17 at 13:01
  • @aynber what you mean?? – Armani Apr 26 '17 at 13:09
  • Meaning that your indexes are not named 'cost_group', 'cost_minigroup', and 'cost_individual'. The indexes are whatever the value of `$course->cost_group`, `$course->cost_minigroup`, and `$course->cost_individual`. When you var_dump your variable, you can see the indexes and values. – aynber Apr 26 '17 at 13:10
  • @aynber yeah. But how you get the table columns in drop down and store in another table if your table like this courses{ id, name, cost_group, cost_minigroup, cost_individual}' these are all columns. – Armani Apr 26 '17 at 13:15
  • I'm not exactly sure what you mean, but if you want to use static index names, then specify them yourself instead of using the database values as indexes. – aynber Apr 26 '17 at 13:19
  • @aynber it is not duplicate of any other question.Cause I looked through the question did not find any answer. You guys marked it as duplicate for your reputation. – Armani Apr 26 '17 at 13:25
  • @RiggsFolly it is not duplicate of any other question.Cause I looked through the question did not find any answer. You guys marked it as duplicate for your reputation. – Armani Apr 26 '17 at 13:26
  • So please unmark it if possible so other experts could see it and help?! – Armani Apr 26 '17 at 13:27
  • Voting to close does not affect our reputation, and it is just like every other undefined index question out there. The data variable does not contain the indexes you think it does. Dump the variable, *look* at the structure, then decide if you need to access the data another way, or build up the data another way. – aynber Apr 26 '17 at 13:27
  • Ok i will try thank you. – Armani Apr 26 '17 at 13:29

0 Answers0