kordix
230
2
Laravel

How To EDIT Posts / Items / Threads

Posted 1 year ago by kordix

Im scared that I can't find anywhere proper way to have possibility to EDIT posts.

EDITING is not mentioned in Laravel from Scratch series.

In forum series there is update() method

public function update($channel, Thread $thread) { $this->authorize('update', $thread);

    $thread->update(request()->validate([
        'title' => 'required',
        'body' => 'required'
    ]));

    return $thread;
}

But this does not tell me much. There is no edit() method and no edit.blade.php

I tried this tutorial http://itsolutionstuff.com/post/crud-create-read-update-delete-example-in-laravel-52-from-scratchexample.html

Here is an error when I go to edit form Trying to get property of non-object (View: C:\xampp\TODOLISTA\resources\views\tasks\edit.blade.php)

Here is my routing: Route::get('tasks/edit/{id}', '[email protected]')->name('edit'); Route::patch('tasks/edit/{id}', '[email protected]')->name('update');

Methods in TaskController:

public function edit($id) { $task = Task::find($id); return view('tasks.edit', compact('task')); }

public function update(Request $request, $id)
{
    Task::find($id)->update([
    'title' => request('title'),
    'channel_id' => 2,
    'description' => request('description')
]);
}

edit.blade.php

{!! Form::model($task, ['method' => 'PATCH','route' => ['update', $task->id]]) !!} {{ csrf_field() }} Title Description Submit {!! Form::close() !!}

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