0

My Controller Code

$StudentData =  StudentModel::getStudentList();
        //dd($StudentData);
        foreach ($StudentData as $data)
        {
             print_r(array($data->Student_name));
             
        }

when i Use dd() commend and I get index values like

Illuminate\Database\Eloquent\Collection {#588 ▼
  #items: array:2 [▼
    0 => App\Models\Student {#585 ▼
      #attributes: array:4 [▶]
      #original: array:4 [▼
          "StudentId" => 2
        "Student_register_number" => 11
        "Student_name" => "Tom"
        "Student_make_percentage" => "69.00"
      ]
      #guarded: array:1 [▶]
    }
    1 => App\Models\Student {#575 ▼
      #attributes: array:4 [▶]
      #original: array:4 [▼
        "StudentId" => 2
        "Student_register_number" => 11
        "Student_name" => "John"
        "Student_make_percentage" => "65.00"
      ]

when i Use print_r(array($data->Student_name)); and run the out put i get Like This

Array
(
    [0] => Tom
)
Array
(
    [0] =>John
)

what actually result i want is

array (2)=>
[
   '0'=>Tom,
   '1'=>'john',
]

how i want to get All Student_name alone from index .and store that as index value as above

Rahul
  • 25
  • 6
  • Does this answer your question? [php implode (101) with quotes](https://stackoverflow.com/questions/6102398/php-implode-101-with-quotes) – gguney Mar 04 '22 at 08:25
  • 1
    Hard to understand the question. But try this: `collect(Student::all())->pluck('Student_name')->values()->all()` – Molod Mar 04 '22 at 08:28
  • @Molod I update and edited the above code hope you understand >.else I change or explain the code to you. Actually I want All Index values .But for **Student name** alone in want to display in blade file as Tom,John .So i want to get Student name separately from above index and store as array .get The array value of (student_name like array(2)=> '0'=>Tom '1'=>'John') implode and send This to blade file that will display like Tom,John – Rahul Mar 04 '22 at 09:13
  • try @Tipu Sultan Eiko answer - it should work – Molod Mar 04 '22 at 09:18

1 Answers1

1

Try this...

 return StudentModel::getStudentList()->pluck('Student_name')->toArray();
Tipu Sultan Eiko
  • 677
  • 4
  • 10