I have a problem when I make a request on my Laravel server
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'dbdespensa.imagenesProducto' doesn't exist (SQL: select * from
imagenesProducto
whereproductoId
= 5)
I have the imagenesProducto table but laravel didnt recognize it
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)
Or maybe you have problem in model. You should specify table name in model.
class ImagenesProducto extends Model{
public $table = "imagenesProducto";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.