简体   繁体   English

无法在 laravel 8 上执行自动完成 - 未找到基表或视图:1146 表“workshop.nama_suppliers”不存在

[英]Cannot do autocomplete on laravel 8 - Base table or view not found: 1146 Table 'workshop.nama_suppliers' doesn't exist

When I tried to do autocomplete on Laravel 8, the error is like this when i do inspection in my browser当我尝试在 Laravel 8 上进行自动完成时,当我在浏览器中进行检查时,错误是这样的

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'workshop.nama_suppliers' doesn't exist (SQL: select Supplier . namasupplier from nama_suppliers where Supplier . namasupplier LIKE %abcd%) SQLSTATE [42S02]:未找到基表或视图:1146 表“workshop.nama_suppliers”不存在(SQL:select Supplier 。来自namasupplier的供应商namasupplier其中Supplier nama_suppliers LIKE %abcd%)

I've already do php artisan migrate and this error still occurs.我已经做了 php artisan migrate 并且这个错误仍然发生。 Even though I don't do type nama_suppliers table at all in my code because in my database there is no table named "nama_suppliers".即使我根本没有在我的代码中键入 nama_suppliers 表,因为在我的数据库中没有名为“nama_suppliers”的表。

And this is my codes I've made:这是我制作的代码:

/database/migrations/2021_05_16_142836_create__supplier_table.php /database/migrations/2021_05_16_142836_create__supplier_table.php

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateSupplierTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if(Schema::hasTable('Supplier')) return;
        Schema::create('Supplier', function (Blueprint $table) {
            $table->id();
            $table->string('namasupplier');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('Supplier');
    }
}

app/Models/NamaSupplier.php应用程序/模型/NamaSupplier.php

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class NamaSupplier extends Model
{
    use HasFactory;

    protected $fillable = [
        'namasupplier'
    ];
}

app/Http/Controllers/homeController.php app/Http/Controllers/homeController.php

public function getnamasupplier(Request $request)
{
    $data = NamaSupplier::select("Supplier.namasupplier")
            ->where("Supplier.namasupplier","LIKE","%{$request->input('query')}%")
            ->get();
   
    return response()->json($data);
}

routes/web.php路线/web.php

Route::get('getnamasupplier', [homeController::class, 'getnamasupplier'])->name('getnamasupplier');

resources/views/tambah_transaksimasuk.blade.php资源/视图/tambah_transaksimasuk.blade.php

<div class="col-md-10 themed-grid-col">
    Supplier     <br>
    <div class="form-floating mb-3">
        <input type="text" class="nsup" name="namasupplier" value=""><br></br>
    </div>
        <script type="text/javascript">
            var path = "{{ route('getnamasupplier') }}";
            $('input.nsup').typeahead({
                source:  function (query, process) {
                return $.get(path, { query: query }, function (data) {
                        return process(data);
                    });
                }
            });
        </script>
</div>

Note: for jquery, I used this for this blade:注意:对于 jquery,我将此刀片用于此刀片:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.1/bootstrap3-typeahead.min.js"></script>

Can you explain why this happened and what solution should I do?你能解释一下为什么会发生这种情况,我应该怎么做?

Add protected $table in your Model, change your model into在 Model 中添加受保护的 $table,将 model 更改为

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class NamaSupplier extends Model
{
    use HasFactory;

    protected $table = 'Supplier';
    protected $fillable = [
        'namasupplier'
    ];
}

For the next development, consider using plural (kata benda jamak) as table's name and singular (kata benda tunggal) as model's name对于下一个开发,考虑使用复数 (kata benta jamak) 作为表名和单数 (kata benta tunggal) 作为模型名

eg: for table supplier, use suppliers as table name (lowered case) and use Supplier as model name, if you do this, you won't need to add protected $table within your model例如:对于表供应商,使用suppliers作为表名(小写)并使用Supplier作为 model 名称,如果这样做,则不需要在 model 中添加受保护的 $table

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Laravel 8 - 未找到基表或视图:1146 表“laravel8.brand”不存在 - Laravel 8 - Base table or view not found: 1146 Table 'laravel8.brand' doesn't exist 未找到基表或视图:1146 表 &#39;ifs.employees&#39; 不存在 Laravel 错误 - Base table or view not found: 1146 Table 'ifs.employees' doesn't exist Laravel Error Laravel:未找到基表或视图:1146表'database.pages不存在 - Laravel: Base table or view not found: 1146 Table 'database.pages doesn't exist 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 SQLSTATE[42S02]:未找到基表或视图:1146 表 &#39;***.indices&#39; 不存在 laravel - SQLSTATE[42S02]: Base table or view not found: 1146 Table '***.indices' doesn't exist laravel Laravel-[PDOException] SQLSTATE [42S02]:找不到基本表或视图:1146表&#39;ip.priorities&#39;不存在 - Laravel - [PDOException] SQLSTATE[42S02]: Base table or view not found: 1146 Table 'ip.priorities' doesn't exist SQLSTATE [42S02]:未找到基表或视图:1146 表“laravel_abonamenty2.currencies”不存在 - SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel_abonamenty2.currencies' doesn't exist SQLSTATE[42S02]: 未找到基表或视图:1146 表 'laravel9rentalcars.categories' 不存在 - SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel9rentalcars.categories' doesn't exist SQLSTATE[42S02]:未找到基表或视图:1146 Laravel 5.2 上不存在表“db_wls.users” - SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db_wls.users' doesn't exist on laravel 5.2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM