Flex

Experience

4,510

0 Best Reply Awards

  • Member Since 1 Year Ago
  • 5 Lessons Completed
  • 0 Favorites

12th December, 2017

Flex started a new conversation How To Show Different Tasks Items According To User Id In Laravel 5.2? • 41 minutes ago

I need show different tasks items in My blade file in the Laravel 5.2 according to the user id. this is My current blade file.

@if (Auth::user()->id)->exists()) 
 @foreach ($project->tasks as $task)
  <ul>
    <li>
  <div>
  <div class="pull-right icons-align">
            <a href="{{url('projects/'.$project->id.'/task/'.$task->id.'/subtask')}}" class="editInline"><i class="glyphicon glyphicon-plus"></i></a>
            </div>
    <h4><i class="fa fa-check-square-o"></i> <span><a href="/projects/{{$project->id}}/tasks/{{ $task->id }}">{{ $task->task_name }}</a>

    </span></h4>
 </div>
 </li>
 </ul>
  <hr>
@endforeach

@else
 @foreach ($project->tasks as $task)
  <ul>
    <li>
  <div>
  <div class="pull-right icons-align">
            <a href="{{url('projects/'.$project->id.'/task/'.$task->id.'/subtask')}}" class="editInline"><i class="glyphicon glyphicon-plus"></i></a>
            <a href="/projects/{{ $project->id }}/tasks/{{ $task->id }}/edit" class="editInline"><i class="glyphicon glyphicon-pencil"></i></a>
            <a href="" class="editInline"><i class="glyphicon glyphicon-trash"></i></a>
        </div>
    <h4><i class="fa fa-check-square-o"></i> <span><a href="/projects/{{$project->id}}/tasks/{{ $task->id }}">{{ $task->task_name }}</a>

    </span></h4>
 </div>
 </li>
 </ul>

  <hr>

this is My task table format

id  task_name  user_id
 1        dfr                  1
 2       bgh                2
 3       hyg                 1
 4       hyu                4

now I need if current logging user id is equel to task table user id display following task files

@foreach ($project->tasks as $task)
  <ul>
    <li>
  <div>
  <div class="pull-right icons-align">
            <a href="{{url('projects/'.$project->id.'/task/'.$task->id.'/subtask')}}" class="editInline"><i class="glyphicon glyphicon-plus"></i></a>
            <a href="/projects/{{ $project->id }}/tasks/{{ $task->id }}/edit" class="editInline"><i class="glyphicon glyphicon-pencil"></i></a>
            <a href="" class="editInline"><i class="glyphicon glyphicon-trash"></i></a>
        </div>
    <h4><i class="fa fa-check-square-o"></i> <span><a href="/projects/{{$project->id}}/tasks/{{ $task->id }}">{{ $task->task_name }}</a>

    </span></h4>
 </div>
 </li>
 </ul>
<hr>
@endforeach

and other task not related to logging user id display with following list

@foreach ($project->tasks as $task)
  <ul>
    <li>
  <div>
  <div class="pull-right icons-align">
            <a href="{{url('projects/'.$project->id.'/task/'.$task->id.'/subtask')}}" class="editInline"><i class="glyphicon glyphicon-plus"></i></a>
            </div>
    <h4><i class="fa fa-check-square-o"></i> <span><a href="/projects/{{$project->id}}/tasks/{{ $task->id }}">{{ $task->task_name }}</a>
</span></h4>
 </div>
 </li>
 </ul>
  <hr>
@endforeach

how can do this?

4th December, 2017

Flex left a reply on How To Display Comments Relavent On Each Task In Laravel 5.2 • 1 week ago

no any idea?

Flex started a new conversation How To Display Comments Relavent On Each Task In Laravel 5.2 • 1 week ago

I am developing project management application using Laravel 5.2. and in My application user can create different projects and one project have multiple tasks. one task may be multiple comments. currently in My app is displaying comments witch are related to each project. (comments displaying for each project not for each task )

see My comments displaying view file.

@foreach ($task->project->comments as $comment)
        <div>
                    <div><i class="fa fa-check-square-o"></i>
                    <span>{{ $comment->comments }} by
                       <span style="font-style: italic;color: #09f;">
                       {{ ($comment->user()->first()->username === auth()->user()->username) ? 'You' : $comment->user()->first()->username }} 
                       </span>
                    </span></div>
                    <a href="/projects/{{ $task->project->id }}/comments/{{ $comment->id }}/edit">Edit</a>
                    <button class="btn btn-danger delete pull-right"
                      data-action="/projects/{{ $task->project->id }}/comments/{{ $comment->id }}"
                      data-token="{{csrf_token()}}">
                    <i class="fa fa-trash-o"></i>Delete
                    </button>
                </div>
                <hr/>
@endforeach

I have task id on each comment in My comment table

