Kevin
Kevin

Reputation: 653

How to get data from database using id?

I am getting id value from vue to model "Zones". But in model I can't get the values from db. Below code I am using to get values.

  class Zones extends Model{
    protected $primaryKey = 'zone_id';
    public function getZone($id){
         $zone = Zones::where('zone_id','=',$id)->first();

         printf($zone);
         exit(0);
    }
 }

Can you please help me what's wrong here?

Upvotes: 0

Views: 91

Answers (3)

Leena Patel
Leena Patel

Reputation: 2453

Use print_r() method to prints array

class Zones extends Model {
protected $primaryKey = 'zone_id';
public function getZone($id){
     $zone = Zones::where('zone_id','=',$id)->first();

     print_r($zone);
     exit(0);
   }
}

Upvotes: 4

bimal
bimal

Reputation: 31

printf($var) 

it prints normal variable string , integer etc

print_r($var);

it prints array

$zone is an array so you need to use print_r

Upvotes: 1

Aleksandrs
Aleksandrs

Reputation: 1509

You could use dd($your_data) function instead of print_r() and exit(0).

There is also dump($your_data) which just prints but not dies.

Also you could use ('zone_id',$id) instead of ('zone_id','=',$id).

Upvotes: 0

Related Questions