php - How to only select 2 column from the database with laravel 5.1? -


i trying use laravel 5.1 select records mysql database , break results pages.

here method use return database results listall view. (this code display white screen "no errors, no results")

public function getindex(){      $accounts = db::table('accounts')                     ->lists('account_id','account_name')                     ->where('client_id', '=', 7)                     ->paginate(100);      $name = 'mike a';      return view('accounts.listall', compact('accounts', 'name'));  } 

when using code below, works returns column. want display 2 columns.

public function getindex(){      $accounts = db::table('accounts')                     ->where('client_id', '=', 7)                     ->paginate(100);      $name = 'mike a';      return view('accounts.listall', compact('accounts', 'name'));  } 

edited

this code after kyle suggestion "below"

namespace app\http\controllers;  use illuminate\http\request;  use app\http\requests; use app\http\controllers\controller; use db; use app\accounts;  class accountscontroller extends controller {      public function getindex(){          $accounts = accounts::select('account_id', 'account_name')                     ->where('client_id', '=', 7)                     ->paginate(100);           $name = 'mike a';          return view('accounts.listall', compact('accounts', 'name'));      }      public function getaccounts($id){          return view('accounts.account')->withname('mike a');     } } 

this accounts model

namespace app;  use illuminate\database\eloquent\model;  class accounts extends model {      /**      * database table used model.      *      * @var string      */     protected $table = 'accounts';      /**      * attributes mass assignable.      *      * @var array      */     protected $fillable = ['account_id', 'account_name', 'company_code'];      /**      * attributes excluded model's json form.      *      * @var array      */     protected $hidden = []; } 

but still white screen

first off, shouldn't using db::table('accounts'). should using account::all(). it's syntax though guess.

i assume have table named accounts 2 columns of table being account_id , account_name. being said, whole class should similar this:

<?php namespace app\http\controllers;  use app\http\requests; use app\http\controllers\controller;  use illuminate\http\request;  use app\account; //don't forget can use below  class accountcontroller extends controller {      public function getindex() {         $accounts = account::select('account_id', 'account_name')                     ->where('client_id', '=', 7)                     ->paginate(100);          $name = 'mike a';          return view('accounts.listall', compact('accounts', 'name'));     } 

is need?


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -