I am working on a Laravel project that does custom SQL commands from input. I have the following functions.
Route
Route::patch('/form-submit', function(Request $request){
$query = $request->input('query');
return view('welcome', compact('query'));
});
Welcome.blade.php
<form method="POST" enctype="multipart/form-data" action="/form-submit" class="text-end">
{{ method_field('PATCH') }}
@csrf
<input name="query" value="{{ $query }}" id="input" class="form-control w-20">
<button type="submit" id="button" class="btn btn-sm btn-info mt-3">Submit</button>
</form>
<?php
$querys = DB::select($query);
?>
Now I want to loop through all the values that the SQL command gives me. For example, for the input "SELECT * from users" I will get all the users and I can show their name using:
@foreach($querys as $data)
{{$data->name}}
@endforeach
But I would like to show all the data for the user, including name, sex, id, age, etc. I tried multiple options but I didn't find yet a solution. The query will always be different so I will not know what data do I have to show. For example, if I type "SELECT * from notifications" I want to add all the informations from the database in a table.
Can anyone help me?
Thank you
question from:https://stackoverflow.com/questions/65943379/laravel-dbselectquery