That means User::find($id) did not return a result. You can check that or use FindOrFail()
Dec 8, 2014
28
Level 5
Call to a member function update() on a non-object
I keep getting this error when I try to update my users
Call to a member function update() on a non-object
Here is my edit.blade.php
@extends('templates::admin')
@section('content')
{{ Form::model($users, array('method' => 'PATCH', 'route' =>'admin.users.update', 'route_id'=>$users->id)) }}
<ul>
<li>
{{ Form::label('name', 'Name') }}
{{ Form::text('name', $users->name, array('id' => 'name')) }}
</li>
<li style="display:none;">
{{ Form::label('password', 'Password') }}
{{ Form::text('password', $users->password, array('id' => 'password')) }}
</li>
<li>
{{ Form::label('email', 'Email') }}
{{ Form::text('email', $users->email, array('id' => 'email')) }}
</li>
<li>
{{ Form::submit('Submit', array('class' => 'btn btn-default', 'role' => 'button')) }}
</li>
</ul>
{{ Form::close() }}
@if($errors->any())
<ul>
{{ implode('', $errors->all('<li class="error">:message</li>')) }}
</ul>
@endif
@stop
and here is my UsersController
public function update($id)
{
$input = Input::all();
$validation = Validator::make($input, User::$rules);
if($validation->fails()){
return Redirect::route('admin.users.edit')
->withInput()
->withErrors($validation)
->with('message', 'There were validation errors');
}
if($validation->passes()){
$input['password'] = Hash::make($input['password']);
$users = User::find($id);
$users->update($input);
return View::make('users::index' , $id);
return Redirect::route('admin.users.edit', $id)
->withInput()
->withErrors($validation)
->with('message', 'There were validation errors');
}
}
and this is the line that is giving problems
$users->update($input);
Level 5
I have finally fixed my problem. It was so simple I want to cry and bash my head against the table.
I changed
return View::make('users::index' , $id);
to
return Redirect::route('admin.users.index', $id);
and it worked
Please or to participate in this conversation.