ahmadaljazzar said:
Add this to your controller.
use App\Profile;
Class 'App\Profile' not found
Still :(
osherdo said:
ahmadaljazzar said:
Add this to your controller.
use App\Profile;
Class 'App\Profile' not found
Still :(
Do you have a Profile model ?
@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 :)
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');
}
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!
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.
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..
Please:
{!! Form::open(['url'=>'/dashboard']) !!}
<p> A)  I am a:  {!! Form::radio('ActivityType',null,['class'=>'form-control']) !!} Male
 {!! 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)  My Age is:
{!! Form::number('name', 'value'); !!}
<p> C)  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)  I am better in:</p>
   {!! Form::radio('ActivityType',null,['class'=>'form-control']) !!} Aerobics
 {!! Form::radio('ActivityType',null,['class'=>'form-control']) !!} Anerobic
 {!! 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>
 {!! Form::checkbox('improve','New anerobic routines'); !!} Find new anerobic routines <br>
 {!! Form::checkbox('improve','New aerobic routines'); !!} Find new aerobic routines <br>
 {!! Form::checkbox('improve','Follow'); !!} Follow other users to get inspired <br>
<br><br>
{!! Form::submit('CreateProfile',['class'=>'form-group']) !!}
</div>
{!! Form::close() !!}
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.
@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)  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 :)
Remove the unsigned from goals and remove the duplicated semicolon then share the error please.
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community