0
votes

I'm new to laravel. Using version 5.4 and tried to search but don't see what I'm doing wrong. I keep getting an "Undefined variable: post" in my view. I'm also doing form model binding. Model binding works properly when manually entering URL. Just can't click on link to bring up edit view.

My routes:

Route::get('test/{id}/edit','TestController@edit');

My controller:

public function edit($id)
{
    $post = Post::find($id);

    if(!$post)
        abort(404);
    return view('test/edit')->with('test', $post);
}

My form:

{{  Form::model($post, array('route' => array('test.update', $post->id), 'files' => true, 'method' => 'PUT')) }}
2
You are returning the content of $post as 'test' - So you can access this variable in your view in this case with $test instead $post.CodeBrauer

2 Answers

3
votes

You're assigning the post value to 'test', so should be accessible with $test rather than $post.

You probably want to do either of these two things instead:

return view('test/edit')->with('post', $post);

or

return view('test/edit', ['post' => $post]);

https://laravel.com/docs/5.4/views

0
votes

Your controller is sending a variable named "test", but your error says that your blade file doesn't have the $post variable passed into it. This can be fixed by changing "test" to "post" in your controller.