简体   繁体   English

未找到基表或视图:1146 表 'aswakt.annonce_order' 不存在

[英]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.听起来像是annonceorder模型之间的数据透视表。

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_orderannonce_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.

相关问题 未找到基表或视图:1146 表 Laravel 5 - Base table or view not found: 1146 Table Laravel 5 Laravel 8:未找到基表或视图:1146 表 - Laravel 8: Base table or view not found: 1146 Table 在Symfony3中找不到基表或视图:1146 - Base Table or View not found:1146 in symfony3 Symfony2:找不到基表或视图:1146 - Symfony2: Base table or view not found: 1146 未找到基表或视图:1146 表 &#39;xyz.testimonials&#39; 不存在(SQL:select * from `testimonials`) - Base table or view not found: 1146 Table 'xyz.testimonials' doesn't exist (SQL: select * from `testimonials`) LARAVEL - 未找到基表或视图:1146 表不存在(SQL: select * from ) - LARAVEL - Base table or view not found: 1146 Table doesn't exist (SQL: select * from ) Laravel Spatie 权限 - 未找到基表或视图:1146 表“my_database.models”不存在 - Laravel Spatie Permissions - Base table or view not found: 1146 Table 'my_database.models' doesn't exist Laravel 8 - 未找到基表或视图:1146 表“laravel8.brand”不存在 - Laravel 8 - Base table or view not found: 1146 Table 'laravel8.brand' doesn't exist 找不到基表或视图:1146表&#39;epharmacy.medicines&#39;不存在 - Base table or view not found: 1146 Table 'epharmacy.medicines' doesn't exist SQLSTATE [42S02]:未找到基表或视图:1146表X不存在 - SQLSTATE[42S02]: Base table or view not found: 1146 Table X doesn't exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM