LARAVEL – How do you add a project ID to a new task using Eloquent relationships
I was wondering if someone could kindly help me. To briefly describe how my website is set up, a User->hasMany Projects, a Project->hasMany Experiements and Experiements -> hasMany Tasks. I am referng to them as experiments but this is baisically just projects-tasks-subtasks.
my relationships are successfully set up and i can create a new project that links to a user using user_id. Once I try to create a new experimnent it successfully creates howeever it does not pass the project_id to the database and returns a value of NULL for the project_id.
My Experiments controller:
$experiments = new experiment;
$experiments->title = $request->input('title');
$experiments->hypothesis = $request->input('hypothesis');
$experiments->duedate = $request->input('duedate');
$experiments->project_id = $request->input('project_id');
$project->experiements()->save($experiments);
return redirect('/projects')->with('success', 'post created');
My create experiment.blade.php:
{!! Form::open(['action' => 'ExperimentsController@store', $project->id, 'method' => 'POST', 'enctype' => 'multipart/form-data']) !!}
<div class="form-group">
</div>
<div class="form-group">
</div>
<div class="form-group">
</div>
<div class="form-group">
</div>
</div>
<div class="modal-footer">
{!! Form::close() !!}
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<div class="success margin-top-20">
How do you pass the project_id through when you create a new experiment so that a list of experiments will show for that specific project? Any help on this would be greatley appreciated and apologies if I am unclear I would be happy to elaborate on any points.
Thanks so much
from Laravel Questions and Answers https://laravelquestions.com/laravel/laravel-how-do-you-add-a-project-id-to-a-new-task-using-eloquent-relationships/
via Lzo Media
No comments:
Post a Comment