Display Data based on user role

Posted 7 months ago by Prathamesh6921

Greetings, i am novice in laravel ,I am trying to fetch all the data on admin profile .On the admin page he want to see the requests made by all users. Login function for role check while sign in.

 public function loginProcess(Request $request)
        {
            if(Auth::attempt(['email' => $request->email, 'password' => $request->password, 'status'=>1])){
                if((Auth::user()->role == 'admin')){
                     return url('showallrequest');
                } else {
                    if($request->session()->has('request_cache')){
                        return $this->saveRequest($request);
                    } else {
                        return url('displayLegal');
                    }
                }
                return 'true';
            }
            return "false";
        }

This is the user controller in which admin will logged-in and after login he will be redirected to the dashboard where he will see all the user's requests.

@section('content')
    <div class="row" style="padding-left: 35px;padding-right: 35px;" >
        <div class="col-md-12" style="margin-bottom: 20px">
            <button class="btn btn-success pull-right" style="background: red;border: none;"><a href="submit_query">New Request <i class="fa fa-plus" style="margin-left: 10px;"></i></a></button>
        </div>
        <div class="col-md-12" id="user_request_div">

        </div>
        <!--end .card -->
    </div>
    @endsection
@section('side_bar')
    @include('backend_template.includes.side_bar')
    @endsection

@section('jsses')
    @include('frontend_template.includes.foot')
    <script>
        $.ajax({
            url:"showAllReqToAdmin",
            type:"POST",
            data:{_token:csrf_token},
            success: function (result) {
                $('#user_request_div').html('');
                console.log(result);
                for(var i = 0;i<result.length;i++){
                    if(result[i].service_package.default_price == null){
                        result[i].service_package.default_price = 0;
                    }
                    $("<div class='card'> " +
                        "<div class='card-body text-default-light' style='padding: 15px;' > " +
                            "<div class='row'>" +
                                    "<div class='col-md-2' style='text-align: left' >"+
                                    "<h4>"+result[i].user.firstname+"</h4>"+
                                    "<h5>"+result[i].user.lastname+"</h5>"+
                                    "</div>"+
                                    "<div class='col-md-3' style='text-align: left' >" +
                                        "<h4 style='padding: 0px'>"+result[i].request_type.aop.name+"</h4>" +
                                        "<h5>"+result[i].title+"</h5>" +
                                    "</div>" +
                                    "<div class='col-md-3' style='text-align: center'> " +
                                        "<h4>Resolution method:</h4> " +
                                        "<h5>"+result[i].service_package.title+ " (" + result[i].service_package.default_price + " SGD)" +"</h5> " +
                                    "</div>" +
                                    "<div class='col-md-2' style='text-align: center'>" +
                                        "<h4>Not yet assigned</h4>" +
                                    "</div>" +
                                    "<div class='col-md-2' style='text-align: center'>" +
                                        "<h4>New</h4> " +
                                        "<h5>"+result[i].created_at+"</h5>" +
                                    "</div>" +
                            "</div>" +
                        "</div>" +
                    "</div>").appendTo('#user_request_div');
                }
            }
        });
    </script>
@endsection

In this blade page i have written the code to append the data

Route.php

Route::get('showAllReqToAdmin', '[email protected]');

I am not getting any error,don't know where is the exact probelm with laravel 5.7 i am using jQuery and ajax,please help me

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