Skip to content

How can i add image column in my table? #1302

Discussion options

You must be logged in to vote

Hey Guys!, This is how you can add an image column.

    public function addColumns(): PowerGridColumns
    {
        return PowerGrid::columns()
            ->addColumn('id')
            ->addColumn('image_url', function (Product $model) {
                if ($model->image_url !== null) {
                    return '<img class="img-fluid" src="'.url('storage/product_images/'.$model->image_url).'" height="150" width="120" alt="'.$model->image_url.'">';
                } else {
                    return '<img class="img-fluid" src="'.url('storage/common/default.png').'" height="150" width="120" alt="Default Image">';
                }
            });
    }

Hope this helps!

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Minhazul-Islam18
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@luanfreitasdev
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants