i have two tables (orders & products) and one pivot table (order_product). i have made many to many relationship b\w them using following code.
class Product extends Model{
protected $fillable = ['name', 'price', 'is_iframe_product'];
public function orders() {
return $this->belongsToMany(Order::class);
} }
class Order extends Model{
public $guaded = ['id'];
protected $fillable = ['is_iframe_order','price', 'status', 'address_id', 'user_id'];
public function products () {
return $this->belongsToMany(Product::class);
} }
i am using following code to insert records in CheckoutController.php
$Product = array('name' => $item['item_name'], "price" => $item['price'], "is_iframe_product" => "1");
$saved = order()->products()->attach([$Product]);
but getting this error:
exception: "Symfony\Component\Debug\Exception\FatalThrowableError" file: "C:\wamp3\www\jewellery\jewellery\app\Http\Controllers\CheckoutController.php" line: 63 message: "Call to undefined function App\Http\Controllers\order()"
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2SwQGEi
via IFTTT
Aucun commentaire:
Enregistrer un commentaire