B
B
booba_no_booba2020-12-14 17:51:49
Laravel
booba_no_booba, 2020-12-14 17:51:49

How to record the id of an authorized user?

I want to write the id of the authorized user to the table adjacent to the user, but not an object is returned, how to ask the code to work?
here is my method:

public function SalesSave(Request $req) {
        $rules = [
            'date' => 'required|min:4|max:36',
            'earnings' => 'min:1|max:16',
        ];
        $validator = Validator::make($req->all(), $rules);
        if($validator->fails()){
            return response()->json($validator->errors(), 400);
        }
        $us = Auth::user()->id;
        DB::table('sales')->insertGetId(
            ['date' => $req->query('date'), 'id' => $us, 'earnings' => $req->query('earnings')]);
        return view('home',[]);
    }

mistake:
unknown.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question