Flex

Experience

3,080

0 Best Reply Awards

  • Member Since 10 Months Ago
  • 2 Lessons Completed
  • 0 Favorites

16th October, 2017

Flex left a reply on Not Saving Collaborator Data To The Table • 4 days ago

No any help to solve this problem

Flex left a reply on Not Saving Collaborator Data To The Table • 4 days ago

do you have any ideas?

Flex started a new conversation Not Saving Collaborator Data To The Table • 4 days ago

in My Laravel 5.2 Application I have option add collaborators with the system. this is my ProjectCollaboratorController.php file

 public function addCollaborator(Request $request, $id, Collaboration $collaboration)
    {
       $this->validate($request, [
            'collaborator'     => 'required|min:5',
        ]);

       $collaborator_username           = substr(trim($request->input('collaborator')),1);
       $collaboration->project_id       = $id;

       //Get the project too
       $project = Project::findOrFail($id);

       if( is_null($this->getId($collaborator_username)))
       {
            return redirect()->route('collaborators.form',['project'=>$project])->with('warning', 'This user does not exist');
       }

       $collaborator = $this->isCollaborator($id, $this->getId($collaborator_username));
       if(! is_null($collaboration))
       {
            return redirect()->route('collaborators.form',['project'=>$project])->with('warning', 'This user is already a collaborator on this project');
       }

       $collaboration->collaborator_id  = $this->getId($collaborator_username);
       $collaboration->save();

       return redirect()->route('collaborators.form',['project'=>$project])->with('info',"{$collaborator_username} has been added to your project successfully");
    }
    /**
     * Get id of the user
     * @param  string $username
     * @return mixed  null | integer
     */
    private function getId($username)
    {
        $result = User::where('name', $username)->first();

        return (is_null($result)) ? null : $result->id;
    }

    /**
     * Check if the user about to be added as a collaborator is already one on the project
     * @param  int  $projectId
     * @param  int  $collaboratorId
     * @return boolean
     */
    private function isCollaborator($projectId, $collaboratorId)
    {
        return Collaboration::where('project_id', $projectId)
                            ->where('collaborator_id', $collaboratorId)
                            ->first();
    }

}

and this is the project_collaborator Model

class Collaboration extends Model
{

    protected $table = 'project_collaborator';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['project_id', 'collaborator_id'];

    public function user()
    {
        return $this->belongsTo(User::class, 'collaborator_id');
    }


      /**
     * Query scope to return information about the current project
     * @param  $query
     * @param  int $id
     * @return query
     */
    public function scopeProject($query, $id)
    {
        return $query->where('project_id', $id);
    }

}

and this is the routes for collaborators route

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


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

this is collaborator add form

collaborators/form.blade.php
 <div class="col-md-4" style="border:1px solid #ccc;margin-left:15px;padding:10px;">
        <h4 class="page-header">
            Collaborators
        </h4>
    @if(isset($collaborators))
           @foreach( $collaborators as $collaborator)
                <div>
                    <div>
                        <span>
                            <img src="{{ $collaborator->user()->first()->getAvatarUrl() }}" />
                        </span>
                    </div>
                    <button class="btn btn-sm btn-danger delete" style="margin-top:5px;padding:4px;width:35px;"
                      data-action="/projects/{{ $project->id }}/collaborators/{{ $collaborator->collaborator_id }}"
                      data-token="{{csrf_token()}}">
                    <i class="fa fa-trash-o"></i>
                    </button>
                </div>
                <hr/>
           @endforeach
        @endif
        <form class="form-vertical" role="form" method="post" action="{{ route('projects.collaborators.create', $project->id) }}">
        <div class="form-group{{ $errors->has('collaborator') ? ' has-error' : '' }}">
            <label> Add New </label>
            {!! mention()->asText('collaborator', old('collaborator'), 'users', 'username', 'form-control') !!}
            @if ($errors->has('collaborator'))
                <span class="help-block">{{ $errors->first('collaborator') }}</span>
            @endif
        </div>

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

but when I clicked add collaborator button only page is refreshed not saving data to the table. how can fix this problem.

