Call to a member function where() on integer

Posted 8 months ago by boldstar

I am getting alarm when trying to submit data. The data coming in uses the user_id to create a new record of a related model Task. but I would like to use the 'user_id' to pluck() the name off the User table and use that data to insert on the model Engagement for the field assigned_to.

  1. Here is the controller I am using to insert the data
public function store(Request $request)
    {
        $data = $request->validate([
            'client_id' => 'required|integer',
            'return_type' => 'required|string',
            'year' => 'required|string',
            'assigned_to' => 'required|integer',
            'status' => 'required|string',
            'done' => 'required|boolean'
        ]);
        
        $user = $request->assigned_to;
        $userName = $user->where($user, auth()->user()->id)->pluck('name');

        $engagement = Engagement::create([
            'client_id' => $request->client_id,
            'return_type' => $request->return_type,
            'year' => $request->year,
            'assigned_to' => $userName,
            'status' => $request->status,
            'done' => $request->done,
        ]);

        $task = Task::create([
            'user_id' => $request->get('assigned_to'),
            'title' => $request->get('return_type')
        ]);

        $engagement->tasks()->attach($task->id);

        return response($engagement, 201);
    }

The alarm I get when I run the store() method is at this section of the controller

$user = $request->assigned_to;
$userName = $user->where($user, auth()->user()->id)->pluck('name');

This is the alarm

Call to a member function where() on integer

I have not seen much information on this issue so any help would be greatly appreciated..

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.