Find us on facebook

Oct 12, 2017

Controller

<?php

namespace App\Http\Controllers;

use App\Contracts\CustomerInterface;
use App\Contracts\DashboardInterface;
use App\Contracts\UserInterface;
use Auth;
use Illuminate\Http\Request;

class UserController extends Controller {

    protected $customer;
    protected $dashboard;
    protected $user;
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct(CustomerInterface $customer, DashboardInterface $dashboard, UserInterface $user) {
        $this->middleware('auth');
        $this->customer = $customer;
        $this->dashboard = $dashboard;
        $this->user = $user;
    }

    /**
     * Show the user list.
     *
     * @return view
     */
    public function listUsers() {
        return view('user.list');
    }

    /**
     * Get users list data.
     *
     * @return view
     */
    public function data() {
        return $this->user->data();
    }

    /**
     * Get user by User id.
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function getUserById(Request $request) {

        return $this->user->getUserById($request->input('uid'));
    }

    /**
     * Process activate request.
     *
     * @return string
     */
    public function activate(Request $request) {
        $payload = [
            "uid" => $request->input('uid'),
            "user_level" => $request->input('user_level'),
            "activate" => $request->input('activate'),

        ];

        $success = ($this->user->activate($payload)) ? "true" : "false";

        return $success;
    }

    /**
     * user profile view.
     *
     * @return view
     */
    public function profile() {
        $profile = $this->user->getUserById(Auth::user()->id);
        $profileData = json_decode($profile->getContent(), true);
        return view('user.profile')->with("profile", $profileData);
    }

    /**
     * update user profile.
     *
     * @return view
     */
    public function updateProfile(Request $request) {

        $payload = [
            "uid" => $request->input('uid'),
            "prof_pic" => $request->file('prof_pic'),
            "name" => $request->input('name'),
            "username" => $request->input('username'),
            "user_level" => $request->input('user_level'),
            "email" => $request->input('email'),
            "phone_no1" => $request->input('phone_no1'),
            "phone_no2" => $request->input('phone_no2'),
            "address" => $request->input('address'),
            "date_joined" => $request->input('date_joined'),
            "report_to" => $request->input('report_to'),

        ];

        $success = ($this->user->updateProfile($payload)) ? "true" : "false";

        return redirect('/user/profile');
    }

}

No comments:

Post a Comment