15th October, 2017

Flex left a reply on How To Fix Undefined Variable: Collaborators • 5 days ago

@NFarrington what did you mean

f $collaborators is supposed to be defined, you will need to check the controller that controls the GET request for the form (which you have not provided) to ensure it is passing the $collaborators variable through (e.g. return view('collaborators.form')->with('collaborators', $collaborators);).

did you mean My form route? if it is so My form view routes is this

Route::get('/project/{project}/collaborators', function(){ 
       return view('collaborators.form'); 
    })->name('collaborators.form');

Flex left a reply on How To Fix Undefined Variable: Collaborators • 5 days ago

No any ideas?

Flex started a new conversation How To Fix Undefined Variable: Collaborators • 5 days ago

I am developing collaborators adding methods to my project management application. this is my collaborators add form

collaborators/form.blade.php
 <div class="col-md-4" style="border:1px solid #ccc;margin-left:15px;padding:10px;">
        <h4 class="page-header">
            Collaborators
        </h4>
        @if( $collaborators)
           @foreach( $collaborators as $collaborator)
                <div>
                    <div>
                        <span>
                            <img src="{{ $collaborator->user()->first()->getAvatarUrl() }}" />
                        </span>
                    </div>
                    <button class="btn btn-sm btn-danger delete" style="margin-top:5px;padding:4px;width:35px;"
                      data-action="/projects/{{ $project->id }}/collaborators/{{ $collaborator->collaborator_id }}"
                      data-token="{{csrf_token()}}">
                    <i class="fa fa-trash-o"></i>
                    </button>
                </div>
                <hr/>
           @endforeach
        @endif
        <form class="form-vertical" role="form" method="post" action="{{ route('projects.collaborators.create', $project->id) }}">
        <div class="form-group{{ $errors->has('collaborator') ? ' has-error' : '' }}">
            <label> Add New </label>
            {!! mention()->asText('collaborator', old('collaborator'), 'users', 'username', 'form-control') !!}
            @if ($errors->has('collaborator'))
                <span class="help-block">{{ $errors->first('collaborator') }}</span>
            @endif
        </div>

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

CollaboratorController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Auth;
use App\User;
use App\Project;
use App\Collaboration;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class ProjectCollaboratorsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function addCollaborator(Request $request, $id, Collaboration $collaboration)
    {
       $this->validate($request, [
            'collaborator'     => 'required|min:5',
        ]);

       $collaborator_username           = substr(trim($request->input('collaborator')),1);
       $collaboration->project_id       = $id;
       if( is_null($this->getId($collaborator_username)))
       {
            return redirect()->back()->with('warning', 'This user does not exist');
       }

       $collaborator = $this->isCollaborator($id, $this->getId($collaborator_username));
       if(! is_null($collaboration))
       {
            return redirect()->back()->with('warning', 'This user is already a collaborator on this project');
       }

       $collaboration->collaborator_id  = $this->getId($collaborator_username);
       $collaboration->save();

       return redirect()->back()->with('info', "{$collaborator_username} has been added to your project successfully");
    }

    /**
     * Get id of the user
     * @param  string $username
     * @return mixed  null | integer
     */
    private function getId($username)
    {
        $result = User::where('username', $username)->first();

        return (is_null($result)) ? null : $result->id;
    }

    /**
     * Check if the user about to be added as a collaborator is already one on the project
     * @param  int  $projectId
     * @param  int  $collaboratorId
     * @return boolean
     */
    private function isCollaborator($projectId, $collaboratorId)
    {
        return Collaboration::where('project_id', $projectId)
                            ->where('collaborator_id', $collaboratorId)
                            ->first();
    }

}

routes

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

but when I click to collaborators adding buttons following error messages displayed.

Undefined variable: collaborators (View: C:\Users\Flex\Desktop\ddd\resources\views\collaborators\form.blade.php)

how can I fix this problem

Flex left a reply on How To Print Project Name On Blade File • 5 days ago

@tisuchi this is My Controller code

