Parth Sureliya
Parth Sureliya

Reputation: 256

get only one row from first table in table left join in laravel

I have two table 1. Bog_post 2. blog_image

Now I want only one image from blog_image table. I also save post id in blog_image table. how can i do this query in laravel ?

Upvotes: 0

Views: 445

Answers (1)

user7986752
user7986752

Reputation:

Create a model as "BlogImage" and edit it.

class BlogImage extends Model
{
    protected $table = 'blog_image';

}

Then create a query with this model.

$blog_image = BlogImage::where('post_id',$post_id)->pluck('image')->first();

You can get just "image" column data in this way, as you want.

Also you can set releationship with this two tables. Here is documentation

Upvotes: 1

Related Questions