Skip to content

Instantly share code, notes, and snippets.

@VictorFursa
Last active November 10, 2017 11:52
Show Gist options
  • Save VictorFursa/16084e85ed8c39460f03db0ff291086e to your computer and use it in GitHub Desktop.
Save VictorFursa/16084e85ed8c39460f03db0ff291086e to your computer and use it in GitHub Desktop.
class Cupon extends Model
{
/**
* Получить продукт где купон id связан.
*/
public function product()
{
return $this->belongsTo('App\Product');
}
}
$cupon = App\Cupon::find(1); - найти купон по id = 1
echo $cupon->product->title;
____________________________
$product = App\Product::find(1);
foreach($product->cupons as $cupon) {
$cupon-id;
}
____________________________________
$prodcuts = App\Product::findAll();
foreach($products as $product) {
foreach($product->cupons as $cupon) {
$cupon->id
}
}
___________________________________________
$cupons = App\Product::find(1)->cupons;
foreach($cupons as $cupon)
{ $cupon->id }
class Product extends Model
{
/**
* Получить купон.
*/
public function cupons()
{
return $this->hasMany('App\Cupon');
}
}
@serkor
Copy link

serkor commented Nov 10, 2017

Спасибо)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment