I want to pass a variable from a function passes to function message. I create $groupname in the else sector and try to use it in the message function query. What is in my case the best way to do this?
class ExistingGroupMembers implements Rule
{
public function __construct()
{
//
}
public function passes($attribute, $value)
{
$existingMembers = Member::where([['idgroup', $value],['member', '<>', Auth::id()]])->select('id')->first('id');
if(!empty($existingMembers)){
return true;
}else{
$groupname = Group::where('id', $value)->select('name')->first();
return false;
}
}
public function message()
{
return 'In der Gruppe ' .$groupname. ' existieren keine User!';
}
}