Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php][mysql]model i pobieranie list
snerf
post 8.09.2015, 12:07:32
Post #1





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

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


Witam

modele:
  1. class Product extends Model
  2. {
  3. protected $fillable = [
  4. 'category_id',
  5. 'product_number',
  6. 'img'
  7. ];
  8. public $table = 'products';
  9.  
  10. public function categories(){
  11. return $this->belongsToMany('App\Category');
  12. }
  13. public function getCategoryIdAttribute(){
  14. dd($this->categories->lists('id')->ToArray()); <-- tu jest błąd
  15.  
  16. }
  17. }

  1. class Category extends Model
  2. {
  3. protected $fillable = [
  4. 'name',
  5. 'img'
  6. ];
  7. public $table = 'categories';
  8.  
  9. public function products(){
  10. return $this->hasMany('App\Product');
  11. }
  12. }

mysql:
-categories
:id
:name

-products
:id
:category_id

error:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'lavarel.category_product' doesn't


Rozumiem że błąd mam z pivotami?
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 04:36