Laravel otrzymuje dane z modelu do kontrolera

// web.php
route::get('/data', '\App\Http\Controllers\Data@get_data');

//controller
<?php

namespace App\Http\Controllers;

use App\Models\Data_model;
use Illuminate\Http\Request;

class Data extends Controller {

    function __construct() {
        $this->data_model = new Data_model(); // access to model
    }
    function get_data() {
        $users = $this->data_model->send_data();
        foreach ($users as $user) {
            echo '<pre>';
            print_r($user);
            echo '</pre>';
            die();
        }
    }
}
?>
  
// model
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB; // add DB functions

class Data_model extends Model
{
    use HasFactory;

    function send_data(){
        $users = DB::table('table_name')->get();

        return $users;
    }
}
Ivan Cuaco