I have three tables: User, Product and Purchase
User: id, email
Product: id, name
Purchase: user_id, product_id, transaction_id
In Laravel, I have defined these models:
class User extends Authenticatable {
//only protected $$fillable and $hidden fields
}
class Product extends Model {
//only protected $$fillable and $hidden fields
}
class Purchase extends Model {
public function user() {
return $this->hasOne('App\Models\Access\User\User');
}
public function product() {
return $this->hasOne('App\Models\Modules\Product');
}
}
The idea is that I can find out which user has purchased which products so that (in my view) I can loop over the products and indicate which ones have been purchased already by that user
I can put an extra column 'purchased' into products (which I can fill once the purchase was successfull) but I would rather avoid this because I feel I have all the information available.
Anyone has a suggestion how I could achieve this?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2jAaQzD
via IFTTT
Aucun commentaire:
Enregistrer un commentaire