[英]Base table or view not found: 1146 Table 'aswakt.annonce_order' does not exist
I want to send the data of a sold product , by payment, to mailtrap but it gives me error:我想通过付款将已售产品的数据发送到 mailtrap,但它给了我错误:
SQLSTATE [42S02]: Base table or view not found: 1146 The table 'aswakt.annonce_order' does not exist (SQL: select adverts. *, Advertisement_order.order_id as pivot_order_id, Advertisement_order.annonce_id as pivot_annonce_id, Advertisement_order.quantity as pivot_quantity from adverts inner join Advertisement_order on adverts.id = adverts_order.annonce_id where adverts_order.order_id = 3 and adverts.deleted_at is null) (View: D:\wamp\www\aswakt\resources\views
\emails\orders\placed.blade.php)
. . my table that I create is ' Annonces_order
', I don't know where it finds the ' Announcement_order
' table.我创建的表是“ Annonces_order
”,我不知道它在哪里可以找到“ Announcement_order
”表。
OrderPlaced.php已下订单.php
public $order;
public function __construct(Order $order)
{
$this->order = $order;
}
public function build()
{
return $this->to($this->order->billing_email, $this->order->billing_name)
->bcc('another@another.com')
->subject('Order for aswak tinghir ')
->markdown('emails.orders.placed');
}
web.php网页.php
Route::get('/mailable', function(){
$order = App\Order::find(1);
return new App\Mail\OrderPlaced($order);
});
placed.blade.php放置.blade.php
Thank you for your order.
**Order ID:** {{ $order->id }}
**Order Email:** {{ $order->billing_email }}
**Order Name:** {{ $order->billing_name }}
**Order Total:** ${{ round($order->billing_total / 100, 2) }}
**Items Ordered**
@foreach ($order->annonces as $annonce)
Name: {{ $annonce->name }} <br>
Price: ${{ round($annonce->price / 100, 2)}} <br>
Quantity: {{ $annonce->pivot->quantity }} <br>
@endforeach
Order.php订单.php
public function annonces()
{
return $this->belongsToMany('App\Annonce')->withPivot('quantity');
}
OrderAnnonce.php订单通知.php
class OrderAnnonce extends Model
{
protected $table = 'order_annonce';
protected $fillable = ['order_id','annonce_id','quantity'];
}
Sounds like a pivot table between your annonce
and order
models.听起来像是annonce
和order
模型之间的数据透视表。
From the documentation on Many To Many Relationships :" To determine the table name of the relationship's intermediate table, Eloquent will join the two related model names in alphabetical order. However, you are free to override this convention. You may do so by passing a second argument to the belongsToMany method "来自多对多关系的文档:“为了确定关系的中间表的表名,Eloquent 将按字母顺序连接两个相关的模型名称。但是,您可以随意覆盖此约定。您可以通过传递一个属于belongsToMany 方法的第二个参数“
In your models relations, add a second parameter 'annonces_order':在您的模型关系中,添加第二个参数“announces_order”:
return $this->belongsToMany(Order::class, 'Annonces_order');
and和
return $this->belongsToMany(Annonce::class, 'Annonces_order');
Or, rename your table Annonces_order
to annonce_order
.或者,你的表重命名Annonces_order
到annonce_order
。
Edit:编辑:
Since you're using an intermediate model you need to tell your relations to actually use that model.由于您使用的是中间模型,因此您需要告诉您的关系实际使用该模型。 Add ->using(OrderAnnonce::class)
to both of your relations:将->using(OrderAnnonce::class)
到您的两个关系中:
return $this->belongsToMany('App\Annonce')->using(OrderAnnonce::class)->withPivot('quantity');
More on Defining Custom Intermediate Table Models有关定义自定义中间表模型的更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.