Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72388

I need help in laravel 6 for reflecting the signed username name

$
0
0

My code is shown below. I want to reflect the getfirstnameorusername on my navigation bar where if someone logs in his or her her username is reflected up.

My PHP code:

<?php

    namespace App\Models;
    use Illuminate\Contracts\Auth\MustVerifyEmail;
    use Illuminate\Auth\Authenticatable;
    use Illuminate\Database\Eloquent\Model;
    use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContact;

    class User extends Model implements AuthenticatableContact
    {
        use Authenticatable;

           /**
         * The database table used by the model.
         *
         * @var string
         */
        protected $table = 'users';

        /**
         * The attributes that are mass assignable.
         *
         * @var array
         */
        protected $fillable = [
            'username',
             'email',
              'password',
               'first_name',
                'last_name',
                 'school',
                  'location',
        ];
        /**
         * The attributes excluded from the model's JSON form.
         *
         * @var array
         */
        /**
         * The attributes that should be hidden for arrays.
         *
         * @var array
         */
        protected $hidden = [
            'password',
             'remember_token',
        ];

        /**
         * The attributes that should be cast to native types.
         *
         * @var array
         */
        protected $casts = [
            'email_verified_at' => 'datetime',
        ];

        public function getName()
        {
            if($this->first_name && $this->last_name){
                return "{$this->first_name} {$this->last_name}";

            }
            if($this->first_name){
                return $this->first_name;
            }
            return null;
        }
        public function getNameorUsername()
        {
            return $this->getName() ?: $this->username;
        }
        public function getFirstNameorUsername()
        {
            return $this->getfirst_name() ?: $this->username;
        }

    }

This is my navigation bar:

<nav class="navbar navbar-default" role="navigation">
    <div class="container">
        <div class="navbar-header">
            <a class="navbar-brand" href="{{route('home')}}">findFriends</a>
        </div>
        <div class="collapse navbar-collapse">
            @if (Auth::check()) 
            <ul class="nav navbar-nav">
                <li><a href="#">Timeline</a></li>
                <li><a href="#">Friends</a></li>
            </ul>
              <form class="navbar-form navbar-left" action="#" role="search">
            <div class="form-group">
              <input type="text" class="form-control" placeholder="find Friends">
            </div>
            <button type="submit" class="btn btn-default">Search</button>
        </form>
           @endif
            <ul class="nav navbar-nav navbar-right">
                @if (Auth::check())
            <li><a href="#">{{ Auth::user()->getNameorUsername}}</a></li>
                <li><a href="#">Update Profile</a></li>
                <li><a href="{{ route('auth.signout')}}">Sign Out</a></li>
            @else
            <li><a href="{{route('auth.signup')}}">Sign Up</a></li>
            <li><a href="{{route('auth.signin')}}">Sign In</a></li>
            @endif
            </ul>
        </div>
    </div>
    </nav>

Viewing all articles
Browse latest Browse all 72388

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>