Eager Loading Specific Columns
You may not always need every column from the relationships you are retrieving. For this reason, Eloquent allows you to specify which columns of the relationship you would like to retrieve:
$books = App\Book::with('author:id,name')->get();
TIP
You have to include the id column to make this work, even if you don't need it. So be sure to include it with whatever other columns you need.
@nakov If you look at the OP's original code, they are using the ->findOrFail($id) to get the specified Task based on the id argument passed in via the request. So the eager loading would be valid in this case, as the OP may be using those items.
The original question was:
In task model i would like to return only user name instead of all attributes
So I assumed they were just looking for a way to limit the number of fields returned on the User model in the query.