id    comments    project_id    task_id
 1         jgh                     1                     1
 2        jgh                     2                    2
 3        jdj                       1                    3

now I need displaying comments on each task. how can I do this?

3rd December, 2017

Flex left a reply on Undefined Variable: Task (View: C:\Users\jone\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 1 week ago

@Snapey @djdiramio @RamjithAp amazing it is working without form.blade.php form action

 <form class="form-vertical" role="form"
                                    enctype="multipart/form-data"
                                    method="post"
                                   action=" ">

            <div class="form-group{{ $errors->has('file_name') ? ' has-error' : '' }}">
                <input type="file" name="file_name" class="form-control" id="file_name">
                @if ($errors->has('file_name'))
                    <span class="help-block">{{ $errors->first('file_name') }}</span>
                @endif
            </div>

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

but I dont know how is it working......can you guess it?

Flex started a new conversation What Is Wrong With This Form Actions In Laravel 5.2 • 1 week ago

I am working with Laravel project in 5.2. in My application I have to attach files and send to file table. in this form action I need send project_id also to the file table.

this is my form action

action=" route('projects.files', 'taskId'=>$task->id)">

my filecontroller is this

 private function saveUploads(Request $request, $fileUrl, $id,$taskId)
    {

     
        $file = new File;
        $file->file_name  = $request->file('file_name')->getClientOriginalName();
        $file->file_url   = $fileUrl;
        $file->project_id = $id;
        $file->task_id = $taskId;
      
        $file->save();
        
    }

but unfortunate in my file table task_id column values always save as following

route('projects.files', 'taskId'=>$task->id)

I need save my task id as 1,2,3,4,5,etc

2nd December, 2017

Flex left a reply on Undefined Variable: Task (View: C:\Users\jone\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 1 week ago

@Snapey did like your comments. it is working but have some problem. that means in my table column task_id save this type values

route('projects.files', 'tasks'=>$task->id)

not save task_id as 1,2,3,....etc

how can solve this problem....

1st December, 2017

Flex left a reply on Undefined Variable: Task (View: C:\Users\jone\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 1 week ago

I change My form action as this

action=" route('projects.files', ['taskId'=>$task->id])">

now did not come undefined variable task error but how now I can send $task->id to Filecontroller method SaveUpload ????

30th November, 2017

Flex left a reply on Undefined Variable: Task (View: C:\Users\jone\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 1 week ago

@RamjithAp now error massage do not display. but My addFiles button do not work. how to configure My addFiles button. this is My new form

 <form class="form-vertical" role="form"
                                    enctype="multipart/form-data"
                                    method="post"
                                    action="Form::open(['route' => ['projects.files', $project->id, $task->id], 'files'=>true]) ">
                <input type="file" name="file_name" class="form-control" id="file_name">
                @if ($errors->has('file_name'))
                    <span class="help-block">{{ $errors->first('file_name') }}</span>
                @endif
            </div>

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

29th November, 2017

Flex left a reply on Undefined Variable: Task (View: C:\Users\jone\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 1 week ago

@RamjithAp @Snapey @divanoli what about your ideas with My comments form and file form

Flex left a reply on Undefined Variable: Task (View: C:\Users\jone\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 1 week ago

Dear all collaborated with this thered see My comment box same to file attachment is is working fine.

comments/form.blade.php

@foreach ($task->project->comments as $comment)

   
    <div>
                    <div><i class="fa fa-check-square-o"></i>
                    <span>{{ $comment->comments }} by
                       <span style="font-style: italic;color: #09f;">
                       {{ ($comment->user()->first()->username === auth()->user()->username) ? 'You' : $comment->user()->first()->username }} 
                       </span>
                    </span></div>
                    <a href="/projects/{{ $task->project->id }}/comments/{{ $comment->id }}/edit">Edit</a>
                    <button class="btn btn-danger delete pull-right"
                      data-action="/projects/{{ $task->project->id }}/comments/{{ $comment->id }}"
                      data-token="{{csrf_token()}}">
                    <i class="fa fa-trash-o"></i>Delete
                    </button>
                </div>
                <hr/>

@endforeach

   
    <form class="form-vertical" role="form" method="post" action="{{ route('projects.comments.create', ['projectId'=> $project->id, 'taskId'=>$task->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>
</div>

CommentController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Auth;
use App\Comment;
use App\Task;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class CommentsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function postNewComment(Request $request, $id, Comment $comment,$taskId)
    {
       $this->validate($request, [
            'comments'     => 'required|min:5',
        ]);

       $comment->comments       = $request->input('comments');
       $comment->project_id     = $id;
       $comment->user_id        = Auth::user()->id;
       $comment->task_id        = $taskId;
       $comment->save();

       return redirect()->back()->with('info', 'Comment posted successfully');
    }
}

routes

Route::post('projects/{projects}/tasks/{tasks}/comments', [
    'uses' => '[email protected]',
    'as'   => 'projects.comments.create',
    'middleware' => ['auth']
]);

and include file tasks/show.blade.php

<h2>{{$task->project->project_name}}</h2>
<hr>

{{$task->task_name}}
<hr>

{!!$task->body!!}

<hr>


@include('comments.form') // this is working fine



@include('files.form')


My comment include file is working fine but problem with file form. can you anybody guess the problem with file form

Flex left a reply on Undefined Variable: Task (View: C:\Users\jone\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 1 week ago

@divanoli it is generated same error here

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

Flex left a reply on Undefined Variable: Task (View: C:\Users\jone\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 1 week ago

@divanoli files/form.blade.php file is include with tasks/show.blade.php file

tasks/show.blade.php

<h2>{{$task->project->project_name}}</h2>
<hr>

{{$task->task_name}}
<hr>

{!!$task->body!!}

<hr>


@include('comments.form')



@include('files.form')


show file view controller is TasksController

public function show($project_id,$task_id)
 {
    $project = Project::find($project_id);
    $task = Task::find($task_id);
  
return view('tasks.show')->withProject($project)->withTask($task);

Flex left a reply on Undefined Variable: Task (View: C:\Users\jone\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 1 week ago

@RamjithAp according to your latest comment again occured this error massage

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

Flex left a reply on Undefined Variable: Task (View: C:\Users\jone\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 1 week ago

@RamjithAp now got this error massage

Missing required parameters for [Route: projects.files] [URI: projects/{project_id}/files/{task_id}].

Flex left a reply on Undefined Variable: Task (View: C:\Users\jone\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 1 week ago

@RamjithAp occurred following error massage

Class 'Form' not found

Flex left a reply on Undefined Variable: Task (View: C:\Users\jone\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 1 week ago

@divanoli when I try to go view file this error massage encounterd

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

Flex left a reply on Undefined Variable: Task (View: C:\Users\jone\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 1 week ago

@divanoli ok sure this is My current route, controller and view files here

files/form.blade.php

  <div class="col-md-5">
    <h4 class="page-header">
        Files
    </h4>
    <div class="row" style="border:1px solid #ccc;margin-left:5px;width:100%;padding:15px;">
     @foreach($project->files as $file)
                <div>
                    <div><i class="fa fa-check-square-o"></i>
                        <span>

                            <a href="{{ $file->file_url }}" target="_blank">{{ $file->file_name }}</a>

                           

    

                        </span>
                    </div>
                </div>
                <hr/>
                @endforeach
          
        <form class="form-vertical" role="form"
                                    enctype="multipart/form-data"
                                    method="post"
                                    action="{{ route('projects.files', ['projectId'=> $project->id, 'taskId'=>$task->id])}}">
            <div class="form-group{{ $errors->has('file_name') ? ' has-error' : '' }}">
                <input type="file" name="file_name" class="form-control" id="file_name">
                @if ($errors->has('file_name'))
                    <span class="help-block">{{ $errors->first('file_name') }}</span>
                @endif
            </div>

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

FilesController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Cloudder;
use App\File as File;
use App\Task;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class FilesController extends Controller
{
    /**
     * Displays the index page of the app
     *
     * @return Response
     */
    public function uploadAttachments(Request $request, $id)
    {
         $this->validate($request, [
            'file_name'     => 'required|mimes:jpeg,bmp,png,pdf|between:1,7000',
        ]);

        $filename     = $request->file('file_name')->getRealPath();

        Cloudder::upload($filename, null);
        list($width, $height) = getimagesize($filename);



        $fileUrl = Cloudder::show(Cloudder::getPublicId(), ["width" => $width, "height" => $height]);
        $this->saveUploads($request, $fileUrl, $id);



        return redirect()->back()->with('info', 'Your Attachment has been uploaded Successfully');
    }

    private function saveUploads(Request $request, $fileUrl, $id,$task)
    {
        $file = new File;
        $file->file_name  = $request->file('file_name')->getClientOriginalName();
        $file->file_url   = $fileUrl;
        $file->project_id = $id;
        $file->task_id = $task;
        //$taskId = Task::find($task_id);
        
        $file->save();
    }



     public function deleteOneProjectFile($fileUrl, $id)
    {
        DB::table('files')
            ->where('file_url', $fileUrl)
            ->where('project_id', $id)
            ->delete();
 
        return redirect()->route('projects.show')->with('info', 'File deleted successfully');
    }


      public function getTasks($id)
     {
         $taskId =  Task::with('project')->get();
         return $taskId;
     }


    
    
}

routes for file attachments

Route::post('projects/{projects}/files', [
     'uses' => '[email protected]',
     'as'   => 'projects.files',
     'middleware' => ['auth']
]);

tasks/show.blade.php

<h2>{{$task->project->project_name}}</h2>
<hr>

{{$task->task_name}}
<hr>

{!!$task->body!!}

<hr>


@include('comments.form')



@include('files.form')


TaskController show methods

 public function show($project_id,$task_id)
 {
    $project = Project::find($project_id);
    $task = Task::find($task_id);

return view('tasks.show')->withProject($project)->withTask($task);

Flex left a reply on Undefined Variable: Task (View: C:\Users\jone\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 1 week ago

@Snapey it is generated following massage

Task {#219 ▼
  #fillable: array:6 [▶]
  #connection: null
  #table: null
  #primaryKey: "id"
  #keyType: "int"
  #perPage: 15
  +incrementing: true
  +timestamps: true
  #attributes: array:9 [▶]
  #original: array:9 [▶]
  #relations: array:1 [▶]
  #hidden: []
  #visible: []
  #appends: []
  #guarded: array:1 [▶]
  #dates: []
  #dateFormat: null
  #casts: []
  #touches: []
  #observables: []
  #with: []
  #morphClass: null
  +exists: true
  +wasRecentlyCreated: false
}

but I can see this massage My files/form.blade.php file action as following

action="{{ route('projects.files', ['projectId'=> $project->id])}}">

without $task variable....

Flex left a reply on Undefined Variable: Task (View: C:\Users\jone\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 1 week ago

@RamjithAp did it but same error here I cannot guess this problem.

Flex left a reply on Undefined Variable: Task (View: C:\Users\jone\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 1 week ago

@RamjithAp witch codes do you need to solve this problem?

consider this when I am going to attach files in the form My local host url is like this way

http://localhost:8000/projects/1/tasks/5

I need submit this task number 5 to the file table. but when I publish $task in the form.blade.php file above error coming and not displaying file attach form. without $task in the blade file My form is displaying correctly. consider My comment adding form is same but it is working without any problem. file attachment form is got this problem. please tell me what codes do you need to solve this problem.

28th November, 2017

Flex left a reply on Undefined Variable: Task (View: C:\Users\jone\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 2 weeks ago

@RamjithAp it is not success for me. please can you say me what is the way to sent $task variable data to the form.blade.php

Flex left a reply on Undefined Variable: Task (View: C:\Users\jone\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 2 weeks ago

it is in TaskController

public function show($id)
  {
          
          
         $project = Project::find($id);
         $task = Task::find($id);
      return view('tasks.show')->withProject($project)->withTask($task);//withComments($comments);
  }

Flex left a reply on Undefined Variable: Task (View: C:\Users\jone\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 2 weeks ago

@RamjithAp I have task folder in My view file and in the task folder I have show.blade.php file this is the show.blade.php file

<h2>{{$task->project->project_name}}</h2>
<hr>

{{$task->task_name}}
<hr>

{!!$task->body!!}

<hr>


@include('comments.form')//this file in comments file in the view folder



@include('files.form') //this file in files folder in the view folder

27th November, 2017

Flex left a reply on Undefined Variable: Task (View: C:\Users\jone\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 2 weeks ago

@Snapey my form.blade.php file is show in task/show.blade.php

<h2>{{$task->project->project_name}}</h2>
<hr>

{{$task->task_name}}
<hr>

{!!$task->body!!}

<hr>


@include('comments.form')



@include('files.form') // this is form.blade.php file in 

Flex left a reply on Undefined Variable: Task (View: C:\Users\jone\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 2 weeks ago

@RamjithAp this is My FileController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Cloudder;
use App\File as File;
use App\Task;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class FilesController extends Controller
{
    /**
     * Displays the index page of the app
     *
     * @return Response
     */
    public function uploadAttachments(Request $request,$id)
    {
       // dd($request->only('id'));

         $this->validate($request, [
            'file_name'     => 'required|mimes:jpeg,bmp,png,pdf|between:1,7000',
        ]);

        $filename     = $request->file('file_name')->getRealPath();

        Cloudder::upload($filename, null);
        list($width, $height) = getimagesize($filename);



        $fileUrl = Cloudder::show(Cloudder::getPublicId(), ["width" => $width, "height" => $height]);
        $this->saveUploads($request, $fileUrl, $id);



        return redirect()->back()->with('info', 'Your Attachment has been uploaded Successfully');
    }

    private function saveUploads(Request $request, $fileUrl, $id,$task)
    {

         //dd($request->only('task'));
        $file = new File;
        $file->file_name  = $request->file('file_name')->getClientOriginalName();
        $file->file_url   = $fileUrl;
        $file->project_id = $id;
        // $file->task_id = $task;
        $file->task_id = $task;//$request->only('task')['task'];
        //$taskId = Task::find($task_id);
        
        $file->save();
    }

     public function deleteOneProjectFile($fileUrl, $id)
    {
        DB::table('files')
            ->where('file_url', $fileUrl)
            ->where('project_id', $id)
            ->delete();
 
        return redirect()->route('projects.show')->with('info', 'File deleted successfully');
    }


      public function getTasks($id)
     {
         $taskId =  Task::with('project')->get();
         return $taskId;
     }


    
    
    
}

26th November, 2017

Flex left a reply on Undefined Variable: Task (View: C:\Users\jone\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 2 weeks ago

@RamjithAp see My controller methods to save file data

private function saveUploads(Request $request, $fileUrl, $id)
    {

         //dd($request->only('task'));
        $file = new File;
        $file->file_name  = $request->file('file_name')->getClientOriginalName();
        $file->file_url   = $fileUrl;
        $file->project_id = $id;
        $file->task_id = $request->only('task')['task'];
        $file->save();
    }

here $id is project_id , and in My form.blade.php file when I print {{$task->id}} it is printing correct task id also. but I cant understand how can I pass $task to the form.blade.php file...do you have any idea here....

Flex left a reply on Undefined Variable: Task (View: C:\Users\jone\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 2 weeks ago

@Snapey actually what is the way to pass $task to the form? I did everything what I know?

Flex started a new conversation Undefined Variable: Task (View: C:\Users\jone\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 2 weeks ago

I am going to submit file in My Laravel application. this is My fileController

private function saveUploads(Request $request, $fileUrl, $id)
    {

         //dd($request->only('task'));
        $file = new File;
        $file->file_name  = $request->file('file_name')->getClientOriginalName();
        $file->file_url   = $fileUrl;
        $file->project_id = $id;
        $file->task_id = $request->only('task')['task'];
        $file->save();
    }

and this is form.blade.php form acctions

action="{{ route('projects.files', ['project'=> $project->id, 'task'=>$task->id])}}">
            <div class="form-group{{ $errors->has('file_name') ? ' has-error' : '' }}">  //this is line line 39

and route

Route::post('projects/{projects}/files', [
     'uses' => '[email protected]',
     'as'   => 'projects.files',
     'middleware' => ['auth']
]);

but got following error

ErrorException in 88ff5154a46f749c29024e0c9f84c577f7c5025e.php line 39: Undefined variable: task (View: C:\Users\john\Desktop\ddd\resources\views\files\form.blade.php)

how can I fix this problem?

12th November, 2017

Flex left a reply on How To Fix Undefined Variable: Task (View: C:\Users\LIlan\Desktop\acxian\resources\views\files\form.blade.php) In Laravel 5.2 • 1 month ago

@jalawes actually I have not create method in My controller. any way did your comments and occurred following error.

Undefined variable: taskId (View: C:\Users\Nalaka\Desktop\acxian\resources\views\files\form.blade.php)

Flex started a new conversation How To Fix Undefined Variable: Task (View: C:\Users\LIlan\Desktop\acxian\resources\views\files\form.blade.php) In Laravel 5.2 [duplicate] • 1 month ago

I am developing project management tool in laravel 5.2. In my application user can create a project and one project has many tasks and one task may have many files attachments. I am using cloudder to save My files. Currently I have assigned My project files to relevant projects only. Now, I need to display the files on each tasks of the relevant projects.

FileController

class FilesController extends Controller
    {

        public function uploadAttachments(Request $request, $id,$taskId) 
        {
             $this->validate($request, [
                'file_name'     => 'required|mimes:jpeg,bmp,png,pdf|between:1,7000',
            ]);

            $filename     = $request->file('file_name')->getRealPath();

            Cloudder::upload($filename, null);
            list($width, $height) = getimagesize($filename);

            $fileUrl = Cloudder::show(Cloudder::getPublicId(), ["width" => $width, "height" => $height]);
            $this->saveUploads($request, $fileUrl, $id,$taskId);

            return redirect()->back()->with('info', 'Your Attachment has been uploaded Successfully');
        }

        private function saveUploads(Request $request, $fileUrl, $id,$taskId)
        {
            $file = new File;
            $file->file_name  = $request->file('file_name')->getClientOriginalName();
            $file->file_url   = $fileUrl;
            $file->project_id = $id;
            $file->task_id = $taskId;

            $file->save();
        }

        return redirect()->route('projects.show')->with('info', 'File deleted successfully');
        }
    }

routes

Route::post('projects/{projects}/tasks/{tasks}/files', [
     'uses' => '[email protected]',
     'as'   => 'projects.files',
     'middleware' => ['auth']
]);

and file form is files/form.blade.php

<div class="row" style="border:1px solid #ccc;margin-left:5px;width:100%;padding:15px;">
     @foreach($project->files as $file)
                <div>
                    <div><i class="fa fa-check-square-o"></i>
                        <span>

                            <a href="{{ $file->file_url }}" target="_blank">{{ $file->file_name }}</a>
                  </span>
                    </div>
                </div>
                <hr/>
                @endforeach

        <form class="form-vertical" role="form"
                                    enctype="multipart/form-data"
                                    method="post"
                                    action="{{ route('projects.files', ['projectId'=> $project->id, 'taskId'=>$task->id])}}">//this is line 39
            <div class="form-group{{ $errors->has('file_name') ? ' has-error' : '' }}">
                <input type="file" name="file_name" class="form-control" id="file_name">
                @if ($errors->has('file_name'))
                    <span class="help-block">{{ $errors->first('file_name') }}</span>
                @endif
            </div>

            <div class="form-group">
                <button type="submit" class="btn btn-info">Add Files</button>
            </div>

now I got this error

ErrorException in 88ff5154a46f749c29024e0c9f84c577f7c5025e.php line 39: Undefined variable: task (View: C:\Users\Lilan\Desktop\acxian\resources\views\files\form.blade.php)

how to fix this problem?

Flex left a reply on How Can I Enter Task_id To The File Table In Laravel 5.2 • 1 month ago

any idea?

Flex started a new conversation How Can I Enter Task_id To The File Table In Laravel 5.2 • 1 month ago

I am developing project management tool in laravel 5.2. in my application user can create a project and one project have many tasks and one task may have many files attachments. I am using cloudder to save My files. currently I have assign My project files to relevant projects only.

FileController

class FilesController extends Controller
    {

        public function uploadAttachments(Request $request, $id)
        {
             $this->validate($request, [
                'file_name'     => 'required|mimes:jpeg,bmp,png,pdf|between:1,7000',
            ]);

            $filename     = $request->file('file_name')->getRealPath();

            Cloudder::upload($filename, null);
            list($width, $height) = getimagesize($filename);

            $fileUrl = Cloudder::show(Cloudder::getPublicId(), ["width" => $width, "height" => $height]);
            $this->saveUploads($request, $fileUrl, $id);

            return redirect()->back()->with('info', 'Your Attachment has been uploaded Successfully');
        }

        private function saveUploads(Request $request, $fileUrl, $id)
        {
            $file = new File;
            $file->file_name  = $request->file('file_name')->getClientOriginalName();
            $file->file_url   = $fileUrl;
            $file->project_id = $id;

            $file->save();
        }

        return redirect()->route('projects.show')->with('info', 'File deleted successfully');
        }
    }

routes

Route::post('projects/{projects}/files', [
     'uses' => '[email protected]',
     'as'   => 'projects.files',
     'middleware' => ['auth']
]); 

and file form is files/form.blade.php

 <div class="row" style="border:1px solid #ccc;margin-left:5px;width:100%;padding:15px;">
     @foreach($project->files as $file)
                <div>
                    <div><i class="fa fa-check-square-o"></i>
                        <span>

                            <a href="{{ $file->file_url }}" target="_blank">{{ $file->file_name }}</a>
                  </span>
                    </div>
                </div>
                <hr/>
                @endforeach

        <form class="form-vertical" role="form"
                                    enctype="multipart/form-data"
                                    method="post"
                                    action="{{ route('projects.files', ['projects' => $project->id]) }}">
            <div class="form-group{{ $errors->has('file_name') ? ' has-error' : '' }}">
                <input type="file" name="file_name" class="form-control" id="file_name">
                @if ($errors->has('file_name'))
                    <span class="help-block">{{ $errors->first('file_name') }}</span>
                @endif
            </div>

            <div class="form-group">
                <button type="submit" class="btn btn-info">Add Files</button>
            </div>

now I need display files on each tasks to relevent projects. how can I do this?

11th November, 2017

Flex left a reply on How Can I Enter Task_id In To The Comment Table In Laravel 5.2 • 1 month ago

this is My comments/form.blade.php

<h4 class="page-header">
    Comments
</h4>
<div class="row" style="margin-left:5px;padding:5px;">
     <[email protected](isset($comments))
           @foreach($comments as $comment)
                <div>
                    <div><i class="fa fa-check-square-o"></i>
                    <span>{{ $comment->comments }} by
                       <span style="font-style: italic;color: #09f;">
                       {{ ($comment->user()->first()->username === auth()->user()->username) ? 'You' : $comment->user()->first()->username }} 
                       </span>
                    </span></div>
                    <a href="/projects/{{ $project->id }}/comments/{{ $comment->id }}/edit">Edit</a>
                    <button class="btn btn-danger delete pull-right"
                      data-action="/projects/{{ $project->id }}/comments/{{ $comment->id }}"
                      data-token="{{csrf_token()}}">
                    <i class="fa fa-trash-o"></i>Delete
                    </button>
                </div>
                <hr/>

           @endforeach
    @endif -->
@foreach ($task->project->comments as $comment)

   
    <div>
                    <div><i class="fa fa-check-square-o"></i>
                    <span>{{ $comment->comments }} by
                       <span style="font-style: italic;color: #09f;">
                       {{ ($comment->user()->first()->username === auth()->user()->username) ? 'You' : $comment->user()->first()->username }} 
                       </span>
                    </span></div>
                    <a href="/projects/{{ $task->project->id }}/comments/{{ $comment->id }}/edit">Edit</a>
                    <button class="btn btn-danger delete pull-right"
                      data-action="/projects/{{ $task->project->id }}/comments/{{ $comment->id }}"
                      data-token="{{csrf_token()}}">
                    <i class="fa fa-trash-o"></i>Delete
                    </button>
                </div>
                <hr/>

@endforeach

   
    <form class="form-vertical" role="form" method="post" action="{{ route('projects.comments.create', $task->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>
</div>

Flex left a reply on How Can I Enter Task_id In To The Comment Table In Laravel 5.2 • 1 month ago

do you have any idea about this?

Flex started a new conversation How Can I Enter Task_id In To The Comment Table In Laravel 5.2 • 1 month ago

hellow, I am developing web based project management system in Laravel 5.2 and in my application one project has many tasks and one task have many comments. now I need add relevent task id when user enter some comment to the comment table

CommentsController

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');
    }

site url is when going to enter some comments on each task is

http://localhost:8000/projects/2/tasks/31

and My existing comments table structure is

id   comments   project_id    user_id
 1       fgt                     1                    1
 2      hgyt                  1                    2
 3      jfu                     2                    1

My routes is

Route::post('projects/{projects}/comments', [
    'uses' => '[email protected]',
    'as'   => 'projects.comments.create',
    'middleware' => ['auth']
]);

how can I enter task id to the comment table?

5th November, 2017

Flex left a reply on How To Filter TaskId Regarding To Each ProjectId • 1 month ago

@RamjithAp Excellent it is working fine thanks a lot.....

Flex left a reply on How To Filter TaskId Regarding To Each ProjectId • 1 month ago

@RamjithAp did it but same error here.. actually My problem is not in index.blade.php it is in TaskController.php

Flex started a new conversation How To Filter TaskId Regarding To Each ProjectId • 1 month ago

in My laravel 5.2 application I need print each tasks name in show.blade.php file in tasks folder tasks/show.blade.php

<h2>{{$task->project->project_name}}</h2>
<hr>
{{$task->task_name}}
<hr>


@include('comments.form')

@include('files.form')

this is My taskController show method

public function show($id)
 {
    $project = Project::find($id);
    $task = Task::find($id);
    $files = $this->getFiles($id);
return view('tasks.show')->withProject($project)->withFiles($files)->withTask($task);
 }

My task table like this way

id  task_name  project_id
 1      jui                  1
 2     kiu                 2
 3     hyu                1  

but my problem is when I print

{{$task->task_name}}

I need print each task details when I click on each task name on index.blade.php in task folder

index.blade.php

@foreach ($project->tasks as $task)
  <h4><i class="fa fa-check-square-o"></i> <span><a href="/projects/{{$project->id}}/tasks/{{ $task->id }}">{{ $task->task_name }}</a>
@endforeach

here it is always displaying task id no 1 task name only. how can fix this problem?

3rd November, 2017

Flex left a reply on How To Fix Non-static Method App\Task::project() Should Not Be Called Statically, Assuming $this From Incompatible Context • 1 month ago

@tisuchi now got this error

FatalErrorException in Task.php line 26: Using $this when not in object context
public static function project()
     {
         return $this->belongsTo('App\Project'); //this is line 26
     }

Flex left a reply on How To Fix Non-static Method App\Task::project() Should Not Be Called Statically, Assuming $this From Incompatible Context • 1 month ago

@tisuchi did as your comment to Task Model

public static function project()
     {
         return $this->belongsTo('App\Project');
     }

but not clear what should do after this change please can you comment again

Flex started a new conversation How To Fix Non-static Method App\Task::project() Should Not Be Called Statically, Assuming $this From Incompatible Context • 1 month ago

in my laravel application got following errors

ProjectController.php line 94:
Non-static method App\Task::project() should not be called statically, assuming $this from incompatible context

this is projectController

 public function show($id)
  {
         $project = Project::find($id);
         $task = $this->getTasks($id);
         $files = $this->getFiles($id);
        
          
         return view('projects.show')->withProject($project)->withFiles($files)->withTasks($task);
  }

  public function getTasks($id)
    {
        $task =  Task::project($id)->get(); // this is line 94
        return $task;
    }

Task Model is

<?php

namespace App;

use App\User;
use App\Auth;
use App\Project;


use Illuminate\Database\Eloquent\Model;

class Task extends Model
{
     protected $fillable = ['task_name', 'body', 'assign','priority','duedate','project_id'];



      public function scopeProject($query, $id)
    {
        return $query->where('project_id', $id);
    }


     public function project()
     {
         return $this->belongsTo('App\Project');
     }

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

    public function subtasks(){
    return $this->hasMany(Subtask::class);
}

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




    
    
    //
}

Project Model

<?php

namespace App;
use Auth;
use App\Task;
use App\Comment;

use Illuminate\Database\Eloquent\Model;

class Project extends Model
{
    protected $fillable = ['project_name','project_notes','project_status','color','group'];
    //

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

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

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




}

how can fix this problem

30th October, 2017

Flex left a reply on How To Fix Undefined Variable: Task (View: C:\Users\Lilan\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 1 month ago

see My @include('comments.form') in same blede file is working properly, but only @include('files.form') is occurred this error

see tasks/show.blade.php

<h2>{{$task->project->project_name}}</h2>
<hr>

{{$task->task_name}}
<hr>

{!!$task->body!!}

<hr>


@include('comments.form') //this is working fine



@include ('files.form') // problem with this


comments/form.blade.php

@foreach ($task->project->comments as $comment)

   
    <div>
                    <div><i class="fa fa-check-square-o"></i>
                    <span>{{ $comment->comments }} by
                       <span style="font-style: italic;color: #09f;">
                       {{ ($comment->user()->first()->username === auth()->user()->username) ? 'You' : $comment->user()->first()->username }} 
                       </span>
                    </span></div>
                    <a href="/projects/{{ $task->project->id }}/comments/{{ $comment->id }}/edit">Edit</a>
                    <button class="btn btn-danger delete pull-right"
                      data-action="/projects/{{ $task->project->id }}/comments/{{ $comment->id }}"
                      data-token="{{csrf_token()}}">
                    <i class="fa fa-trash-o"></i>Delete
                    </button>
                </div>
                <hr/>

@endforeach

   
    <form class="form-vertical" role="form" method="post" action="{{ route('projects.comments.create', $task->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>
</div>

and relationship with comments and project

Project Model

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

Comment Model

 public function project()
    {
        return $this->belongsTo('App\Project');
    }

do you have any idea to solve this problem I am using Laravel 5.2

29th October, 2017

Flex left a reply on How To Fix Undefined Variable: Task (View: C:\Users\Lilan\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 1 month ago

@Carban yes please see My files/form.blade.php it is using foreach did you mean it?

Flex left a reply on How To Fix Undefined Variable: Task (View: C:\Users\Lilan\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 1 month ago

I did not use Controller to include(files.form) as My another include files....

Flex left a reply on How To Fix Undefined Variable: Task (View: C:\Users\Lilan\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 1 month ago

@crnkovic this is My FileController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Cloudder;
use App\File as File;
use App\Task;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class FilesController extends Controller
{
    /**
     * Displays the index page of the app
     *
     * @return Response
     */
    public function uploadAttachments(Request $request, $id)
    {
         $this->validate($request, [
            'file_name'     => 'required|mimes:jpeg,bmp,png,pdf|between:1,7000',
        ]);

        $filename     = $request->file('file_name')->getRealPath();

        Cloudder::upload($filename, null);
        list($width, $height) = getimagesize($filename);

        $fileUrl = Cloudder::show(Cloudder::getPublicId(), ["width" => $width, "height" => $height]);
        $this->saveUploads($request, $fileUrl, $id);

        return redirect()->back()->with('info', 'Your Attachment has been uploaded Successfully');
    }

    private function saveUploads(Request $request, $fileUrl, $id)
    {
        $file = new File;
        $file->file_name  = $request->file('file_name')->getClientOriginalName();
        $file->file_url   = $fileUrl;
        $file->project_id = $id;
       // $file->task_id = $taskId;
        $file->save();
    }

     public function deleteOneProjectFile($fileUrl, $id)
    {
        DB::table('files')
            ->where('file_url', $fileUrl)
            ->where('project_id', $id)
            ->delete();
 
        return redirect()->route('projects.show')->with('info', 'File deleted successfully');
    }


    
    
}

Flex started a new conversation How To Fix Undefined Variable: Task (View: C:\Users\Lilan\Desktop\ddd\resources\views\files\form.blade.php) In Laravel • 1 month ago

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="{{ $file->file_url }}" target="_blank">{{ $file->file_name }}</a>
</span>
                    </div>
                </div>
                <hr/>
                @endforeach

        <form class="form-vertical" role="form"
                                    enctype="multipart/form-data"
                                    method="post"
                                    action="{{ route('projects.files', ['projects' => $project->id]) }}">
            <div class="form-group{{ $errors->has('file_name') ? ' has-error' : '' }}">
                <input type="file" name="file_name" class="form-control" id="file_name">
                @if ($errors->has('file_name'))
                    <span class="help-block">{{ $errors->first('file_name') }}</span>
                @endif
            </div>

            <div class="form-group">
                <button type="submit" class="btn btn-info">Add Files</button>
            </div>
            <input type="hidden" name="_token" value="{{ csrf_token() }}">
        </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>{{ $task->project->project_name }}</h2>
<hr>

{{$task->task_name}}
<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?

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.