私は、次のモデルの関係および渡すオブジェクトが
Poll
id | name
--------------
1 | Poll One
PollQuestion
id | poll_id | question
-------------------------
1 | 1 | Something
PollAnswer
id | question_id | answer
-------------------------------
1 | 1 | Answer 1
-------------------------------
2 | 1 | Answer 2
-------------------------------
3 | 1 | Answer 3
Aポールのようなデータベース設計が一つPollQuestionを持つことができる持っている、とPollQuestionは多くのPollAnswer年代を持つことができます。
これはすべて正常に動作し、私は投票、質問と回答を作成できます。これはすべてバックエンド内で行われ、管理者としてログインする必要があります。
フロントエンドでは、投票質問と可能な回答を表示する必要があります。 PollResponseモデルを設定して、Pollが多くのPollResponseを持つことができるようにしました。モデルは、私はその後、私のルートは、この次
Route::group(['middleware' => ['web']], function() {
Route::model('polls.response', 'PollResponse');
Route::resource('/', 'PollResponseController', ['except' => ['create', 'show', 'edit', 'update', 'destroy']]);
Route::group(['middleware' => ['admin_logged', 'can_see']], function()
{
Route::model('polls', 'Poll');
Route::bind('polls', function($value, $route) {
return App\Poll::whereId($value)->first();
});
Route::resource('admin/polls', 'PollController');
Route::model('polls.questions', 'PollQuestion');
Route::resource('polls.questions', 'PollQuestionController', ['except' => ['index', 'create', 'show', 'edit', 'destroy']]);
});
});
のように設定している。この
class Poll extends Model
{
public function pollQuestion()
{
return $this->hasOne('App\PollQuestion', 'poll_id');
}
public function pollResponse()
{
return $this->hasMany('App\PollResponse', 'poll_id');
}
}
class PollResponse extends Model
{
public function poll()
{
return $this->belongsTo('App\Poll');
}
}
のようなものになりそうなアイデアは、通常のユーザがメインのドメインを訪問し、その備えた最新の世論調査の質問を見ることができる、です可能な答え。彼らは答えを と選択し、回答を提出します。これは次のようなものです
<div class="panel-heading">
<h3 class="panel-title"> {{ $question->question }}</h3>
</div>
<div class="panel-body">
{!! Form::model(new App\PollResponse, ['route' => ['store', $poll->id]]) !!}
@if (count($answers) !== 0)
@foreach($answers as $key => $value)
<div class="radio">
<label>
<input type="radio" name="optionsRadios" value="{{ $value->answer }}"> {{ $value->answer }}
</label>
</div>
@endforeach
@endif
{!! Form::submit('Save', array("class"=>"btn btn-info pull-right ")) !!}
{!! Form::close() !!}
</div>
これはすべて正常に動作します。私は、私のPollResponseController内でストア機能に問題があります。私が応答を提出すると、 poll_idがルート内で定義されたURLに追加されます。しかし、店舗機能で、私は現在、私は出力電流ポーリングオブジェクトにこれを期待
public function store(Request $request, Poll $poll)
{
dd($poll);
}
をしていますが、それは現在空ポーリングオブジェクトを出力しています。どのようにして関連するPoll オブジェクトをこの関数に入れて、特定のPollに応答を関連付けることができますか?私はそれがあるため、この行のだ賭ける
おかげ