1

This is my code :

Route:

Route::get('/editposts/{id}', function ($id) {
    $showpost = Posts::where('id', $id)->get();
    return view('editposts', compact('showpost'));
});


Route::post('/editposts', array('uses'=>'PostController@Update'));

Controller :

public function Update($id)
{

    $Posts = Posts::find($id);
    $Posts->Title = 10;
    $Posts->Content = 10;
    $Posts->save();

    //return Redirect()->back(); Input::get('Title')

}

and View:

            @foreach($showpost as $showpost)

            <h1>Edit Posts :</h1>

            {{ Form::open(array('url'=>'editposts', 'method'=>'post')) }}
            Title : {{ Form::text('Title', $showpost->Title) }} <br> Content : {{ Form::text('Content', $showpost->Content ) }} <br> {{ Form::submit('Update') }}
            {{ Form::close() }}

            @endforeach

but when I want to Update my data i receive an error :

http://localhost:8000/editposts/1

Missing argument 1 for App\Http\Controllers\PostController::Update()

4 Answers 4

2

You need to change route:

Route::post('editposts/{id}', 'PostController@Update');

Then the form to:

{{ Form::open(['url' => 'editposts/' . $showpost->id, 'method'=>'post']) }}
Sign up to request clarification or add additional context in comments.

2 Comments

NotFoundHttpException in RouteCollection.php line 161:
@Mohammad please post the exact route and form you're using now.
0

Change your post route to:

Route::post('/editposts/{id}', 'PostController@Update');

Done!

1 Comment

NotFoundHttpException in RouteCollection.php line 161:
0

Correct the route,specify a parameter

    Route::post('editposts/{id}', 'PostController@Update');

Pass the post'id as paramater

  {{ Form::open(array('url'=>'editposts/'.$post->id, 'method'=>'post')) }}

        Title : {{ Form::text('Title', $showpost->Title) }} <br> Content : {{ Form::text('Content', $showpost->Content ) }} <br> {{ 

        Form::submit('Update') }}
   {{ Form::close() }}

Notice $post->id

1 Comment

NotFoundHttpException in RouteCollection.php line 161:
0

First declare your route:

Route::post('/editposts/{id}', array('uses'=>'PostController@Update'));

Then update your form url:

{{ Form::open(['url' => url()->action('PostController@Update', [ "id" => $showpost->id ]), 'method'=>'post']) }}

This is assuming your model's id column is id

(Optional) You can also use implicit model binding :

public function Update(Posts $id) {
    //No need to find it Laravel will do that 
    $id->Title = 10;
    $id->Content = 10;
    $id->save();
 }

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.