Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
找不到基表或视图:1146表“laravel8.brand”不存在(SQL:select count(*)_Laravel - Fatal编程技术网

找不到基表或视图:1146表“laravel8.brand”不存在(SQL:select count(*)

找不到基表或视图:1146表“laravel8.brand”不存在(SQL:select count(*),laravel,Laravel,我已经迁移了我的数据库: 正如您所看到的,添加了品牌 在我的品牌控制器上,我得到了以下信息: <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Brand; use Illuminate\Support\Carbon; class BrandController extends Controller { public function AllBrand(){

我已经迁移了我的数据库:

正如您所看到的,添加了品牌

在我的品牌控制器上,我得到了以下信息:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Brand;
use Illuminate\Support\Carbon;

class BrandController extends Controller
{
    public function AllBrand(){
        $brands = Brand::latest()->paginate(2);
        return view('admin.brand.index', compact('brands'));
    }

    public function StoreBrand(Request $request){
        $validatedData = $request->validate([
            'brand_name' => 'required|unique:brand|min:4',
            'brand_image' => 'required|mimes:jpg,jpeg,png',
        ],
        [
            'brand_name.required' => 'Please input brand name',
            'brand_image.min' => 'Brand longer than 4 Characters'
        ]);

        $brand_image = $request->file('brand_image');
        $name_gen = hexdec(uniqid());
        $img_ext = strtolower($brand_image->getClientOriginalExtension());
        $img_name = $name_gen.'.'.$img_ext;
        $upload_location = 'images/brand/';
        $publish_image =  $upload_location.$img_name;
        $brand_image->move($upload_location,$img_name);

        Brand::insert([
            'brand_name' => $request->brand_name,
            'brand_image' => $publish_image,
            'created_at' => Carbon::now()
        ]);

        return Redirect()->back()->with('success', 'Brand added successfully!');
    }
}
但当我尝试添加一个品牌时,它向我显示了以下错误:SQLSTATE[42S02]:找不到基表或视图:1146表'laravel8.brand'不存在SQL:选择count*作为brandwherebrand\u name=Practice\u Bom的聚合

不确定是什么原因造成的,但我很确定我已经迁移了它,如下图所示


你知道我遗漏了什么吗?

也许你可以在模型中设置表名,将其设置为复数:

类品牌延伸模式 { 受保护的$table=‘品牌’; ... }
数据库中的表是多个品牌,但您的代码使用的是单数品牌。您是否在代码中的某个位置指定了表名,但遗漏了s?我建议您删除品牌表,并从迁移表中删除迁移,然后运行php artisan迁移命令。我同意,请检查您的模型文件。$table变量应该设置为brands才能工作。@MuzaffarShaikh投票给我:D
  <form action="{{ route('store.brand') }}" method="POST" enctype="multipart/form-data">
    @csrf
  <input type="text" name="brand_name" placeholder="Brand name"/>
  @error('brand_name')
  <span style="color: red; font-weight: bold;"> {{ $message }}</span>
  @enderror

  <h3>Brand Image</h3>

  <input type="file" name="brand_image"/>
  @error('brand_image')
  <span style="color: red; font-weight: bold;"> {{ $message }}</span>
  @enderror
  <br/>
  <br/>
  
  <button type="submit">Add Brand</button>
  </form>