为什么会出现“找不到类'App \ Models \ NewMod'”错误?

时间:2019-05-23 09:56:38

标签: laravel-5

我每次都得到try { JSONArray array = new JSONArray(response); goodModelArrayList = new ArrayList<>(); for (int i = 0; i < array.length(); i++) { JSONObject e = array.getJSONObject(i); spinnerModel = new MyTransport(); fromcenter = new Fromcenter(); location = new Location(); for (int j = 0; j < e.length(); j++) { JSONObject object = e.getJSONObject("location"); latitude = object.getString("latitude"); longitude = object.getString("longitude"); } for (int k = 0; k < e.length(); k++) { JSONObject object = e.getJSONObject("fromcenter"); car = object.getString("car"); //bus = object.getString("bus"); //I am not able to get the bus. It throws JSONException error. } spinnerModel.setId(String.valueOf(e.getString("id"))); spinnerModel.setName(e.getString("name")); spinnerModel.setFromcenter(car); //spinnerModel.setBus(bus); //I am not able to store the datas. spinnerModel.setLocation(latitude); spinnerModel.setLocations(longitude); goodModelArrayList.add(spinnerModel); } } catch (Exception e) { e.printStackTrace(); } 。我已经尝试过针对该问题的先前解决方案,但没有一个可以帮助我。我已经多次更改了模型和控制器的名称,以检查这是否是命名约定问题,但无法解决。

在模型中:     

App/Models error

在控制器中:     

namespace App\models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class NewMod extends Model
{
 public function add()
{DB::connection('lara1')->insert("insert into abc (id, name) values (?, 
?)', [2, 'pqr']);")}
}
}

在途中:

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Models\NewMod ;

class NewModController extends Controller
{
public function add()
{
    /*$a= $_GET["name"];

    DB::insert('insert into abc (id, name) values (?, ?)', [2, $a]);*/
    $l= new NewMod();
    $l->add;
    echo "record inserted ";
}
}

1 个答案:

答案 0 :(得分:0)

替换

use App\Models\NewMod ;

使用

use App\models\NewMod ;

如果您的文件夹名称是Models

替换

namespace App\models;

使用

namespace App\Models;