I need print My project name and task name on subtask blade file. My problem is this, I have project management app and its contain projects and one project have many tasks and one task have many subtasks. this is my relationship between task and subtasks task model
Task Model
public function subtasks(){
return $this->hasMany(Subtask::class);
}
Subtask model
public function task(){
return $this->belongsTo(Task::class);
}
and my subtask data input file is :
subtask/form.blade.php
<h4>Add Sub Task</h4>
<form class="form-vertical" role="form" method="post" action="">
<div class="form-group">
<input type="text" name="task_name" class="form-control" id="name" value="">
@if ($errors->has('task_name'))
<span class="help-block"></span>
@endif
</div>
<div class="form-group">
<button type="submit" class="btn btn-info">Create Task</button>
</div>
<input type="hidden" name="_token" value="">
</form>
this is my subtaskcontroller
public function store(Request $request,$projectId,$taskId)
{
$subtask = new Subtask;
$subtask->subtask_name = $request->input('task_name');
$subtask->task_id = $taskId;
$subtask->project_id = $projectId;
$subtask->save();
//
}
I need print My project name and task name on the subtask.blade.php how can I do this? Edited please see my controller show
public function show($id)
{
$task = $subtask->task;
$project = $task->project;
return view('subtasks.form', ['subtask' => $subtask, 'task' => $task, 'project => $project]);
//
}
how should I replase show($id) here
Edited subtask store method
public function store(Request $request,$projectId,$taskId)
{
$subtask = new Subtask;
$subtask->subtask_name = $request->input('task_name');
$subtask->task_id = $taskId;
$subtask->project_id = $projectId;
$subtask->save();
//
}
subtask show method
public function show($id)
{
$subtask = Subtask::findOrFail($id);
$task = $subtask->task;
$project = $task->project;
return view('subtasks.form', ['subtask' => $subtask, 'task' => $task, 'project => $project]);
//
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire