artisticre
6 days ago
194
3
Laravel

Not sure what to do

Posted 6 days ago by artisticre

I have an application. I think my relationship might be wrong but here goes. Its working and collecting data. It is all working fine except when I want to click on an individual application. It is listing all based on the the application table user_id. This is where I think my relationships are wrong.

Users Table

public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

Profile Table

public function up()
    {
        Schema::create('profile', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->bigInteger('user_id')->nullable();
            $table->string('address')->nullable();
            $table->string('apt')->nullable();
            $table->string('city')->nullable();
            $table->string('state')->nullable();
            $table->string('zipcode')->nullable();
            $table->string('homephone')->nullable();
            $table->string('cellphone')->nullable();
             $table->timestamps();
        });
    }

Application Table

public function up()
    {
        Schema::create('sponsorapp', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->bigInteger('user_id')->unsigned();
            $table->string('besttime');
            $table->string('applicantname');
            $table->boolean('applicantbaptized');
            $table->boolean('spousediscuss');
            $table->boolean('bothspouseattend');
            $table->string('ifnospouseattend')->nullable;
            $table->text('whygoodcandidate');
            $table->text('applicantattitude');
            $table->text('leadershipexpectations');
            $table->text('sponsorsupport');
            $table->text('otherinfo');
            $table->date('datesigned');
            $table->timestamps();
        });
    }

Show method

public function show($id)
    {
        {
            $sponsor = DB::table('users')
            ->join('profile', 'profile.user_id', '=', 'users.id')
            ->leftJoin('sponsorapp', 'sponsorapp.user_id', '=' ,'users.id')
            ->select(
                'users.name', 
                'users.email', 
                'profile.address',
                'profile.apt',
                'profile.city',
                'profile.state',
                'profile.zipcode',
                'profile.homephone',
                'profile.cellphone',
                'sponsorapp.applicantname',
                'sponsorapp.besttime',
                'sponsorapp.applicantbaptized',
                'sponsorapp.spousediscuss',
                'sponsorapp.bothspouseattend',
                'sponsorapp.user_id'
                )
                ->where('sponsorapp.user_id', '=', $id)
                ->get();
                return view('sponsorapplication.show', compact('sponsor'));
        }
    }

Please sign in or create an account to participate in this conversation.