A
A
a0xh2022-01-06 04:47:07
Laravel
a0xh, 2022-01-06 04:47:07

How to implement edit method in Laravel?

I have the following route:

user/{login}/accounts/{account}/edit

I am trying to implement the edit() method in the resource controller like this:

public function edit(Account $account)
{
    return view('user.account.edit', [
        'account' => $account
    ]);
}


But I get an error: Argument 1 passed to App\Http\Controllers\User\AccountController::edit() must be an instance of App\Account, string given .

Also I tried to implement it in this way:

public function edit($id)
{
    $account = Account::find($id);
    return view('user.account.edit', dd($account));
}


But then I get just Null .

What am I doing wrong and in which direction should I dig?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2022-01-06
@a0xh

You have two parameters in the route, and you are trying to accept only one in the method, and the second one. And the framework passes both there, as you asked.

A
a0xh, 2022-01-06
@a0xh

As Aleksey Ukolov wrote above , you just had to pass the second parameter.

public function edit($login, Account $account)
{
    return view('profile.accounts.edit', [
        'account' => $account
    ]);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question