I have a database name lrvesikhon and there is a table named 'person'. I created a model named 'Person' and also create a controller named 'PersonsController'. I also config the .env file. But some error occurs. The error:
My code -
PersonController -
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class PersonsCotroller extends Controller
{
public function index(){
$person_list = Person::all();
dd($person_list);
}
}
Web -
<?php
Route::get('/', 'PersonsCotroller@index');
Person Model -
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Person extends Model
{
protected $table = "person";
}
CodePudding user response:
Your haven't hooked up the model class.
Add in your controller after namespace App\Http\Controllers:
use App\Models\Person;
CodePudding user response:
Write bellow code after use App\Http\Request;
use App\Models\Person;
If your model Person is not in Models directory change to use App\your-directory\Person;