public function store(Request $request,$projectId,$taskId)
    {
        $subtask = new Subtask;
        $subtask->subtask_name = $request->input('task_name');
        $subtask->task_id = $taskId;
        $subtask->project_id = $projectId;

        $subtask->save();
        //
    }

14th October, 2017

Flex left a reply on How To Print Project Name On Blade File • 6 days ago

@tisuchi thisis My routes for subtask


Route::get('projects/{projectId}/task/{taskId}/subtask', function ($projectId, $taskId) {

    return view('subtasks/form',['projectId'=>$projectId,'taskId'=>$taskId]);
});



Route::post('projects/{projectId}/task/{taskId}/subtask','[email protected]')->name('subtasks.form');

and my view file is form.blade.php and controller method is mentioned above

13th October, 2017

Flex left a reply on How To Print Project Name On Blade File • 6 days ago

@tisuchi I need dynamic way

Flex left a reply on How To Print Project Name On Blade File • 1 week ago

@tisuchi thanks for your reply but I have some problem with this code segments.

$subtaskid = 'Give Any Subtask ID here';

should I replace this sub task ID manually when I access different sub tasks?

12th October, 2017

Flex left a reply on How To Print Project Name On Blade File • 1 week ago

@tisuchi I need some help this is agent case?

Flex left a reply on How To Print Project Name On Blade File • 1 week ago

@tisuchi @Cronix and where should I put this codes

$projects = Project::with(['task', 'subtask'])->get();
$task = Task::with(['project', 'subtask'])->get();
$subtask = Subtask::with(['project', 'task'])->get();

Flex left a reply on How To Print Project Name On Blade File • 1 week ago

@tisuchi my subtask.form.php file is showing in my answer please see it?

Flex left a reply on How To Print Project Name On Blade File • 1 week ago

@tisuchi after established relationship how can i print project name and task name in my subtask.form.php?

Flex started a new conversation How To Print Project Name On Blade File • 1 week ago

hello, I need print My project name and task name on subtask blade file. My problem is this, I have project management app and its contain projects and one project have many tasks and one task have many subtasks. this is my relationship between task and subtasks task model

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

subtask model

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

and my subtask data input file is

subtask/form.blade.php
<h4>Add Sub Task</h4>
  <form class="form-vertical" role="form" method="post" action="{{ route('subtasks.form', ['projectId'=> $projectId, 'taskId'=>$taskId])}}">
            <div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
                <input type="text" name="task_name" class="form-control" id="name" value="{{ old('task_name') ?: '' }}">
                @if ($errors->has('task_name'))
                    <span class="help-block">{{ $errors->first('task_name') }}</span>
                @endif
            </div>

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

this is my subtaskcontroller

 public function store(Request $request,$projectId,$taskId)
    {
        $subtask = new Subtask;
        $subtask->subtask_name = $request->input('task_name');
        $subtask->task_id = $taskId;
        $subtask->project_id = $projectId;

        $subtask->save();
        //
    }

I need print My project name and task name on the subtask.blade.php how can I do this?

8th October, 2017

Flex left a reply on How To Create Table Relationship In Laravel • 1 week ago

@Dry7 what is the meaning of

fk__tasks__project_id

and

'fk__tasks__task_id'

7th October, 2017

Flex started a new conversation How To Create Table Relationship In Laravel • 1 week ago

hello, I am developing project management application using laravel 5.2 and in my app user can create projects and each project have many tasks and each task have many sub tasks as well. in my table project and task table have following relationship. task model relationship with project model is

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

project model relationship with task table

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

now My subtask table as following

id    subtask  task_id   project_id
1          abc          2              1
2          dfg          2              1
3          frt            3              2

how can I create subtasks model in relationship with project and task table?

6th October, 2017

Flex left a reply on How To Create Text Input Pop Up Box • 2 weeks ago

no any idea about this?

Flex started a new conversation How To Create Text Input Pop Up Box • 2 weeks ago

