我正在開發Laravel應用程序,我需要爲我的每個任務文件添加註釋表單,以便與每個項目相關。 這是評論/ form.blade.php如何在Laravel 5.2中包含刀片文件
<form class="form-vertical" role="form" method="post" action="{{ route('projects.comments.create', $project->id) }}">
<div class="form-group{{ $errors->has('comments') ? ' has-error' : '' }}">
<textarea name="comments" class="form-control" style="width:80%;" id="comment" rows="5" cols="5"></textarea>
@if ($errors->has('comments'))
<span class="help-block">{{ $errors->first('comments') }}</span>
@endif
</div>
<div class="form-group">
<button type="submit" class="btn btn-info">Add Comment</button>
</div>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
我要包括這種形式的文件,以在show.blade.php任務文件夾文件中查看文件。 這是show.blade.php
<h2>{{ $tasks->project->project_name }}</h2>
<hr>
{{$tasks->task_name}}
<hr>
{!!$tasks->body!!}
<hr>
@include('comments.form')
commentController.php
public function postNewComment(Request $request, $id, Comment $comment)
{
$this->validate($request, [
'comments' => 'required|min:5',
]);
$comment->comments = $request->input('comments');
$comment->project_id = $id;
$comment->user_id = Auth::user()->id;
$comment->save();
return redirect()->back()->with('info', 'Comment posted successfully');
}
routes.php文件
Route::post('projects/{projects}/comments', [
'uses' => '[email protected]',
'as' => 'projects.comments.create',
'middleware' => ['auth']
]);
但最後得到這個錯誤按摩
Undefined variable: project (View: C:\Users\Nalaka\Desktop\acxian\resources\views\comments\form.blade.php)
怎麼能解決這個問題LEM?
你以前一定'$ project'包括'form.blade' – C2486
嘗試改變'$項目 - >向id''$任務 - >項目 - > ID ' –