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

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -