mardi 1 décembre 2015

Undefined property: Illuminate\Database\Eloquent\Collection::$id

I don't know exactly why I'm getting this error as indicated by title. I am trying to write the code fro deleting records. This is the code below.

<TABLE >
            @foreach($users as $user)
                <TR><TD>{{ $user->id }}</TD><TD>{{ $user->firstname }}</TD><TD><div id="divContainer"><div class="theDiv"><form action="/users/{{ $users->id }}" method="POST"> {{ csrf_field() }} {{ method_field('DELETE') }}<button class="css-deletebutton">DELETE</button></form></div></div></TD><TD>{!! Form::submit('DEACTIVATE', ['class'=>'css-statusbutton']) !!}</TD></TR>
            @endforeach

            <!--{!! $users->render() !!}-->
    </TABLE>

This is the route:

Route::resource('users', 'UserController');

This is the controller method:

public function show($id)
    {
        $users = User::find($id);
        return view('userpages.show')->with('users', $users);
    }

This is the view to be displayed for deletion of any record.

@section('body')
    {!! Form::open([ 'method' => 'delete', 'route' => ['users.destroy', $users->id]]) !!}
    <TABLE>
        <TR><TD>{{ $users->firstname }}</TD><TD>{{ $users->lastname }}</TD><TD>{{ $users->email }}</TD><TD>{{ $users->username }}</TD><TD>{!! Form::submit('DELETE', ['class'=>'css-deletebutton']) !!}</TD></TR>
    </TABLE>
    {!! Form::close() !!}
    @stop

This is the error message I'm getting:

ErrorException in acf1a7ad2174bd2b743200b1a50b4c9f line 14:
Undefined property: Illuminate\Database\Eloquent\Collection::$id (View: C:\Users\ken4ward\Documents\xampp\htdocs\schoolproject\resources\views\userpages\index.blade.php)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire