user3386779
user3386779

Reputation: 7195

Trying to get property of non-object on query data

I have a table with column code ,program_string_id,practice_string_id

$project = db::table('project as p')->where('p.code',$asset_request->project_code);
$project_type = $project->select('p.practice_string_id','p.program_string_id')->first();

print_r($project_type) gives stdClass Object ( [practice_string_id] => PRACTICE0019 [program_string_id] => )

print_r($project_type->practice_string_id); returns

Trying to get property of non-object.

How to get the value in laravel query

Upvotes: 0

Views: 75

Answers (2)

Narinder Bajwa
Narinder Bajwa

Reputation: 54

Try this

  $project_type = DB::table('project')
                  ->where('code',$asset_request->project_code)
                  ->select('project.*')
                  ->first();
   dd($project_type);

Upvotes: 0

Hamelraj
Hamelraj

Reputation: 4826

you can write single query like this and just debug weather you are getting correct code and correct data

 $project_type = DB::table('project')
                  ->where('code',$asset_request->project_code)
                  ->select('practice_string_id','program_string_id')
                  ->first();
   dd($asset_request->project_code,$project_type);

Upvotes: 1

Related Questions