2 years ago

Type error: Argument 1 passed to Controller::show() must be an instance of model, string given

Posted 2 years ago by elgin

I have been trying building an application to track apartment expenses and while implementing the show method for displaying expenses of a specific apartment I got an error stating Type error: Argument 1 passed to App\Http\Controllers\ExpensesController::show() must be an instance of App\Expense, string given

My route for the page is as follows

Route::get('/apartments/{apartment}/expenses/{expense}', '[email protected]');

My controller method is as follows

public function show(Expense $expense)
        return view('layouts.expenses.show', compact('expense'));

I have also tried changing the controller method to

public function show($id)
    $expense = Expense::find($id);
        return view('layouts.expenses.show', compact('expense'));

and the result was getting value of "1 " for any id. I have checked the urls from my list template and they are generated correctly.

Any clues?

Please sign in or create an account to participate in this conversation.