hi, I need create text input pop up box in My laravel application. see this codes,

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>


  @foreach ($project->tasks as $task)
  <ul>
    <li>
  <div>
  <div class="pull-right icons-align">
            <a href="" class="editInline"><i class="glyphicon glyphicon-plus"></i></a>
            <a href="" class="editInline"><i class="glyphicon glyphicon-pencil"></i></a>
            <a href="" class="editInline"><i class="glyphicon glyphicon-trash"></i></a>
        </div>
    <h4><a href="/projects/{{$project->id}}/tasks/{{ $task->id }}">{{ $task->task_name }}</a></h4>
 </div>
 </li>
 </ul>
  <hr>


@endforeach


</head>

<script>
$("a.editInline").css("display","none");

$('li').on('mouseover mouseout',function(){
     $(this).find('.editInline').toggle();
     //find the closest li and find its children with class editInLine and 
     //toggle its display using 'toggle()'
});
</script>
</body>

when I click

<a href="" class="editInline"><i class="glyphicon glyphicon-plus"></i></a>

this button icon I need generate text input pop up. how can I do this?

28th September, 2017

Flex left a reply on How To Fix Undefined Variable: Collaborators • 3 weeks ago

@adamprickett why we need controller to display blade file?

27th September, 2017

Flex left a reply on How To Fix Undefined Variable: Collaborators • 3 weeks ago

@edoc first of all need develop frontend (collaborators) adding form. after create controller.

Flex left a reply on How To Fix Undefined Variable: Collaborators • 3 weeks ago

@edoc actually I have not any controller for that

Flex left a reply on How To Fix Undefined Variable: Collaborators • 3 weeks ago

No any ideas?

Flex started a new conversation How To Fix Undefined Variable: Collaborators • 3 weeks ago

in My laravel app. I have form.blade.php file in collaborator folder of view file. collaborators/form.blade.php

 <div class="col-md-4" style="border:1px solid #ccc;margin-left:15px;padding:10px;">
        <h4 class="page-header">
            Collaborators
        </h4>
        @if( $collaborators)
           @foreach( $collaborators as $collaborator)
                <div>
                    <div>
                        <span>
                            <img src="{{ $collaborator->user()->first()->getAvatarUrl() }}" />
                        </span>
                    </div>
                    <button class="btn btn-sm btn-danger delete" style="margin-top:5px;padding:4px;width:35px;"
                      data-action="/projects/{{ $project->id }}/collaborators/{{ $collaborator->collaborator_id }}"
                      data-token="{{csrf_token()}}">
                    <i class="fa fa-trash-o"></i>
                    </button>
                </div>
                <hr/>
           @endforeach
        @endif
        <form class="form-vertical" role="form" method="post" action="{{ route('projects.collaborators.create', $project->id) }}">
        <div class="form-group{{ $errors->has('collaborator') ? ' has-error' : '' }}">
            <label> Add New </label>
            {!! mention()->asText('collaborator', old('collaborator'), 'users', 'username', 'form-control') !!}
            @if ($errors->has('collaborator'))
                <span class="help-block">{{ $errors->first('collaborator') }}</span>
            @endif
        </div>

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

it include with users.blade.php file in projects folder projects/users.blade.php

@include('collaborators.form')

but I got this error massages

Undefined variable: collaborators (View: C:\Users\Flex\Desktop\mati\resources\views\collaborators\form.blade.php)

Flex started a new conversation How To Develop Mouse Hover Icon Display System • 3 weeks ago

hi, I need develop icon display system when mouse hover to the place. (like laracast answer thered edit and delete button display ) how can I do this. what is the suitable technology for that.

26th September, 2017

Flex left a reply on How To Route Localhost With Existing Project Id • 3 weeks ago

@deansatch I add new methods to My ProjectController as following

public function addusers()
    {
        return view('projects.users');

    }

did you mean that kind of methods?

Flex left a reply on How To Route Localhost With Existing Project Id • 3 weeks ago

@deansatch I have not usercontroller or methods for This may I need it? can"t I do this in my ProjectController?

Flex started a new conversation How To Route Localhost With Existing Project Id • 3 weeks ago

