I have a site set up to sell my photographic prints. The photos are in categories and are available in a number of sizes, so I have a photos, categories and sizes table, joined by a category_photo and photo_size table.
Up to now I have been adding new photos to the site using PHPMyAdmin, but manually updating three tables is a bit of a pain, so I am building a little backend to make it quicker. I can add a new photo to the photos table easily enough, but when it comes to populating the lookup tables for category and size I am running into a problem with the table names.
Here is my code for populating the category_photo table:
foreach($request->category as $category)
{
$catphoto = new Category_Photo(['photo_id' => $photo->id, 'category_id' => $category]);
$photo->categories()->save($catphoto);
}
However, when I run this, I get the error:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db.category__photos' doesn't exist (SQL: insert into `category__photos` (`photo_id`, `category_id`) values (50, 1))
It is looking for a table called category__photos rather than category_photo. How can I rectify this? Or is there a better way to achieve what I'm trying to do?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire