Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Dann's avatar
Level 1

export the view i'm seeing (from DB)

Hi

i have a view in laravel which shows data from MySQL. I also have a search field to filter the mysql results (https://github.com/kevinpijning/laravel-searchable)

everything is of course working fine, but i would like to export what i get from the DB, AFTER SEARCHING, inside a txt, csv or whatever...

the question is, how can i tell Laravel about what i searched using the module above and send that data to my export function ?

i'm quite new at this and i don't know if it's even possible (i suppose it should be but i might be dreaming)

thanks in advance Dann

0 likes
9 replies
bashy's avatar

Just pass the results into laravel-excel package (probably best) and map out the data and columns you need. I've already done this before and it works fine.

1 like
Dann's avatar
Level 1

@joelkoskela the data i'm getting back from the search module

@bashy that's the thing, the data i need is decided when i enter a search inside my view. For example i type the beginning of server names, got around 100 results for example, and i want those inside my export... how do i pass the search result data to the export i'm trying to do ?

thanks for your help (and don't forget i'm a newbie ;) )

bashy's avatar

Have you got a button to export the list? You will probably need to do the same request but with an option checked to actually run the export.

1 like
Dann's avatar
Level 1

that's the thing, i'm not doing anything for the search, i'm calling a module like this in my controller :

$alls = Ansible::searchable()->sortable()->paginate(2000);

and in the view i'm calling this blade extension like specified in the module doc (https://github.com/kevinpijning/laravel-searchable) :

@searchableform

so i don't know what's going on behind the scene...

is it possible the way i'm doing it or using this module is making my life harder ? i might also not know about something very simple because i wrote this laravel site with no experience, following examples... so don't assume i know all the basics ^^

bashy's avatar

Oh right, I just thought you were using it to pass search params via GET or something :P I don't know about that then.

1 like
Dann's avatar
Level 1

actually the search url after i type something is in the form http://website/ansible?search=asic

so maybe i could use this in an export function to pass it directly to my module inside the controller ?

so how do get params from GET url in a controller ? :)

thanks

bashy's avatar
bashy
Best Answer
Level 65

Yeah maybe. I'm not to familiar with how it works but you can get the GET/POST data via request('search')

1 like
Dann's avatar
Level 1

thanks i managed to do it using Requests (i knew the name but didn't understood the concept, now i do ;)) and passing it to a controller function.

Please or to participate in this conversation.