Hi, I am working with Laravel 5.2 and developing project management app. In My application I have project created form as new.blade.php in projects folder of view file. new.blade.php

 <form class="form-vertical" role="form" method="post" action="{{ route('projects.store') }}">
 <div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
                <label for="name" class="control-label">Name</label>
                <input type="text" name="name" class="form-control" id="name" value="{{ old('name') ?: '' }}">
                @if ($errors->has('name'))
                    <span class="help-block">{{ $errors->first('name') }}</span>
                @endif
            </div>
<div class="form-group{{ $errors->has('notes') ? ' has-error' : '' }}">
                <label for="notes" class="control-label">Notes</label>
                <textarea name="notes" class="form-control" id="notes" rows="10" cols="10">
                  {{ old('notes') ?: '' }}
                </textarea>
                @if ($errors->has('notes'))
                    <span class="help-block">{{ $errors->first('notes') }}</span>
                @endif
            </div>
            <div class="form-group">
                <button type="submit" class="btn btn-default">Create</button>
            </div>
            <input type="hidden" name="_token" value="{{ csrf_token() }}">
        </form>

this form data save in ProjectController

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

        $project = new Project;
        $project->project_name   = $request->input('name');
        $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();

now I need after save this project data redirect page to users.blade.php file witch situated same projects folder with ulr project id. as example

localhost:8000/project/10/users

how can I do this? need some help......

24th September, 2017

Flex started a new conversation What Is The Best Way To Create Add Collaborators • 3 weeks ago

Hi, I have some problem what is the best way to develop my collaborator table to add collaborators in My Project management app. My problem is this I am developing project management app and in my application user can create a project and project have many tasks and tasks have one or many collaborators. first of all I need create email invitation to collaborators to project and then I need add collaborators from project to each tasks. so, may I need 2 table like this project_collaborator_table

id  collaborator_id  project_id
1                1                        2
2               2                       2
3               1                        3

and task_collaborator_table

id    collaborator_id      project_id     task_id
1                   1                           2                   1
2                   1                          2                   2

or can I manage withing 1 table this problem?

18th September, 2017

Flex left a reply on How To Show Table Data Regarding To Id • 1 month ago

@IgorBabko can you reply about My final question......

Flex left a reply on How To Show Table Data Regarding To Id • 1 month ago

can any body give some guidness to My final question?

17th September, 2017

Flex left a reply on How To Show Table Data Regarding To Id • 1 month ago

@IgorBabko now I need change little bit that means show tasks comment to relevant each task_id (current system show all comments regarding to project now I need show only comments regarding to each task on each project)

Flex left a reply on How To Show Table Data Regarding To Id • 1 month ago

@IgorBabko Grete it is working thanks for nice support

Flex left a reply on How To Show Table Data Regarding To Id • 1 month ago

@IgorBabko dear, this is My TaskControlller method to show task in tasks/show.blade.php

 public function getOneProjectTask($projectId, $taskId)
    {


     
        $task = Task::where('project_id', $projectId)
                      ->where('id', $taskId)
                      ->first();
        return view('tasks.show')->withTasks($task)->with('projectId', $projectId);
    }

this is my tasks/show.blade.php

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

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

{!!$tasks->body!!}

<hr>


@include('comments.form')


Flex left a reply on How To Show Table Data Regarding To Id • 1 month ago

@IgorBabko ok it is in tasks/index.blade.php


  @foreach ($project->tasks as $task)
    <h4><a href="/projects/{{$project->id}}/tasks/{{ $task->id }}">{{ $task->task_name }}</a></h4>
@endforeach

and this index.blade.php file situated in projects/show.blade.php

@include('tasks.index')
    

Flex left a reply on How To Show Table Data Regarding To Id • 1 month ago

@IgorBabko did it but same error massage here

see my TasksController

namespace App\Http\Controllers;

use Auth;
use App\Project;
use App\Task;
use Illuminate\Http\Request;

use App\Http\Requests;

