app/Http/Controllers/ClienteController.php
/**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
Display a listing of the resource.
@return \Illuminate\Http\Response
Display a listing of the resource . @return \ Illuminate \ Http \ Response
public function index()
    {
      $clientes = Cliente::with(['usuario' => function ($query){
     $query->addselect('*');
     $query->addselect(DB::raw('CONCAT(nombre," ",apellido) as full_name'));
   }])->where('estado', 1)->get();
      return Datatables::of($clientes)
      ->addColumn('action', function($cliente) {
        $editar_cliente=(Auth::user()->can('editar_clientes'))?'<a href="editar/'.$cliente->id.'" class="btn btn-primary btn-xs btn-flat btn-block usuario_edit">Editar</a>':'';
        $borrar_cliente=(Auth::user()->can('borrar_clientes'))?'<button type="button" id="cli-'.$cliente->id.'" class="btn btn-danger btn-xs btn-flat btn-block delete_cliente" data-toggle="modal" data-target="#myModal">Borrar</button>':'';
        return $editar_cliente.$borrar_cliente;
      })
      ->addColumn('ejecutivo', function($cliente) {
        return ($cliente->usuario != null)?$cliente->usuario->full_name:'No definido';
      })
      ->make(true);
    }
public function index ( ) { $ clientes = Cliente :: with ( [ 'usuario' => function ( $ query ) { $ query -> addselect ( '*' ) ; $ query -> addselect ( DB :: raw ( 'CONCAT(nombre," ",apellido) as full_name' ) ) ; } ] ) -> where ( 'estado' , 1 ) -> get ( ) ; return Datatables :: of ( $ clientes ) -> addColumn ( 'action' , function ( $ cliente ) { $ editar_cliente = ( Auth :: user ( ) -> can ( 'editar_clientes' ) ) ? '<a href="editar/' . $ cliente -> id . '" class="btn btn-primary btn-xs btn-flat btn-block usuario_edit">Editar</a>' : '' ; $ borrar_cliente = ( Auth :: user ( ) -> can ( 'borrar_clientes' ) ) ? '<button type="button" id="cli-' . $ cliente -> id . '" class="btn btn-danger btn-xs btn-flat btn-block delete_cliente" data-toggle="modal" data-target="#myModal">Borrar</button>' : '' ; return $ editar_cliente . $ borrar_cliente ; } ) -> addColumn ( 'ejecutivo' , function ( $ cliente ) { return ( $ cliente -> usuario != null ) ? $ cliente -> usuario -> full_name : 'No definido' ; } ) -> make ( true ) ; }
Display a listing of the resource.
Display a listing of the resource .
// $clientes = Cliente::all(); // return response()->json($clientes);