drmticpet66231422 2017-09-09 06:56
浏览 19
已采纳

如何在Laravel 5.2中包含刀片文件

I am developing Laravel application and I need add comment form to My each task file regarding to each project. this is comments/form.blade.php

 <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>

I am going to include this form file to show.blade.php file in tasks folder in view file. this is 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' => 'CommentsController@postNewComment',
    'as'   => 'projects.comments.create',
    'middleware' => ['auth']
]);

but finally got this error massage

Undefined variable: project (View: C:\Users\Nalaka\Desktop\acxianesources\views\comments\form.blade.php)

how can fix this problem?

  • 写回答

1条回答 默认 最新

  • doutongfu9484 2017-09-09 07:04
    关注

    You have not defined $project anywhere but you have $tasks from which you are getting project name already in show.blade.php so if you have project id also there in $tasks->project data then you can use this variable in view change form tag in comments/form.blade.php as below:

    <form class="form-vertical" role="form" method="post" action="{{ route('projects.comments.create', $tasks->project->id) }}">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答