0
I’m having trouble with the ORM Eloquent
where I give update
in a table and a column of that table is the same as mine input
he leaves null
.
Example:
Table
name idade
joão 10
using the command
$user->update($input);
being $user
the users table model, if I upgrade the age to 10 again it leaves age as null
, but using the command
DB::table('users')->where('id', $id)->update($input);
works properly.
Controller
<?php
use Illuminate\Database\Eloquent\ModelNotFoundException;
use \Carbon\Carbon;
class Users extends BaseController implements InterfaceController {
use \Traits\UserTrait;
public
$rules = [
‘idade’ => 'numeric'
],
public $model;
public function __construct(Users $model)
{
$this->model = $model;
}
public function update($id) {
$user = $this->model->findOrFail($id);
$input = Input::all();
$user->update($input);
}
}
Put also your
controller
, also put what is$input
? I didn’t understand the first part since it worked the second– novic
I put the example of the controller. I need the first function because of the type of answer. The first command returns all the data of the updated object, the second returns only 1(success) or 0(error).
– Hélio Biancardi
It makes no sense. If I exchange $user->update($input) for DB::table('users')->Where('id', $id)->update($input) it works normal. I didn’t change anything in the users' model. I needed to create the update method to change what it does after the update. In other cases it works normal.
– Hélio Biancardi
I understood I made a mess, what returns:
$input = Input::all();
???– novic
Input::all() would be the array that was sent by the POST method via front-end form using ajax.
– Hélio Biancardi
I need to know what the values are
var_dump
inInput::all()
?– novic
array (size=2) 'name' => string 'John Test' (length=10) 'age' => string '10' (length=2)
– Hélio Biancardi
Post your model?
– novic