Flex

Experience

5,030

0 Best Reply Awards

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

28th December, 2017

Flex left a reply on How To Show Project Name In Limited Characters In Laravel? • 1 month ago

how can I add some ....... to the end of the project name ? did some thing via https://laravel.com/docs/5.5/helpers#method-str-limit but not success?

Flex started a new conversation How To Show Project Name In Limited Characters In Laravel? • 1 month ago

I need show My laravel application project name with limited characters. that means as an example consider some project name contains more than 10 letters, then I need only show 10 characters.

My project name create controller is

public function store(Request $request)
    {
        $this->validate($request, [
            'name'     => 'required|min:3',
            'notes'    => 'required|min:10',
            'color'    => 'required',
            'group'    => 'required',
            'status'   => 'required'
        ]);

        $project = new Project;
        $project->project_name   = $request->input('name');
        $project->project_status = $request->input('status');
        $project->group          = $request->input('group');
        $project->color          = $request->input('color');
        $project->project_notes  = $request->input('notes');
        $project->user_id        = Auth::user()->id;

        $duplicate = Project::where('project_name',$project->project_name)->first();
        if($duplicate)
        {
            return redirect()->route('projects.index')->with('warning','Title already exists');
        }   

        $project->save();
        return redirect()->route('projects.index')->with('info','Your Project has been created successfully');

and project name showing blade file is

<div class="row">
             @foreach ($projects as $proj)
               <div class="col-md-3" style="border:3px solid {!!$proj->color!!};margin-left:5px;margin-bottom: 5px;">
               <h2><a href="/projects/{{ $proj->id }}">{!! $proj->project_name !!}</a></h2>

then how can I show only 10 charactors in My blade file?

Flex left a reply on How To Validate Input Box With Numbers And One Letter In Laravel? • 1 month ago

@Cronix your comments is working 100%

27th December, 2017

Flex left a reply on How To Validate Input Box With Numbers And One Letter In Laravel? • 1 month ago

use this but got this error

preg_match(): No ending delimiter '^' found

Flex left a reply on How To Validate Input Box With Numbers And One Letter In Laravel? • 1 month ago

do you have an idea?

Flex started a new conversation How To Validate Input Box With Numbers And One Letter In Laravel? • 1 month ago

I need validate nic input box values with nine number and at the end V letter

ex-:895632145V

protected function validator(array $data)
    {
        return Validator::make($data, [
            'username' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|min:6|confirmed',
            'nic' => 'required|min:10',
            ]);
    }

how can do this?

24th December, 2017

Flex started a new conversation Why Did't Highlight Collaborator Link In My Menu Sidebar In Laravel? • 2 months ago

using this sidebar menu in my laravel application. it is normally highlighted when visit current menu link. but when I click Collaborators link it is not highlight sidebar

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<style>
 .nav-sidebar li.active{
  /*your css code here*/
 }
</style>
<div class="col-sm-3 col-md-2 sidebar">
    <ul class="nav nav-sidebar">
        <li style="margin-left:20px;">
            {{--<img src="{{ Auth::user()->getAvatarUrl() }}" height="50" width="50" style="border-radius:25px;" />--}}
        </li>
        <li><a href="#"> @ {{ Auth::user()->name }}</a></li>
        <li><a href="#">PREGO<span class="sr-only">(current)</span></a></li>
        <li><a href="#">Edit Account</a></li>
        <li><a href="{{ route('projects.index') }}">Projects</a></li>
        <li><a href="{{ route('collaborators.form', $project)}}">Collaborators</a></li>
        <li><a href="#">Todos</a></li>
    </ul>
</div>
<script>

   $('.nav-sidebar').on('click','li', function(){
    $(this).addClass('active').siblings().removeClass('active');
  });
</script>

I need highlight when click collaborator link as other link. how can do this?

23rd December, 2017

Flex started a new conversation Asdafefqwewefwefwefwef • 2 months ago

edwefwefefwefwefwefw

17th December, 2017

Flex started a new conversation Non-static Method App\Collaboration::project() Should Not Be Called Statically, Assuming $this From Incompatible Context In Laravel • 2 months ago

I need show project collaborators on each project in My laravel app. this is My Collaborator table,

id  project_id collaborator_id
  1        1                         5
 2        2                        8
 3       4                         5

and I have queryScope in My Collaborator model,

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

and collaborator method to Get all the collaborators on this project

public function getCollaborators($id)
    {
        $collaborators = Collaboration::project($id)->get();
        return $collaborators;
    }

and route

Route::get('/project/{project}/collaborators', function($id){ 
       $collaborators = \App\Collaboration::project()->get(); // this is line 150
       $project = \App\Project::findOrFail($id);
       return view('collaborators.form',compact('collaborators','project')); 
    })->name('collaborators.form');

now when I go to the show project collaboratos following error is coming,

ErrorException in routes.php line 150: Non-static method App\Collaboration::project() should not be called statically, assuming $this from incompatible context

but this route is working and show all collaborators in the collaborator

Route::get('/project/{project}/collaborators', function($id){ 
       $collaborators = \App\Collaboration::all();
       $project = \App\Project::findOrFail($id);
       return view('collaborators.form',compact('collaborators','project')); 
    })->name('collaborators.form');

but I need show only collaborators on each project who related only to that project. how can fix this problem?

12th December, 2017

Flex left a reply on How To Show Different Tasks Items According To User Id In Laravel 5.2? • 2 months ago

@robrogers3 actually user model did not tasks. please see my controller

public function show($id)
 {
   if (Permission::where('status', 1)->where('project_id', $id)->where('collaborator_id',Auth::user()->id)->exists()) {
    
     $project = Project::find($id);
   $tasks = $this->getTasks($id);
    $permissions = $this->getPermissions($id);
   
    
     return view('Collaborators.show')->withProject($project)->withTasks($tasks);//,['task' => $task, 'project' => $project]);
    
        // return view('tasks.index')->withProject($project)->withTasks($tasks)->withFiles($files)->withComments($comments)->withCollaborators($collaborators);
    }
    else if (Permission::where('status',2)->where('project_id',$id)->where('collaborator_id',Auth::user()->id)->exists()){
      $project = Project::find($id);
      $tasks = $this->getTasks($id);

      return view('Collaborators.manager')->withProject($project)->withTasks($tasks);
    }

    else if (Permission::where('status',3)->where('project_id',$id)->where('collaborator_id',Auth::user()->id)->exists()){
      $project = Project::find($id);
      $tasks = $this->getTasks($id);

      return view('Collaborators.client')->withProject($project)->withTasks($tasks);
    }

can we use above logic with My controller?

Flex started a new conversation How To Show Different Tasks Items According To User Id In Laravel 5.2? • 2 months 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 • 2 months ago

no any idea?

Flex started a new conversation How To Display Comments Relavent On Each Task In Laravel 5.2 • 2 months 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 • 2 months 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 • 2 months 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 • 2 months 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 • 2 months 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 • 2 months 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 • 2 months 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 • 2 months 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 • 2 months 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 • 2 months 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 • 2 months 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 • 2 months 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 • 2 months 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 • 2 months 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 • 2 months 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 • 2 months 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 • 2 months 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 • 2 months 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 months 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 months 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 months 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 months 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 months 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 months 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 months 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 months 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 • 3 months 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] • 3 months 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 • 3 months ago

any idea?

Flex started a new conversation How Can I Enter Task_id To The File Table In Laravel 5.2 • 3 months 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 • 3 months 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 • 3 months 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 • 3 months 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 • 3 months ago

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

Edit Your Profile
Update

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