Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

noblemfd's avatar

Master Detail Form with Just two tables

I am developing an appraisal management system using Master Detail Form with just three tables:

  1. Goals

  2. KPI

  3. Goal Types

Models

Goal

protected $fillable = [
    'goal_name',
    'goal_description',
];

public function goalType()
{
    return $this->belongsTo('App\Models\GoalType','goal_type_id');
}

KPI

protected $fillable = [
'goal_id
    'goal_type_id',
    'kpi_description',
];

GoalController

public function create()
{
    $goaltypes = GoalType::all();
    return view('goals.create');
}

Goal Type

protected $fillable = [
              'goal_type_name'
          ];

public function store(StoreGoalRequest $request)
{
    
    $goaltype = GoalType::create([
        'goal_name'                 => $request->goal_name,
         'goal_description'         => $request->goal_description,
        'created_by'                => Auth::user()->id,
        'created_at'                => date("Y-m-d H:i:s"),
        'is_active'                 => 1,
    ]);
    Session::flash('success', 'Appraisal Goal is created successfully');
    return redirect()->route('goals.index');
}

One Goal will have many KPI. The goal_name, goal_type_name and goal_description are entered only once at an instance. goal_type_name is a dropdown derived from goal_type_id.

I want to create a master detail form, whereby there will be a add button that will add kpi_description (text box) several times.

When save button is clicked:

  1. goal_name and goal_description will be saved in goals table

  2. goal_type_id from the dropdown, goal_id from goals table and kpi_description will be saved in the kpi table

  3. nothing is saved in goal_type table. It only supplies the goal_type_id and goal_type_name for the dropdown

  4. goals table is the main controller.

How do I modify my model and controller, and also write my view to achieve this?

Thank you

0 likes
2 replies
bobbybouwmann's avatar

This is like asking us to build your application.

What have you tried so far? What part is not working for you? We can all type it out here, but you won't learn anything from, let alone understand it.

Sinnbeck's avatar

Also it would be a good idea to break down the task into sub tasks, and the you when you get stuck on a part you can ask.

This is like asking "How do I build my own car from scratch?". Instead you start by finding out how the engine works, then the how to form the chassis and so on.

So something like

  1. Add test data to the database and get it show as expected
  2. Find out how to dynamically add a text box to a form (hint: javascript eg. jquery) ...and so on

Please or to participate in this conversation.