Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can't do pagination in laravel

I need to do a pagination of the data I retrieve from the DB but I get this error:

Call to undefined method App\Models\DataFromRasp::table()

I followed the Laravel documentation but I still getting this error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

My controller is this:

class DeviceController extends Controller
{
    public function index()
    {
        $data=Device::all();
        return view('backend.auth.user.device', compact("data"));

    }

    public function create()
    {
        
    }

    public function store(Request $request)
    {
        
    }

    public function show(Device $deviceID)
    {
        $device = Device::firstWhere('id', $deviceID);
        return view('backend.auth.user.singleDevice', compact("device"));
    }

    public function edit(Device $device)
    {
        //
    }

    public function update(Request $request, Device $device)
    {
        //
    }

    public function destroy(Device $device)
    {
        //
    }

    public function visualizeData()
    {
        $data=DataFromRasp::table('data_from_rasp')->simplePaginate(10);
        return view('backend.auth.user.dictionary', compact("data"));
    }

    public function getData(Request $request)
    {   
        $m_data = $request->get('m_data');
        $r_data = $request->get('r_data');
        DataFromRasp::create(['MAC' => $m_data, 'RSSI' => $r_data]);
        if(($m_data == 'C4:A5:DF:24:05:7E' or $m_data == '70:1C:E7:E4:71:DA') and Device::where('MAC_ADDR', $request->m_data)->doesntExist()){ 
            Device::create(['MAC_ADDR' => $m_data]);
        } 
    }

    public function scan()
    {
        $process = new Process(['python2','C:\Simone\Università\Smart IoT Devices\Lab_Raspy\Bluetooth\prova.py']);
        $process->run();
        if (!$process->isSuccessful()) { throw new ProcessFailedException($process); }
        return redirect()->route('dict');
    }
}

The route is:

Route::get('dict', [DeviceController::class, 'visualizeData'])->name('dict');

Can someone help me?

>Solution :

try $data = DataFromRasp::paginate(10)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading