0

I’m assuming this may be some convention I’m not understanding.

I have a model called Ingredient in the main App folder.

namespace App;

use Illuminate\Database\Eloquent\Model;

class Ingredient extends Model
{
    protected $table = "ingredients";
}

Then I have a controller trying to call that app

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Config;
use App\Ingredient;

class IngredientController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return response()
            ->json([
                'status' => 'ok',
                'ingredients' => Ingredient::all()
            ]);
    }
}

Everything seems to be ok. I get a 500 server error though:

include(C:\\Dev\\ScratchApi\\vendor\\composer\/..\/..\/app\/Ingredients.php): failed to open stream: No such file or directory

The file name of the model is Ingredient.php

Do I need to rename my file to Ingredients.php to meet a naming convention? Or why is this trying to call a file name different from the class name I’m telling it to look for?

2
  • try to clear the cache and update the composer. Commented Jul 19, 2019 at 10:01
  • make use php artisan make:model ModelName -m. You need not to mention table name while using this command. Make sure you model name is singular Commented Jul 19, 2019 at 10:04

3 Answers 3

1

I think it's because of autoload cache. So, Run following command on your project root directory,

composer dumpautoload

Hope it works.

Sign up to request clarification or add additional context in comments.

2 Comments

I think this is it. In a few more minutes it will let me accept and answer. I’ll mark this accepted.
@Jhorra Glad to help you bro.
1

Add option "-o" when run dump autoload.

composer dump-autoload -o

Comments

0

Try to use this:

composer dump-autoload

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.