Laravel 6.x this works... how call an Eloquent Laravel db method?

Laravel 6.x the below works… how instead to call an Eloquent Laravel db method???

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Controllers\Controller;

use Illuminate\Support\Facades\DB;

class DogController extends Controller

{
    public function index()
    {
        $dogs = DB::select('select * from dogs');

        foreach ($dogs as $dog) {

            echo $dog->name;

        }

    }
....


<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Dog extends Model
{
// empty
}


namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Controllers\Controller;

use Illuminate\Support\Facades\DB;

class DogController extends Controller

{
    public function index()
    {
$dogs = App\Dog::all();

this fails… what to do?

{
public function index()
{
$dogs = App\Dog::all();

where all() method is? gives error

https://laravel.io/forum/how-instead-call-an-eloquent-static-method-from-controller

solved here ^^^

1 Like