Only getting the correct name and id?

I have a user who can have many clients, and a client can have many tasks, where one user is assigned to the task aswell. my current problem is that im trying to output all the clients tasks, on the client show page and show which user is assigned to the task, and that is working sort of. My problem is, it only gets the correct name and id from the table, and shows the same email, created_at, number etc for all users my current code is:

Clients show page:

@foreach($client->alltasks as $task) <p class="popovertext"> <span class="glyphicon glyphicon-envelope" aria-hidden="true"> </span> {{$task->assignee->email}}<br />
<span class="glyphicon glyphicon-headphones" aria-hidden="true"> </span> {{$task->assignee->work_number}}</p>

{{$task->assignee->name}}</a> <!--Shows users assigned to task (Basiclly tasks.fk_user_id_assign = user.user_id -> show name from users -->
<td>{{date('d, F Y, H:i:s', strTotime($task->assignee->created_at))}} </td>

Client model

class Client extends Model {

public function userAssignee() {
return $this->belongsTo('AppUser', 'fk_user_id', 'id');

public function alltasks()
return $this->hasMany('AppTasks', 'fk_client_id', 'id')->orderBy('status', 'asc')->orderBy('created_at', 'desc');

Client controller:

public function show($id)

$client = Client::findOrFail($id);
return view('')->withClient($client);

tasks model:

class Tasks extends Model {

protected $fillable = [

public function assignee() {
return $this->belongsTo('AppUser', 'fk_user_id_assign');

public function clientAssignee()
return $this->belongsTo('AppClient', 'fk_client_id');

And the user model:

public function tasksAssign()
return $this->hasMany('AppTasks', 'fk_user_id_assign', 'id')->where('status', 1);
public function tasksCreated()
return $this->hasMany('AppTasks', 'fk_user_id_created', 'id');

I tried too retrieve the query with a query_dump aswell, and this is what i got

string(134) "select * from `tasks` where `tasks`.`fk_client_id` = ? and `tasks`.`fk_client_id` is not null order by `status` asc, `created_at` desc"

I hope it’s understandable, and someone out there can help me, i tried so many diffrent things now, and I’m stuck.

from Newest questions tagged laravel-5 – Stack Overflow

Related Posts

Codeigniter : Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE) in Laravel project

I’m getting following error: **Parse error: syntax error, unexpected ‘const’ (T_CONST), expecting variable (T_VARIABLE)** Note : It’s working in local but facing issue in production server. private…

Firebase receive notification while tab is active or on focus

What i want is to be able to perform an action when a user receives a notification while the browser is open and tab is active or…

Laravel’s alias loader does not find class

We have a legacy project that we cannot update and we need to make some changes in symfony’s Response.php in vendor. We have solved this by copying…

Laravel 5 – generic document management

I have a system where you can create different types of unique documents. For instance, one document is called Project Identified and this expects certain inputs. Originally,…

Laravel Nova limit the results in indexQuery

I ran intro a situation where I need to limit the results of a resource to only 3 results. To be more specific, based on the logged…

Auditoria en laravel 5.8 [closed]

Cómo puedo automatizar el registro de actividades de un usuario en laravel? Si un usuario ingresa a un app de laravel, debo guardar toda su actividas, a…

Leave a Reply

Your email address will not be published.