Не отображается имя пользователя спонсора, Laravel - PullRequest
1 голос
/ 27 сентября 2019

Я делаю многоуровневую систему, и мы используем реферальную ссылку, но имя пользователя спонсора не отображается в html страницы регистрации, и для доступа необходимо выйти из текущего сеанса.

Моя миграция:

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddReferrerToUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('users', function (Blueprint $table) 
        {
                $table->integer('referrer_id')->unsigned()->default(1)->after('id');
                $table->foreign('referrer_id')->references('id')->on('users');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('users', function (Blueprint $table)
         {
                $table->dropForeign(['referrer_id']);
                $table->dropColumn( 'referrer_id' );
        });
    }
}

Мой контроллер: refController.php

<?php

namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;

class RefController extends Controller
{
    public function index( $username )
     {
    $user = User::where( 'username', $username )->first();

    return ( is_null( $user ) )
        ? redirect( '/' )
        : redirect( '/register' )->withCookie( cookie()->forever( 'referrer_id', $user->id ) );
     }
}

Мои маршруты:

Route::get('/user', function () {
    return redirect('/');
});

Route::get('/user/{username}', 'RefController@index' );

Мой HTML:

    <?php if (isset($referrer_id->id)) { ?>

        <p class="login-box-msg" style="margin-top: 20px; margin-bottom: 30px; color: #373737;">You have been nominated for:<br><b>{{$referrer_id->name. ' - '. $referrer_id->email}}</b></p>

    <?php } ?>

Моя структура "referrer_id" находится внутри таблицы "users".

Ответы [ 2 ]

0 голосов
/ 27 сентября 2019

переименуйте ваш html-файл в ####. Php в ####. Blade.php

и напишите этот код, и вы можете получить какие-либо данные, проверьте

@php print_r(Auth::user()->referrer_id);
print_r(Auth::user()->name);  //as per your database field name name
print_r(Auth::user()->email);  //as per your database field name email
@endphp


 <?php if (isset(Auth::user()->referrer_id)) { ?>

        <p class="login-box-msg" style="margin-top: 20px; margin-bottom: 30px; color: #373737;">You have been nominated for:<br><b>{{Auth::user()->name. ' - '. Auth::user()->email}}</b></p>

 <?php } ?>
0 голосов
/ 27 сентября 2019
  <?php if (isset(Auth::user()->referrer_id)) { ?>

        <p class="login-box-msg" style="margin-top: 20px; margin-bottom: 30px; color: #373737;">You have been nominated for:<br><b>{{Auth::user()->name. ' - '. Auth::user()->email}}</b></p>

    <?php } ?>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...