0
votes

When i'm try to pass data to edit page then i got this error.Please help me

QueryException in Connection.php line 729: SQLSTATE[42S22]: Column not found: 1054 Unknown column '1' in 'field list' (SQL: select 1 from phonebooks)

PhonebookController.php

public function edit($id)
    {
        $data = Phonebooks::all($id);
        echo"$data";
        return view('phonebook.edit', compact('$data'));
    }

edit.blade.php

<html>
    <body>
        <form method="POST" action="{{ URL::to('phonebook') }}" >
            <input type="text" name="id" value="{{$id}}"/>
            <input type="text" name="phoneNo" value="{{old('phoneNo')}}"/>
            <input type="text" name="email" value="{{old('email')}}" />
            <input type="submit" value="Save"/>
            <input type="hidden" name="_token" value="{{ csrf_token() }}">
        </form>

    </body>
</html>
2
try Phonebooks::find($id); And use print_r instead of echo - Meera Tank
Try it also,then got this error ErrorException in dbaaacd2cddb92a8901b9b21664ee9c4c15a3183.php line 5: Undefined variable: id (View: /home/ubuntu/workspace/student/resources/views/phonebook/edit.blade.php) - Rika

2 Answers

2
votes

You should try this:

 public function edit($id)
        {
            $data = Phonebooks::find($id);

            return view('phonebook.edit', compact('data'));
        }

<html>
    <body>
        <form method="POST" action="{{ URL::to('phonebook') }}" >
            <input type="text" name="id" value="{{$data->id}}"/>
            <input type="text" name="phoneNo" value="{{old('phoneNo')}}"/>
            <input type="text" name="email" value="{{old('email')}}" />
            <input type="submit" value="Save"/>
            <input type="hidden" name="_token" value="{{ csrf_token() }}">
        </form>

    </body>
</html>
0
votes
public function edit($id)
        {
            $data = Phonebooks::find($id);
            return view('phonebook.edit', compact('data'));
        }

If you use Laravel Form Model then not required to pass any hidden data and assign individual values. Below is link how you can use Form model. Even not require passing CSRF token on hidden.

https://selftaughtcoders.com/from-idea-to-launch/lesson-23/laravel-5-application-form-model-binding-laravelcollective-forms-html-library-bootstrap-framework/

{!! Form::model($post, ['method' => 'PATCH','url' => ['/admin/posts',$post->id], ]) !!}

{!! Form::text('phoneNo', null, ['class' => 'form-control']) !!}

{!! Form::email('email', null, ['class' => 'form-control']) !!}
{!! Form::submit('Save', ['class' => 'btn btn-primary form-control']) !!}

Hope this is a help to you!