I've this this model City.php in app\Models
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class City extends Model
{
//
}
and this CityController.php
<?php
namespace App\Http\Controllers;
use App\Models\City;
use Illuminate\Http\Request;
class CityController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
$cities = City::OrderBy('city_code')->get();
return view('testcities',compact('cities'));
}
but i get back this error in laravel:
Error Class 'App\Models\City' not found
You should rename cities.php
to Cities.php
. But based on Laravel best practices Model names MUST be in singular form with its first letter in uppercase. So it's better to create model name with City
rather than Cities
.
Please make sure your class is named Cities.php
. You can also try to run composer dump-autoload
to tell Composer to read all your classes again.
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.