lancecoder

@splendidkeen about the columns?

splendidkeen

Thank you for your patience @lancecoder

Yes, so that it won't create a new column for every change within my profile. Because the main idea was to distribute the data for a Business setup into two tables, that the first table mustn't carry all the data. For the second table, it would be great to also have a static column for with the business_id of my profile (that works already) and the changes within this column to be constant and always in this column (that doesn't work yet)

lancecoder

@splendidkeen no problem.

Can you show me your screenshot of doesn't work yet?

splendidkeen

So I am editing my profile as a Business at the edit.blade.php view:

edit.blade.php:

// This is where I edit a value within my first table (works), but overwrites values within the second table to NULL

(div) class="form-group{{ $errors->has('first_name') ? ' has-error' : ''}}""
        (label) for="first_name" class="control-label" id="labeledit">Name(/label)
        (input) type="text" name="first_name" class="form-control" id="editfields" value="{{ Request::old('first_name') ?: Auth::user()->first_name }}"(/)
        @if ($errors->has('first_name'))
            (span) class="help-block">{{ $errors->first('first_name') }}(/span)
        @endif
                                        
(/div) 


// This is where I edit a value within my second table (works within DB), but not within my profile to show/grab the value


(div) class="form-group{{ $errors->has('biography') ? ' has-error' : ''}}""
        (label) for="biography" class="control-label" id="labeledit">Biography(/label)
        (input) type="text" name="biography" class="form-control" id="editfields" value="{{ Request::old('biography') ?: Auth::user()->biography }}"(/)
        @if ($errors->has('biography'))
            (span) class="help-block">{{ $errors->first('biography') }}(/span)
        @endif
                                        
(/div) 

Can't figure it out

matthew.erskine

It looks like you're going around this in a really confusing way. You need clear distinction between your 'Business' resource and your 'Profile' resource. Create two separate migrations, models and controllers and you will find this a lot easier.

splendidkeen

I created everything twice. @matthew.erskine & it works, but I have a problem with grabbing the values from the second table for the authenticated user.

Edit2.blade.php:

(div) class="form-group{{ $errors->has('biography') ? ' has-error' : ''}}""(/)
    (label) for="biography" class="control-label" id="labeledit">Biography(/label)
    (input) type="text" name="biography" class="form-control" id="editfields" value="{{ Request::old('biography') ?: Auth::user()->biography }}"(/)
            @if ($errors->has('biography'))
                (span) class="help-block">{{ $errors->first('biography') }}(/span)
            @endif
                                        
(/div)  

It won't grab the value which is stored within the table 'businessadd'

Controller:

class PartnerSetupController extends Controller {

    
    public function getPartnerEdit(){
        return view('partner.profile.edit2');  
    }
    
    public function postPartnerEdit(Request $request){
        
        $this->validate($request, [

            'biography' => 'max:140',
            'sliderone' => 'max:500',
            'slidertwo' => 'max:25',
            'sliderthree' => 'max:25',
            

            
        ]);
            
            $business_id = Auth()->user()->id;
            
            if(MoreBusiness::where('business_id', $business_id )->count()) {
                MoreBusiness::where('business_id',$business_id)->update([
                    'business_id' => $business_id,
                    'biography' => $request->input('biography'),
                    'sliderone' => $request->input('sliderone'),
                    'slidertwo' => $request->input('slidertwo'),
                    'sliderthree' => $request->input('sliderthree'),
                    ]);
            }
            

}

Migration:


public function up()
        {
            Schema :: create ('businessadd', function(Blueprint $table){
                $table->increments('id');
                $table->integer ('business_id')->unsigned(); 
                $table->string ('biography');
                $table->string ('sliderone');
                $table->string ('slidertwo');
                $table->string ('sliderthree');
                $table->timestamps();

                $table->foreign('business_id')
                    ->references('id')
                    ->on('business')
                    ->onDelete('cascade');
        });

      }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema :: drop ('businessadd');
    }

Can't see the bridge-problem @matthew.erskine

splendidkeen

I deleted and recreated the table migration again, now it spits this err @lancecoder

SQLSTATE[HY000]: General error: 1364 Field 'business_id' doesn't have a default value (SQL: insert into `businessadd` (`biography`, `sliderone`, `slidertwo`, `sliderthree`, `updated_at`, `created_at`) values (Hello, , , , 2017-10-16 18:11:58, 2017-10-16 18:11:58))

lancecoder

@splendidkeen because you don't a value for business_id.

percy1995

help!

splendidkeen

@lancecoder

Because it is unsigned? How to value?

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