how to write html in ajax

0

Hello, I have this code for a table with user data. I want to write the options to edit and delete in ajax, but I do not know how they are written, if someone could tell me how it would be helpful

PS: I know it is poorly written, so I want you to help me.

class SearchController extends Controller
{

    public function search(Request $request)
    {
        if ($request->ajax())
        {
            $output="";
            $personas = DB::table('personas')
                                             ->join('users', 'users.username', '=', 'personas.username' )
                                             ->join('institucions', 'institucions.rut_institucion', '=', 'users.rut_institucion')
                                             ->select('personas.rut_persona', 'personas.nombre_persona', 'personas.direccion', 'personas.telefono', 'personas.email', 'personas.username', 'users.tipo_usuario', 'institucions.nombre_institucion')
                                             ->where('personas.username', 'LIKE', '%'.$request->search.'%')
                                             ->orWhere('personas.nombre_persona', 'LIKE', '%'.$request->search.'%')
                                             ->get();
            if ($personas)
            {
                foreach ($personas as $key => $persona) {
                    if($persona->tipo_usuario == 0){
                        $tipo_usuario = "Administrador";
                    }elseif($persona->tipo_usuario == 1){
                        $tipo_usuario = "Director";
                    }elseif($persona->tipo_usuario == 2){
                        $tipo_usuario = "Secretaria";
                    }elseif($persona->tipo_usuario == 3){
                        $tipo_usuario = "Encargado de Computación";
                    }elseif($persona->tipo_usuario == 4){
                        $tipo_usuario = "Informática";
                    }
                    elseif($persona->tipo_usuario == 5){
                        $tipo_usuario = "Infraestructura";
                    }
                    $output.='<tr>'.
                                '<td>'.$persona->rut_persona.'</td>'.
                                '<td>'.$persona->nombre_persona.'</td>'.
                                '<td>'.$persona->direccion.'</td>'.
                                '<td>'.$persona->telefono.'</td>'.
                                '<td>'.$persona->email.'</td>'.
                                '<td>'.$persona->username.'</td>'.
                                '<td>'.$tipo_usuario.'</td>'.
                                '<td>'.$persona->nombre_institucion.'</td>'.

                                '<td>' 
                                '<a class="btn btn-primary" href="{{ route('users.edit', $persona->username) }}">'.Editar.'</a>'
                                '</td>'

                                if ($persona->tipo_usuario != 0)
                                {
                                    '<td>' 
                                        '<form method="POST" action="{{ route('users.destroy', $persona->username) }}">'

                                        '<input type="submit" value="Eliminar" class="btn btn-danger">'

                                        {{ method_field('DELETE') }}
                                        {{ csrf_field() }}
                                        '</form>'

                                    '</td>'
                                }

                             '</tr>';




                }

                    return Response($output);   
            }
        }
    }
}

I want to write this that I had in html and php in ajax this:

<td> 
<a class="btn btn-primary" href="{{ route('users.edit', $persona->username) }}">Editar</a>
                            </td>
                            @if ($persona->tipo_usuario != 0)
                            <td> 
                                 <form method="POST" action="{{ route('users.destroy', $persona->username) }}">

                                    <input type="submit" value="Eliminar" class="btn btn-danger">

                                    {{ method_field('DELETE') }}
                                    {{ csrf_field() }}
                                 </form>

                            </td>
                            @endif
    
asked by pinisco 12.02.2018 в 16:49
source

0 answers