realty/app/Http/Controllers/API/v1/UserController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $this->authorize('create', User::class);
        $this->validate($request, [
            'image_id' => 'nullable|integer|exists:images,id',
            'role'     => 'required|string|in:manager,employee',
            'f_name'   => 'required|string|max:191',
            'm_name'   => 'nullable|string|max:191',
            'l_name'   => 'required|string|max:191',
            'email'    => 'required|string|email|max:191|unique:users',
            'password' => 'required|string|min:8',
        ]);
        $attributes = [
            'company_id' => auth()->user()->company_id,
            'password'   => Hash::make($request->password),
        ];
        return new UserResource(
            User::create(
                array_merge(
                    $attributes, $request->only(
                        'image_id',
                        'role',
                        'f_name',
                        'm_name',
                        'l_name',
                        'email'
                    )
                )
            )
        );
    }
public function store ( Request $ request ) { $ this -> authorize ( 'create' , User :: class ) ; $ this -> validate ( $ request , [ 'image_id' => 'nullable|integer|exists:images,id' , 'role' => 'required|string|in:manager,employee' , 'f_name' => 'required|string|max:191' , 'm_name' => 'nullable|string|max:191' , 'l_name' => 'required|string|max:191' , 'email' => 'required|string|email|max:191|unique:users' , 'password' => 'required|string|min:8' , ] ) ; $ attributes = [ 'company_id' => auth ( ) -> user ( ) -> company_id , 'password' => Hash :: make ( $ request -> password ) , ] ; return new UserResource ( User :: create ( array_merge ( $ attributes , $ request -> only ( 'image_id' , 'role' , 'f_name' , 'm_name' , 'l_name' , 'email' ) ) ) ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .