1 month ago

Master Detail Form with Just two tables

Posted 1 month ago by noblemfd

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

  1. Goals

  2. KPI

  3. Goal Types



protected $fillable = [

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


protected $fillable = [


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

Goal Type

protected $fillable = [

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

Please sign in or create an account to participate in this conversation.