Reputation: 7195
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
Reputation: 54
Try this
$project_type = DB::table('project')
->where('code',$asset_request->project_code)
->select('project.*')
->first();
dd($project_type);
Upvotes: 0
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