dimanche 29 octobre 2017

how to include (file.form) blade.php file with another blade file in laravel

in my laravel project management application I have project and one project can create many tasks and one task have publish many files regarding to the task. so, in my file attachment form is this in files folder in view file

files/form.blade.php

@foreach ($task->project->files as $file)
                <div>
                    <div><i class="fa fa-check-square-o"></i>
                        <span>

                            <a href="" target="_blank"></a>
</span>
                    </div>
                </div>
                <hr/>
                @endforeach

        <form class="form-vertical" role="form"
                                    enctype="multipart/form-data"
                                    method="post"
                                    action="">
            <div class="form-group">
                <input type="file" name="file_name" class="form-control" id="file_name">
                @if ($errors->has('file_name'))
                    <span class="help-block"></span>
                @endif
            </div>

            <div class="form-group">
                <button type="submit" class="btn btn-info">Add Files</button>
            </div>
            <input type="hidden" name="_token" value="">
        </form>

and file model relationship with Task model is this

public function task(){
    return $this->belongsTo(Task::class);
}

Task model relationship with File model is this

public function files(){
    return $this->hasMany('App\File');
}

and now I included files/form.blade.php file with tasks/show.blade.php file as this

tasks/show.blade.php

<h2></h2>
<hr>


<hr>

{!!$task->body!!}

<hr>
@include('files.form')

then when I try to view task/show.blade.php file this following error is coming

Undefined variable: task (View: C:\Users\Lilan\Desktop\ddd\resources\views\files\form.blade.php)

how can fix this problem?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire