简体   繁体   English

Laravel Lumen无法识别共享主机中的表

[英]Laravel Lumen cannot recognize table in shared hosting

I have a problem when I make a request on my Laravel server 我在Laravel服务器上发出请求时遇到问题

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'dbdespensa.imagenesProducto' doesn't exist (SQL: select * from imagenesProducto where productoId = 5) SQLSTATE [42S02]:找不到基表或视图:1146表'dbdespensa.imagenesProducto'不存在(SQL:从imagenesProducto中选择*,其中productoId = 5)

I have the imagenesProducto table but laravel didnt recognize it 我有imagenesProducto表,但是laravel无法识别它

Thanks and help :) 谢谢和帮助:)

namespace App\Http\Controllers;
use App\ImagenesProducto;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Database\Eloquent\ModelNotFoundException;
class ImagenesProductoController extends Controller
 {
    function getImagesByProduct(Request $request,$id){
    if($request-> isJson()){
        try{
            $images = ImagenesProducto::where('productoId','=',$id)->get();
            return response()->json($images,200);
        }catch(ModelNotFoundException $e){
            return response()->json("error"=>"error",500);
        }
    }else{
        return response()->json(['error'=>'Unhatorized'], 401, []);
    }
}

} }

Are other database queries successful? 其他数据库查询是否成功? (if not you should check .env file for db config) (如果不是,则应检查.env文件的数据库配置)

Or maybe you have problem in model. 也许您在模型中遇到问题。 You should specify table name in model. 您应该在模型中指定表名称。

class ImagenesProducto extends Model{
public $table = "imagenesProducto";

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM