Support the ongoing development of Laravel.io →
Views Blade Forms
Last updated 2 years ago.
0

Add this to your controller.

use App\Profile;
0

ahmadaljazzar said:

Add this to your controller.

use App\Profile;

Class 'App\Profile' not found

Still :(

0

osherdo said:

ahmadaljazzar said:

Add this to your controller.

use App\Profile;

Class 'App\Profile' not found

Still :(

Do you have a Profile model ?

0

@ahmadaljazzar thanks.

I forgot to capitalize profile. Now I get another issue of undefined variable: $data

I am trying to insert data to db and redirect with this function :

{
	// persist the data (insert to db) 
	//and then redirect to the hub.
        Profile::create([
            'name' => $data['name'],
            'age' => $data['age'],
            'goals' => $data['goals'],
            'activityType' => $data['activityType'],
            'expectations' => $data['expectations']
        
        ]);

    return redirect()->route('hub');  // this is where you redirect to the hub after you store the User
    }

What's up with the data variable. Do you happen to know what should I do now?

If not that's okay too since you've done good with the original problem :)

0

You must pass $data to your store method, which is the request you're sending from your form. your store method should look like this.

protected function store(Request $data)
{
// persist the data (insert to db) 
//and then redirect to the hub.
        Profile::create([
            'name' => $data['name'],
            'age' => $data['age'],
            'goals' => $data['goals'],
            'activityType' => $data['activityType'],
            'expectations' => $data['expectations']

        ]);

    return redirect()->route('hub');
}
Last updated 8 years ago.
0

You're the best.

I am now getting this error (sql error):

QueryException in Connection.php line 651: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'age' cannot be null (SQL: insert into `profiles` (`age`, `goals`, `activityType`, `expectations`, `updated_at`, `created_at`) values (, , , , 2016-01-17 23:15:38, 2016-01-17 23:15:38))

I think I should change something in the migration regarding the age column. Just checking that out.

A big honest thanks deserves to you!

0

Your database fields aren't nullable, so you can't create a profile with empty values. check your form, make sure you name your inputs.

Last updated 8 years ago.
0

I've just changed the given field to this:

   $table->tinyInteger('age')->unsigned()->nullable();

Still gives me the same error :(

I am so sorry for troubling you much..

Last updated 8 years ago.
0

Share your form.

0

Please:

 {!! Form::open(['url'=>'/dashboard']) !!} 

        <p> A)&nbsp I am a: &nbsp{!! Form::radio('ActivityType',null,['class'=>'form-control']) !!} Male
 &nbsp{!! Form::radio('ActivityType',null,['class'=>'form-group']) !!} Female

@if (count($errors) > 0)
  <div class="alert alert-danger">
        <strong>Whoops!</strong> There were some problems with your input.<br><br>
        <ul>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div> 
@endif

 <br><br> B)&nbsp My Age is:
 {!! Form::number('name', 'value'); !!}


        <p> C)&nbsp What are your fitness goals for the next year?<br></p>
{!! Form::textarea('notes', 'By default,other users can see your goals.',['class'=>'form-control', 'maxlength'=>100]) !!}</p> <!--default is null -->
<p> D)&nbsp I am better in:</p>
 &nbsp&nbsp&nbsp{!! Form::radio('ActivityType',null,['class'=>'form-control']) !!}  Aerobics
 &nbsp{!! Form::radio('ActivityType',null,['class'=>'form-control']) !!} Anerobic
 &nbsp{!! Form::radio('ActivityType',null,['class'=>'form-group']) !!} I am pretty good at both <br><br>
 
 E) What do you expect from this app to help you? <br><br> (You can always change this later) <br><br>
 &nbsp{!! Form::checkbox('improve','New anerobic routines'); !!} Find new anerobic routines <br>
 &nbsp{!! Form::checkbox('improve','New aerobic routines'); !!} Find new aerobic routines <br>
 &nbsp{!! Form::checkbox('improve','Follow'); !!} Follow other users to get inspired <br>
<br><br>
{!! Form::submit('CreateProfile',['class'=>'form-group']) !!}
</div>

        {!! Form::close() !!}
0

You don't have any field with name of age. replace you age field with this.

{!! Form::number('age', null) !!}

This will render html input field with a name of age and type number.

0

@ahmadaljazzar okay thanks.

Now it says that 'goals' cannot be null. So I quickly updated the goals' section in the view to this:

  <p> C)&nbsp What are your fitness goals for the next year?<br></p>
{!! Form::textarea('goals','By default,other users can see your goals.',['class'=>'form-control', 'maxlength'=>100]) !!}</p> <!--default is null -->

and also in the migration to this:

 $table->tinyInteger('age')->unsigned()->nullable();
            $table->string('goals')->unsigned()->nullable();;

still gets me the same error. Do you know what now maybe? EDIT: I am off to sleep - really late here. I will check on this post tomorrow morning. thanks for now!!! extremely helpful you are :)

Last updated 8 years ago.
0

Remove the unsigned from goals and remove the duplicated semicolon then share the error please.

0

I have also made some progress.

I just need to change the value to activityType to an actual value. when trying to do this - it returns an error:

constant' aerobics' is not defined.

I also get:

Route [/hub] not defined.
0

@osherdo because you probably don't have a route named '/hub'.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

osherdo osherdo Joined 26 Apr 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.