jeudi 14 septembre 2017

How to create a survey template

Basically I have 3 tables: Survey, Questions, and Answers. I'm trying to decipher a way to create survey templates that can be re-used. Basically, user would go in, create a new survey name and description, and have the option to select 1 of 3 question templates, template 1, template 2, or create your own survey from scratch.

The issue is, I have no idea where to even start with this process. I'm new to Laravel and looking for some guidance. Please forgive me if this is something in the docs I've missed.

Here is my current create function in my Survey Controller, and my Model

public function create(Request $request, Survey $survey)
{
    $arr = $request->all();
    $arr['user_id'] = Auth::id();
    $surveyItem = $survey->create($arr);
    return Redirect::to("/survey/{$surveyItem->id}");
}

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Survey extends Model
{
    protected $fillable = ['title', 'description', 'user_id'];
    protected $dates = ['deleted_at'];
    protected $table = 'surveys';

    public function questions(){
        return $this->hasMany(Question::class);
    }

    public function user(){
        return $this->belongsTo(User::class);
    }

    public function answers(){
        return $this->hasMany(Answer::class);
    }


}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire