Closed lps83 closed 3 years ago
Does your user model already have a name() method or interface that returns a relationship? Mine only ever expects to return a string, so I find your error odd. Can you show more of your stack trace? I'd like to know if the error is being thrown from my package or your app in general.
Yes, I only have one public function name() in App/Models/User I may made a mistake during the configuration ... I don't have an attribute name. I use "username"
Stacktrace :
`[2021-03-21 20:01:16] local.ERROR: App\Models\User::name must return a relationship instance. {"userId":26,"exception":"[object] (LogicException(code: 0): App\Models\User::name must return a relationship instance. at /Users/sylvain/Documents/dev/obpro/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:464) [stacktrace]
"} `
Did you fix it? My package requires your provider models to implement my contract, which requires the name()
method. So if you already had a name method on your model that did not return a string, that will cause conflicts. I have not used jetstream, but I am unsure why I see 'name' being loaded on your model, and as a relationship. Seems my package is conflicting with something else you had on your user model?
I'm still working on it. No your fonction name() is the only one in my user's model.
public function name(): string { return strip_tags(ucwords($this->username)); }
Can you share your user model then? Also, what happens if you grab a user model and dump($user->name())
and dump($user->username)
? I have no issues myself using my name method or overwriting it in my projects that use this package.
This is my user model :
`<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Illuminate\Support\Facades\Auth; use Laravel\Fortify\TwoFactorAuthenticatable; use Laravel\Jetstream\HasProfilePhoto; use Laravel\Sanctum\HasApiTokens; use Spatie\Permission\Traits\HasRoles; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use RTippin\Messenger\Contracts\MessengerProvider; use RTippin\Messenger\Contracts\Searchable; use RTippin\Messenger\Traits\Messageable; use RTippin\Messenger\Traits\Search;
class User extends Authenticatable implements MessengerProvider, Searchable { use HasApiTokens; use HasFactory; use HasProfilePhoto; use HasRoles; use Notifiable; use TwoFactorAuthenticatable; use Messageable; use Search;
private $attached;
private $expire;
private $highlevel;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'username',
'fname',
'lname',
'email',
'password',
'ipv4',
'color',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password',
'pin',
'remember_token',
'two_factor_recovery_codes',
'two_factor_secret',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = [
'profile_photo_url',
];
static public function userAttachedFullName(){
}
static public function userAttachedShortName(){
}
static public function getCoiffeurs(){
}
static public function getCoiffeursId(){
}
static public function getCoiffeursJSON(){
}
static public function getStaffUsername($id){
}
static public function getUserById($id){
}
static public function isAttachedCan($doWhat){
}
static public function prestaFullOrNot($array){
}
static public function getAgendasData($id){
}
static public function getStoreName(){
}
//Messenger
public function getAvatarColumn(): string
{
return 'profile_photo_path';
}
public function name(): string
{
return strip_tags(ucwords($this->username));
}
} `
dd(strip_tags(ucwords($this->username))) works and return my username.
What are these coming from?
static public function userAttachedFullName(){
}
static public function userAttachedShortName(){
}
I know nothing about jetstream, but looking at the stacktrace, my provider resource will return your base model, ( https://github.com/RTippin/messenger/blob/master/src/Http/Resources/ProviderResource.php#L77 ) and laravel is calling some jetstream code for your picture, which seems to reference name, which you do not even have on your model as you changed that (lname, fname, username).
https://github.com/laravel/jetstream/blob/2.x/src/HasProfilePhoto.php#L69
InvalidArgumentException
The given provider { App\Models\User } must implement the interface RTippin\Messenger\Contracts\MessengerProvider
at vendor/rtippin/messenger/src/Messenger.php:92 88▕ } 89▕ 90▕ foreach ($providers as $provider) { 91▕ if (! is_subclass_of($provider, MessengerProvider::class)) { ➜ 92▕ throw new InvalidArgumentException("The given provider { $provider } must implement the interface ".MessengerProvider::class); 93▕ } 94▕ 95▕ $this->providers[$provider] = new MessengerProviderDTO($provider); 96▕ }
+1 vendor frames
2 app/Providers/MessengerServiceProvider.php:28 Illuminate\Support\Facades\Facade::__callStatic("registerProviders")
I apply all things
but when i run php artisan serve this error
@tapang786 Please do not reply to old issues that have nothing in common with your issue at hand, on top of opening a new issue.
Hi, Thanks for you amazing work ! I trying to make it work on one of my project !
Sadly I get stuck with this error.
[2021-03-18 20:27:02] local.ERROR: App\Models\User::name must return a relationship instance. {"userId":26,"exception":"[object] (LogicException(code: 0): App\\Models\\User::name must return a relationship instance. at /Users/sylvain/Documents/dev/obpro/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php:464)
I put that in my User Model because I use Username instead of 'name'
public function name(): string { return strip_tags(ucwords($this->username)); }
Any idea ? Thanks