user11455925
user11455925

Reputation:

Pluck or Something else?

DB::table('mobil')->where('id',$id)->first().

I ever try it, but it give me all columns data. The problem is, In this Mobil table I have name, status, des, model and Id. The data that I need is name, status, and des. Can you help me to make a code to take some data that I need and it must one row. It must first row

Upvotes: 1

Views: 62

Answers (3)

Davit Zeynalyan
Davit Zeynalyan

Reputation: 8618

You can pass columns name as array in ->first() method

DB::table('mobil')
    ->where('id', $id)
    ->first(['name', 'status', 'des'])

Upvotes: 0

Natvarsinh Parmar - bapu
Natvarsinh Parmar - bapu

Reputation: 1138

Using DB query

DB::table('mobil')
    ->select('name', 'status', 'des')
    ->where('id', $id)  
    ->first(); 

Using model

if your model is Mobil.php

Mobil::select('name', 'status', 'des')
    ->where('id', $id)  
    ->first(); 

Upvotes: 0

Roman Meyer
Roman Meyer

Reputation: 2872

you can use select method

DB::table('mobil')
    ->where('id', $id)
    ->select(['name', 'status', 'des'])
    ->first();

Upvotes: 2

Related Questions