php - how to select specific columns in laravel -


i want show values of 2 specified columns 'first_name' , 'pic' 'users' table. trying 'pluck' showing json format when echo. need show it, - 'john pic' all.please, me. here sample code in 'index.blade.php' bellow -

<?php $fname = db::table('users')->pluck('first_name','pic');  echo $fname; ?> 

use can use select

$fname = db::table('users')->select('first_name','pic')->get(); 

since, direct access database view not preferred, can write query in controller function,

public function getdata(){     $fname = db::table('users')->select('first_name','pic')->get();     return view('index',compact('fname')); } 

now, iterate on loop in view file,

@foreach($fname $name)     // access data {{$name->first_name}} , {{$name->pic}} @endforeach 

hope understand.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -