9 months ago

Method destroy() not picking up ID

Posted 9 months ago by boby

So, I am working on something that should be like online books library. I have controllers Books and Users, and one as a relation between them, called OweController. I use CRUD on this controllers. When I navigate to Owes page I fill it like this:

public function index()
        $owes = Owe::where('', '1')
                    ->leftjoin('books','owes.book_id', '=', '')
                    ->leftjoin('users','owes.user_id', '=', '')
                    ->select(' as oweId', ' as bookId','books.title',' as userId','users.first_name','users.last_name')

        return view('owes.index', compact('owes'));

then on index I have a form for book return:

<form method="POST" action="{{ route('owes.destroy', $owe->oweId) }}">
    <input type="hidden" name="member" value="{{ $owe->userId }}">  
        <button type="submit" class="btn btn-primary">
                {{ __('Return book') }}

So question: if I use as above: route('owes.destroy', $owe->oweId) my destroy method picks this oweId as:

public function destroy($oweId)
        $owe = Owe::findOrFail((int)($oweId));
        $owe->update(['active' => false]);

but if I do it like on other controllers using: action="/owes/$owe->oweId) - this oweID is sent to destroy but not picked up from it. It is null. Of course my destroy is different in that case: destroy(Request $request, Owe $owes)

Second question is, can I send userId without using hidden in above form as I think that is not a proper way to do it.

So sorry for such a long post, but I wanted to provide as much info as possible.

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