My code is showing the error as follows while displaying images from databse

  Fri 16 / 06 / 2023

  Posted by: wajahat

Category : Laravel

Tags : laravel , deployment

Description

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'galleries.products_id' in 'where clause'
SELECT * FROM `galleries` WHERE `galleries`.`products_id` = 1 AND `galleries`.`products_id` IS NOT NULL limit 1


View Code
                        <div class="container">

        <div class="row pt120">

            <div class="books-grid">



            <div class="row mb30">



               @if (count($products) > 0)



               @foreach ($products as $product)



               <div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">

                <div class="books-item">

                    <div class="books-item-thumb">



                      @if ($product->gallery)



                      <img src="{{ asset('assets/site/img/'. $product->gallery->image ) }} " alt="book">



                      @endif





                        <div class="new">New</div>

                        <div class="sale">Sale</div>

                        <div class="overlay overlay-books"></div>

                    </div>
                
  Answered by CDL

I think defined your foreign key with a different name, if it isn't id so specify it in the model.

~~~

protected $primaryKey = 'Your_primary_ID';

~~~

If it's not the case, reach back to us again using post comments with more details. You can also update the post content to share more detail with us. Thank you

  Comment   Share
0 Likes   3 Comments


comment-author
Sonam Ojha

SELECT * FROM `galleries` WHERE `galleries`.`product_id` = 1 AND `galleries`.`product_id` IS NOT NULL LIMIT 1; it's looking like you unknown column 'galleries.products_id' in the WHERE clause of your SQL query. you should check your sql structure



Reply


commented 1 year ago
comment-author
Hadayat Niazi Super Admin

Good job dear.



comment-author
wajahat Author

can you please share the screen with me whenever you have time please tell me I want to learn more but get stuck here ??



Reply


commented 1 year ago
comment-author
wajahat Author

Still have a same problem sir ?



Reply


commented 1 year ago
comment-author
Hadayat Niazi Super Admin

Please share more detail about your project.