Laravel 5, Call to undefined method stdClass::update()
I'm using Laravel 5 and I have a simple edit page that must update database. when I try to run it, I got error
FatalErrorException in UserController.php line 47: Call to undefined method stdClass::update()
Controller :
public function userUpdate()
if(Input::get('send'))
$arr = [
'email' => Input::get('email')
];
DB::table(Config::get('users_table'))->find(Input::get('userId'))->update(['is_active' => TRUE]);
return redirect()->route('users');
Database schema :
id bigserial NOT NULL,
username text,
email text,
permission integer NOT NULL,
is_staff boolean NOT NULL DEFAULT false,
is_active boolean NOT NULL DEFAULT false,
updated_at timestamp without time zone,
created_at timestamp without time zone,
remember_token text
Route :
Route::post('/user/update', [
'as' => 'userUpdate', 'uses' => 'UserController@userUpdate'
]);
View :
!! Form::open(['route' => 'userUpdate', 'method' => 'post']) !!
<label>Username</label>
!! Form::text('username', $user->username, ['class' => 'form-control readonly', 'readonly' => '']) !!
<label>Email</label>
!! Form::text('email', $user->email, ['class' => 'form-control']) !!
<label>Permission</label>
!! Form::text('permission', $user->permission, ['class' => 'form-control']) !!
!! Form::hidden('userId', $user->id) !!
!! Form::submit('Update User', ['class' => 'btn green', 'name' => 'send']) !!
!! Form::submit('Cancel', ['class' => 'btn black', 'name' => 'clear']) !!
!! Form::close() !!
I use this structure, specially this type of using Input and Form class in another function in my controller for make list of rows or get an individual row of table, and everything was ok, but in updating database I got Call to undefined method stdClass::update()
error. Is there something that I am missing?
php laravel laravel-5 stdclass laravel-query-builder
add a comment |
I'm using Laravel 5 and I have a simple edit page that must update database. when I try to run it, I got error
FatalErrorException in UserController.php line 47: Call to undefined method stdClass::update()
Controller :
public function userUpdate()
if(Input::get('send'))
$arr = [
'email' => Input::get('email')
];
DB::table(Config::get('users_table'))->find(Input::get('userId'))->update(['is_active' => TRUE]);
return redirect()->route('users');
Database schema :
id bigserial NOT NULL,
username text,
email text,
permission integer NOT NULL,
is_staff boolean NOT NULL DEFAULT false,
is_active boolean NOT NULL DEFAULT false,
updated_at timestamp without time zone,
created_at timestamp without time zone,
remember_token text
Route :
Route::post('/user/update', [
'as' => 'userUpdate', 'uses' => 'UserController@userUpdate'
]);
View :
!! Form::open(['route' => 'userUpdate', 'method' => 'post']) !!
<label>Username</label>
!! Form::text('username', $user->username, ['class' => 'form-control readonly', 'readonly' => '']) !!
<label>Email</label>
!! Form::text('email', $user->email, ['class' => 'form-control']) !!
<label>Permission</label>
!! Form::text('permission', $user->permission, ['class' => 'form-control']) !!
!! Form::hidden('userId', $user->id) !!
!! Form::submit('Update User', ['class' => 'btn green', 'name' => 'send']) !!
!! Form::submit('Cancel', ['class' => 'btn black', 'name' => 'clear']) !!
!! Form::close() !!
I use this structure, specially this type of using Input and Form class in another function in my controller for make list of rows or get an individual row of table, and everything was ok, but in updating database I got Call to undefined method stdClass::update()
error. Is there something that I am missing?
php laravel laravel-5 stdclass laravel-query-builder
add a comment |
I'm using Laravel 5 and I have a simple edit page that must update database. when I try to run it, I got error
FatalErrorException in UserController.php line 47: Call to undefined method stdClass::update()
Controller :
public function userUpdate()
if(Input::get('send'))
$arr = [
'email' => Input::get('email')
];
DB::table(Config::get('users_table'))->find(Input::get('userId'))->update(['is_active' => TRUE]);
return redirect()->route('users');
Database schema :
id bigserial NOT NULL,
username text,
email text,
permission integer NOT NULL,
is_staff boolean NOT NULL DEFAULT false,
is_active boolean NOT NULL DEFAULT false,
updated_at timestamp without time zone,
created_at timestamp without time zone,
remember_token text
Route :
Route::post('/user/update', [
'as' => 'userUpdate', 'uses' => 'UserController@userUpdate'
]);
View :
!! Form::open(['route' => 'userUpdate', 'method' => 'post']) !!
<label>Username</label>
!! Form::text('username', $user->username, ['class' => 'form-control readonly', 'readonly' => '']) !!
<label>Email</label>
!! Form::text('email', $user->email, ['class' => 'form-control']) !!
<label>Permission</label>
!! Form::text('permission', $user->permission, ['class' => 'form-control']) !!
!! Form::hidden('userId', $user->id) !!
!! Form::submit('Update User', ['class' => 'btn green', 'name' => 'send']) !!
!! Form::submit('Cancel', ['class' => 'btn black', 'name' => 'clear']) !!
!! Form::close() !!
I use this structure, specially this type of using Input and Form class in another function in my controller for make list of rows or get an individual row of table, and everything was ok, but in updating database I got Call to undefined method stdClass::update()
error. Is there something that I am missing?
php laravel laravel-5 stdclass laravel-query-builder
I'm using Laravel 5 and I have a simple edit page that must update database. when I try to run it, I got error
FatalErrorException in UserController.php line 47: Call to undefined method stdClass::update()
Controller :
public function userUpdate()
if(Input::get('send'))
$arr = [
'email' => Input::get('email')
];
DB::table(Config::get('users_table'))->find(Input::get('userId'))->update(['is_active' => TRUE]);
return redirect()->route('users');
Database schema :
id bigserial NOT NULL,
username text,
email text,
permission integer NOT NULL,
is_staff boolean NOT NULL DEFAULT false,
is_active boolean NOT NULL DEFAULT false,
updated_at timestamp without time zone,
created_at timestamp without time zone,
remember_token text
Route :
Route::post('/user/update', [
'as' => 'userUpdate', 'uses' => 'UserController@userUpdate'
]);
View :
!! Form::open(['route' => 'userUpdate', 'method' => 'post']) !!
<label>Username</label>
!! Form::text('username', $user->username, ['class' => 'form-control readonly', 'readonly' => '']) !!
<label>Email</label>
!! Form::text('email', $user->email, ['class' => 'form-control']) !!
<label>Permission</label>
!! Form::text('permission', $user->permission, ['class' => 'form-control']) !!
!! Form::hidden('userId', $user->id) !!
!! Form::submit('Update User', ['class' => 'btn green', 'name' => 'send']) !!
!! Form::submit('Cancel', ['class' => 'btn black', 'name' => 'clear']) !!
!! Form::close() !!
I use this structure, specially this type of using Input and Form class in another function in my controller for make list of rows or get an individual row of table, and everything was ok, but in updating database I got Call to undefined method stdClass::update()
error. Is there something that I am missing?
php laravel laravel-5 stdclass laravel-query-builder
php laravel laravel-5 stdclass laravel-query-builder
asked Feb 2 '16 at 6:36
Mahmood KohansalMahmood Kohansal
557524
557524
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
you can't use find method in query builder,you need to use where
public function userUpdate()
if(Input::get('send'))
$arr = [
'email' => Input::get('email')
];
DB::table(Config::get('users_table'))->where('id',Input::get('userId'))->update(['is_active' => TRUE]);
return redirect()->route('users');
add a comment |
In my case I had to change from
first() to limit(1)
ie.
$blog = DB::table('blogs')
->where('blogs.id', $id)
->first();
To
$blog = DB::table('blogs')
->where('blogs.id', $id)
->limit(1);
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35146650%2flaravel-5-call-to-undefined-method-stdclassupdate%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
you can't use find method in query builder,you need to use where
public function userUpdate()
if(Input::get('send'))
$arr = [
'email' => Input::get('email')
];
DB::table(Config::get('users_table'))->where('id',Input::get('userId'))->update(['is_active' => TRUE]);
return redirect()->route('users');
add a comment |
you can't use find method in query builder,you need to use where
public function userUpdate()
if(Input::get('send'))
$arr = [
'email' => Input::get('email')
];
DB::table(Config::get('users_table'))->where('id',Input::get('userId'))->update(['is_active' => TRUE]);
return redirect()->route('users');
add a comment |
you can't use find method in query builder,you need to use where
public function userUpdate()
if(Input::get('send'))
$arr = [
'email' => Input::get('email')
];
DB::table(Config::get('users_table'))->where('id',Input::get('userId'))->update(['is_active' => TRUE]);
return redirect()->route('users');
you can't use find method in query builder,you need to use where
public function userUpdate()
if(Input::get('send'))
$arr = [
'email' => Input::get('email')
];
DB::table(Config::get('users_table'))->where('id',Input::get('userId'))->update(['is_active' => TRUE]);
return redirect()->route('users');
answered Feb 2 '16 at 6:41
Imtiaz PabelImtiaz Pabel
3,6601816
3,6601816
add a comment |
add a comment |
In my case I had to change from
first() to limit(1)
ie.
$blog = DB::table('blogs')
->where('blogs.id', $id)
->first();
To
$blog = DB::table('blogs')
->where('blogs.id', $id)
->limit(1);
add a comment |
In my case I had to change from
first() to limit(1)
ie.
$blog = DB::table('blogs')
->where('blogs.id', $id)
->first();
To
$blog = DB::table('blogs')
->where('blogs.id', $id)
->limit(1);
add a comment |
In my case I had to change from
first() to limit(1)
ie.
$blog = DB::table('blogs')
->where('blogs.id', $id)
->first();
To
$blog = DB::table('blogs')
->where('blogs.id', $id)
->limit(1);
In my case I had to change from
first() to limit(1)
ie.
$blog = DB::table('blogs')
->where('blogs.id', $id)
->first();
To
$blog = DB::table('blogs')
->where('blogs.id', $id)
->limit(1);
answered Nov 14 '18 at 18:20
Black MambaBlack Mamba
2,81412139
2,81412139
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35146650%2flaravel-5-call-to-undefined-method-stdclassupdate%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown