How do I get users to enter their username after logging in?
<p>I want users to enter a username before they get to the dashboard view (if it's the first time they ever logged in) and that "Enter a unique username" will only appear once after their first login and never appear again. I'm not sure do I involve the HomeController and dashboard view(timeline) or not and whether I should just do an @if and @else statement to distinguish between username = null or not.</p>

<p>Home Controller:</p>

<pre><code>use Auth;

class HomeController extends Controller
{
public function index()
{
    if (Auth::check()) {
        return view('dashboard.index');
    }

    return view('home');
}

}
</code></pre>

<p>This is my User.php:</p>

<pre><code>use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
protected $table = 'users';

protected $fillable = [
    'username',
    'first_name',
    'last_name',        
    'email', 
    'password',
    'location',
    'gender',
    'date_of_birth',
];

protected $hidden = [
    'password', 
    'remember_token',
];

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

    }

    if ($this-&gt;first_name) {
        return $this-&gt;first_name;
    }

    return null;

}

    public function getUsername()
{
    if ($this-&gt;first_name &amp;&amp; $this-&gt;last_name) {
    return "{$this-&gt;first_name}.{$this-&gt;last_name}";

    }

    if ($this-&gt;first_name) {
        return $this-&gt;first_name;
    }

    return null;

}

public function getNameOrUsername()
{
    return $this-&gt;getName() ?: $this-&gt;username;
}

public function getUsernameOrName()
{
    return $this-&gt;getUsername() ?: $this-&gt;username;
}

public function getFirstNameOrUsername()
{
    return $this-&gt;first_name ?: $this-&gt;username;
}
}
</code></pre>

<p>getusername.blade.php:</p>

<pre><code>&lt;div style="min-width: 800px; margin: 0 auto; position: relative; top: 75px;"&gt;
&lt;div class="row" style="width: 600px; margin: 0 auto; border: 2px solid #000; padding: 40px;"&gt;
    &lt;div class="col-lg-6" style="width: 600px; color: #999; padding: 44.5px 0;"&gt;
    &lt;h3 style="color: #000; margin-top: 0; margin-bottom: 10px;"&gt;Enter a username&lt;/h3&gt;
        &lt;form class="form-vertical" role="form" method="post" action="{{ route('dashboard.getusername') }}"&gt;
        &lt;div&gt;
            &lt;div&gt;Your public username is the same as your Profile address:

                &lt;div&gt;
                &lt;ul&gt;
                    &lt;li&gt;
                    &lt;div&gt;mostwanted.com/&lt;span id="display_name"&gt;
                    &lt;script&gt;
                    $('#username').keyup(function () {
                    $('#display_name').text($(this).val());
                    });
                    &lt;/script&gt;
                    &lt;/span&gt;&lt;/div&gt;
                    &lt;/li&gt;
                &lt;/ul&gt;
                &lt;/div&gt;
            &lt;/div&gt;
                &lt;div class="form-group {{ $errors-&gt;has('username') ? ' has-error' : '' }}"&gt;
                    &lt;label for="username" class="control-label"&gt;Choose a username&lt;/label&gt;
                    &lt;input style="width: 456px;" placeholder="e.g.&amp;nbsp;{{ Auth::user()-&gt;getUsernameOrName() }}" type="text" name="username" class="form-control" id="username" value=""&gt;
                        @if ($errors-&gt;has('username'))
                            &lt;span class="help-block" style="font-size: 12px; margin-bottom: 0;"&gt;{{ $errors-&gt;first('username') }}&lt;/span&gt;
                        @endif
                &lt;/div&gt;
                &lt;div&gt;Note:&amp;nbsp;Your username cannot be changed and should include your authentic name&amp;nbsp;&lt;/div&gt;
        &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class="form-group" style="margin-top: 15px;"&gt;
                &lt;button style="float: right;" type="submit" class="btn btn-primary"&gt;Save username&lt;/button&gt;
            &lt;/div&gt;
            &lt;input type="hidden" name="_token" value="{{Session::token()}}"&gt;                
        &lt;/form&gt;
    &lt;/div&gt;
&lt;/div&gt;  
</code></pre>

<p></p>

<p>UsernameController:</p>

<pre><code>use Auth;
use DB;
use MostWanted\Models\User;
use Illuminate\Http\Request;


class UsernameController extends Controller
{
public function getUsername()
{
    return view('dashboard.getusername');
}

public function postUsername(Request $request)
{

    $username = Auth::user()-&gt;username;

    if (!$username) {
        return view('dashboard.getusername');
    }

    $this-&gt;validate($request, [
        'username' =&gt; 'required|unique:users|regex:/^[A-Za-z0-   9.]+$/|max:50',
        ]);

    User::create([
        'username' =&gt; $request-&gt;input('username'),
        ]);     

    return view('dashboard.index');

}
}
</code></pre>

<p>The last time I did it was <code>@if (Auth::user()-&gt;username===null)</code> it only goes to the form for entering a username even if I've entered a username already (redirect to the username form only).</p>

<p>P.S I have no idea why the <code>&lt;script&gt;</code> doesn't work. I want the <code>&lt;span&gt;</code> to display whatever is being entered in the <code>&lt;input&gt;</code></p>

<p>EDIT*:</p>

<p>routes.php:</p>

<pre><code>/** 
*Home + Entering Username
*/
Route::get('/', [
'uses' =&gt; '\MostWanted\Http\Controllers\HomeController@index',
'as' =&gt; 'home',
]);

Route::get('/', ['middleware' =&gt; 'nousername', function () {

[
'uses' =&gt; '\MostWanted\Http\Controllers\UsernameController@getUsername',
'as' =&gt; 'dashboard.getusername',
];

[
'uses' =&gt; '\MostWanted\Http\Controllers\UsernameController@postUsername',
];

}]);

Route::group(['middleware' =&gt; ['web']], function () {

/**
*Authenication
*/

#Sign up
Route::get('/signup', [
'uses' =&gt; '\MostWanted\Http\Controllers\AuthController@getSignup',
'as' =&gt; 'auth.signup',
'middleware' =&gt; ['guest'],
]);

Route::post('/signup', [
'uses' =&gt; '\MostWanted\Http\Controllers\AuthController@postSignup',
'middleware' =&gt; ['guest'],
]);

#Log in
Route::get('/login', [
'uses' =&gt; '\MostWanted\Http\Controllers\AuthController@getSignin',
'as' =&gt; 'auth.signin',
'middleware' =&gt; ['guest'],
]);

Route::post('/login', [
'uses' =&gt; '\MostWanted\Http\Controllers\AuthController@postSignin',
'middleware' =&gt; ['guest'],
]);

#Log out
Route::get('/logout', [
'uses' =&gt; '\MostWanted\Http\Controllers\AuthController@getSignOut',
'as' =&gt; 'auth.signout',
]);

/**
*Search
*/

Route::get('/search', [
'uses' =&gt; '\MostWanted\Http\Controllers\SearchController@getResults',
'as' =&gt; 'search.results',
]);

/**
*User profile
*/

Route::get('/user/{username}', [
'uses' =&gt; '\MostWanted\Http\Controllers\ProfileController@getProfile',
'as' =&gt; 'profile.index',
]);

});
</code></pre>

<p>NoUsernameMiddleware:</p>

<pre><code>namespace MostWanted\Http\Middleware;

use Auth;
use Closure;

class NoUsernameMiddleware
{
public function handle($request, Closure $next) {
if(!Auth::user()-&gt;username) {
    return redirect("/choose_username");
}
    return $next($request);
}
}
</code></pre>