class TasksController extends Controller
{
public function postNewTask(Request $request,$id, Project $project)
{

    $task = new Task;
    $task->task_name   = $request->input('name');
    $task->body = $request->input('body');
    $task->assign = $request->input('status');
    $task->priority = $request->input('status');
     $task->duedate  = date("Y-m-d", strtotime($request->input("date")));
     $task->project_id = $id;
$task->save();
     return redirect()->back()->with('info', 'Task created successfully');
}

public function getOneProjectTask($projectId, $taskId)
    {


     
        $task = Task::where('project_id', $projectId)
                      ->where('id', $taskId)
                      ->first();
        return view('tasks.show')->withTasks($task)->with('projectId', $projectId);
    }

public function show(Task $task)
    {
        return view('tasks.show', ['task' => $task]);
    }

}

Flex left a reply on How To Show Table Data Regarding To Id • 1 month ago

@IgorBabko witch controller? Comment or Task

Flex left a reply on How To Show Table Data Regarding To Id • 1 month ago

@Dry7 later I need customized this with project_id that means comment show

related to project_id -> task_id -> comment

Flex left a reply on How To Show Table Data Regarding To Id • 1 month ago

@IgorBabko did it but generated following error

Undefined variable: task (View: C:\Users\Flex\Desktop\promag\resources\views\comments\form.blade.php)

Flex started a new conversation How To Show Table Data Regarding To Id • 1 month ago

hi, I am developing project management app using Laravel. in my application I have project and one project have many tasks and one task have many comments. so, I have comment table like this

id    comment  project_id    user_id
1         abc               1                    1
2        dcf                1                    2
3        fgt                2                    1
4        fgt                2                    2
5        fhgt              1                     3

this is my comment controller for comment post

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

and this is my comment model

<?php

namespace App;

use App\User;
use App\Project;
use Auth;
use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['comments', 'project_id', 'user_id'];
    
        public function scopeProject($query, $id)
    {
        return $query->where('project_id', $id);
    }
    
    /*
     * Get the user that is reponsible for a comment
     * @return collection
     */
    
     public function user()
    {
        return $this->belongsTo(User::class);
    }

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



}

in my application user can visit there project area using projectController index function

public function index()
     {
        $projects = Project::all();
        return view('projects.index')->withProjects($projects);
}

and then when click on one project link user can see tasks created form and existing tasks list for relevant project. my task created form is in projects folder in view file in resources folder and existing task list include with this file projects/show.blade.php

 @include('tasks.index')

tasks/index.blade.php file is

 @foreach ($project->tasks as $task)
    <h4><a href="/projects/{{$project->id}}/tasks/{{ $task->id }}">{{ $task->task_name }}</a></h4>
@endforeach

my project model is

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


}

now when I click one of existing task link I can see comment box and now I need show comment table comment on each task related with each project. I mean I need to show each project comments on every tasks witch is related to that project. can you give me some help?

Thanks!

14th September, 2017

Flex left a reply on How To Set Up Relationship Between Two Models • 1 month ago

@Dry7 I have some problem here with your answer that means in Task model you have used comments with "s" to end

public function comments()
    

but in Comment model you have used task with out "s" to end

public function task()

what is this different.

13th September, 2017

Flex started a new conversation How To Set Up Relationship Between Two Models • 1 month ago

hi, I have two models in My Laravel app as Task and Comment. Task model

<?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'];
}

Comment

<?php

namespace App;

use App\User;
use Auth;
use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['comments', 'project_id', 'user_id'];

}

in My app one task has many comments and one comment contain relate with one task. so now I need established relationship between these two models. how can do this?

12th September, 2017

Flex started a new conversation Show Comment Data On Each Projects • 1 month ago

hello, In My Laravel app going to display comments on each task related to each project. I have project and tasks witch related to projects. when I click on each project I can see tasks witch related to projects. then I click on each task I need display comments related to this task. I am posting comments using commentController

  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->task_id = $taskId;
       $comment->user_id        = Auth::user()->id;
       $comment->save();

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


My comment form.blade.php

<div class="row" style="margin-left:5px;padding:5px;">
    @if(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
   
    <form class="form-vertical" role="form" method="post" action="{{ route('projects.comments.create', $tasks->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>

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

Comment model

class Comment extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['comments', 'project_id', 'user_id'];
    
        public function scopeProject($query, $id)
    {
        return $query->where('project_id', $id);
    }
    
    /*
     * Get the user that is reponsible for a comment
     * @return collection
     */
    
     public function user()
    {
        return $this->belongsTo(User::class);
    }

}

