Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][Laravel]eloquent i powiązania modeli
snerf
post
Post #1





Grupa: Zarejestrowani
Postów: 74
Pomógł: 3
Dołączył: 30.03.2014

Ostrzeżenie: (0%)
-----


Witam
Może przejdę do porblemu.

baza:
-products
-categories

model
-category
  1. <?php
  2. protected $fillable = [
  3. 'name',
  4. 'img'
  5. ];
  6. public function products(){
  7. return $this->belongsToMany('App\Product');
  8. }
  9. ?>

-product
  1. protected $fillable = [
  2. 'category_id',
  3. 'product_number',
  4. 'img'
  5. ];
  6. public function categories(){
  7. return $this->belongsToMany('App\Category');
  8. }


controller category
  1.  
  2. @foreach($category as $article)
  3. {{ $article->name }} // DZIAŁA
  4. <ul>
  5. @foreach($article->products as $tag) // ZWRACA BŁĄD
  6. <li>{{ $tag->id }}</li>
  7. @endforeach
  8. </ul>
  9. @endforeach


błąd:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'lavarel.category_product' doesn't exist (SQL: select `products`.*, `category_product`.`category_id` as `pivot_category_id`, `category_product`.`product_id` as `pivot_product_id` from `products` inner join `category_product` on `products`.`id` = `category_product`.`product_id` where `category_product`.`category_id` = 1)

Mógłby ktoś nakierować mnie na rozwiązanie tego problemu?
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 13:49