problem with query where select

Published 4 days ago by daniel21gt

I have tried to do a where query with a select options

Code with error

https://paste.laravel.io/de1569e9-6fe5-477c-b6fc-eac5fb3d59d9

"Trying to get property of non-object (View: C:\laragon\www\crudgobernaciontres\resources\views\Usuario\index.blade.php)"

In this module I consult all the records, but I also want to select by username, I still do not get it.

view https://paste.laravel.io/505fad0a-3fb6-49d4-9465-1751e9de6136 controller https://paste.laravel.io/dfdbb2b5-8c9f-46b2-b9bc-38b5dc2a7cbe

Is it possible to do this in the same module?

bobbybouwmann

This seems to be invalid

<form action="{{route('usuario.show', $id->$usuario_ad)}}" method="POST">

Note the $id->$usuario_ad. I think you need one of the parameters here instead of both!

Snapey
Snapey
4 days ago (1,037,395 XP)

Not sure what you are trying to do but your loop will not produce valid html

daniel21gt

I just want to filter a list with a where, so

select * from users where userad = danielad;

In my view I select an option

https://paste.laravel.io/1ccc28a5-232e-46b2-adda-7090f34208e2

then this selection sent it to my controller

https://paste.laravel.io/287f2e0e-356a-4e64-bd1d-c219a4753387

I just want to see the table with the data referring to "danielad"

bobbybouwmann
bobbybouwmann
1 day ago (1,179,925 XP)

Your form fields always need to be inside the <form> and </form> tags. Otherwise your browser doesn't understand how to post it. After that you should be able to get it from the request.

Note that you can't post to a get route. In this case the show route is already a get route and you can't combine the two. Instead you can use a query parameter in your url to do the filter

<form method="GET" action="{{ route('usuario.show', $id) }}">

    // Your select here
    // Your submit button here

</form>

// In your controller you can access the filter like so
public function show(Request $request, $id)
{
    $filter = $request->get('tipo');

    // your query with above filter

    // The response here
}

Please sign in or create an account to participate in this conversation.