then I need show My comment table data on each task. how can do this?

20th August, 2017

Flex left a reply on SQLSTATE[23000]: Integrity Constraint Violation: • 2 months ago

@Snapey finally got the result. in this way in My TaskController

  public function postNewTask(Request $request,$id, Project $project)
{

    $task = new Task;
    $task->task_name   = $request->input('name');
    $task->body = $request->input('body');
    $task->assign = $request->input('status');
    $task->priority = $request->input('status');
    $task->duedate  = date("Y-m-d", strtotime($request->input("date")));
    $task->project_id = $id;
    $task->save();

form url

<form  method="post" action="{{ route('projects.tasks.create', $project->id) }}">

and routes

Route::post('projects/{projects}/tasks', [
    'uses' => '\App\Http\Controllers\[email protected]',
    'as' => 'projects.tasks.create'
]);

thanks very much for your instructions....

19th August, 2017

Flex left a reply on SQLSTATE[23000]: Integrity Constraint Violation: • 2 months ago

@Snapey I found some error in My Migration files that means I did not put primary and forign key as well between My project and Task files is this problem with this mattes

Task migration file

public function up()
    {
         Schema::create('tasks', function(Blueprint $table)
        {
            $table->increments('id')->unsigned();
            $table->longText('task_name');
            $table->text('body');
            $table->string('assign');
            $table->string('priority');
            $table->date('duedate');
            $table->integer('project_id')->unsigned();
            $table->timestamps();
 
          
        });
        
    }

projects migration file

public function up()
    {
        Schema::create('projects', function(Blueprint $table)
            {
                $table->increments('id')->unsigned();
                $table->string('project_name');
                $table->longText('project_notes');
                $table->string('project_status')->default('Upcoming');
                $table->integer('user_id')->unsigned();
                $table->char('color', 7);
                $table->string('group');
                $table->timestamps();

                $table->foreign('user_id')
                      ->references('id')->on('users')
                      ->onUpdate('cascade')
                      ->onDelete('cascade');
            });
        //
    }

Flex left a reply on SQLSTATE[23000]: Integrity Constraint Violation: • 2 months ago

@Snapey ok got lop of things from you now I need know some thing this is My new routes

Route::resource('project/{project}/tasks','TasksController');


and this is my new form URL

<form method="post" action="{{ route('tasks.store', $project->id) }}">

what are the wrongs with this both routes and form actions

Flex left a reply on SQLSTATE[23000]: Integrity Constraint Violation: • 2 months ago

@Snapey did it with your routes but same error has occurred here

Flex left a reply on SQLSTATE[23000]: Integrity Constraint Violation: • 2 months ago

@Snapey above code segment occurred same error

My task roures is as follow

Route::resource('tasks','TasksController');

Flex left a reply on SQLSTATE[23000]: Integrity Constraint Violation: • 2 months ago

No any idea?

Flex started a new conversation SQLSTATE[23000]: Integrity Constraint Violation: • 2 months ago

Hi, I need pass Project Model id as project_id to My Task Model table. this is My TaskController

public function store(Request $request, Project $project)
{
    $task = new Task;
    $task->task_name   = $request->input('name');
    $task->body = $request->input('body');
    $task->assign = $request->input('status');
    $task->priority = $request->input('status');
     $task->duedate  = date("Y-m-d", strtotime($request->input("date")));
    

    // This will set the project_id on task and save it
    $project->tasks()->save($task);
}

this is My form action route regarding to store task data in projects folder blade file is show.blade.php

<form method="post" action="{{ route('tasks.store') }}">

this is Task Mode

<?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 projects()
     {
         return $this->belongsTo('App\Project');
     }
    
    
    //
}

this is Project Model

<?php

namespace App;
use Auth;
use App\Task;

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


}


but I got this error massage here

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'project_id' cannot be null

how can fix this problem?

Edit Your Profile
Update

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