Answer the question
In order to leave comments, you need to log in
How to add your own method to the User model?
I want to add my own method that will calculate the number of messages and set this amount in the user field = rating.
There is a model that was originally in Laravel:
<?php
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function updateRating($query)
{
...
}
}
$user = User::where('name','=',$username);
$user->increment('answ_num');
$user->updateRating();
Call to undefined method Illuminate\Database\Query\Builder::updateRating()
Answer the question
In order to leave comments, you need to log in
$user = User::where('name','=',$username)->get();
You did not receive the model itself. You just got a request builder
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question