Deekshith

Member Since 2 Years Ago

Experience Points
11,470
Total
Experience

3,530 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
31
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

  • Community Pillar

    Earned once your experience points ranks in the top 10 of all Laracasts users.

Level 3
11,470 XP
Apr
10
1 day ago
Activity icon

Replied to Add Condition Along With Pagination For One To Many Relationsip.

The categories method is undefined. as I am using Corel package for this and in documentation, they mentioned like below,

Categories and Taxonomies
Get a category or taxonomy or load posts from a certain category. There are multiple ways to achieve it.

// all categories
$cat = Taxonomy::category()->slug('uncategorized')->posts->first();
echo "<pre>"; print_r($cat->name); echo "</pre>";

// only all categories and posts connected with it
$cat = Taxonomy::where('taxonomy', 'category')->with('posts')->get();
$cat->each(function($category) {
    echo $category->name;
});

// clean and simple all posts from a category
$cat = Category::slug('uncategorized')->posts->first();
$cat->posts->each(function($post) {
    echo $post->post_title;
});

I am using first method but now i want to pass multiple categories and fetch all posts linked with those categories.

Activity icon

Replied to Add Condition Along With Pagination For One To Many Relationsip.

Also, i stuck in corcel package where I have a query like below to fetch posts from wordpres DB

Taxonomy::category()->slug('current-affairs-2')->with('posts')->first();   

return $cat->posts()
             ->where('post_status', 'publish')
             ->whereYear('post_date','2019')
             ->whereMonth('post_date', '10')
             ->newest()
             ->paginate(10);

But here the problem if I want to add multiple categories in slug method how to add?

Here I want to add

['current-affairs-2','current-events-2']

So I want to merge all the posts which has these two categories and I will display those posts in frontend.

Activity icon

Replied to Add Condition Along With Pagination For One To Many Relationsip.

Sorry, it worked as there was a typo in the column name. :-)

Activity icon

Replied to Add Condition Along With Pagination For One To Many Relationsip.

status is an unknown column here because I should put this condition in posts relationship as this one to many relationship

Activity icon

Started a new Conversation Add Condition Along With Pagination For One To Many Relationsip.

i have a query like below,

$cat = Taxonomy::category()->slug('current-affairs-2')->with(['posts'=>function($q) {
                $q->where('status', 'publish')
					->whereDate('post_date','2021-03-03');
            }])->first();

    return $cat->posts()->paginate(10);

But here "where" condition is not working. how to add pagination along with conditions for one to many relationships?

can I add conditions here only?

 $cat->posts()->paginate(10);
Activity icon

Started a new Conversation Laravel Corcel Get Posts By Category

I am using laravel corcel to get details of my WordPress DB posts.

I have a query like below where it displays all posts on the selected date,

$date = "2019-10-12";
        return Post::status('publish')
        ->whereIn('post_type', ['post'])
        ->whereHas('taxonomies', function ($query) {
            $query->whereIn('taxonomy',['category', 'category2']);
        })
        ->whereDate('post_date',$date)
        ->newest()
        ->paginate(100);

the response is,

[
{
"post_title":"sdfsf",
"taxonomies": [
        {
          "term_taxonomy_id": 345,
          "term_id": 345,
          "taxonomy": "category",
          "description": "",
          "parent": 0,
          "count": 1013,
          "pivot": {
            "object_id": 135101,
            "term_taxonomy_id": 5596
          },
          "term": {
            "term_id": 238401871,
            "name": "SECURE SYNOPSIS",
            "slug": "secure-synopsis",
            "term_group": 0
          }
        },
        {
          "term_taxonomy_id": 5597,
          "term_id": 238401872,
          "taxonomy": "post_tag",
          "description": "",
          "parent": 0,
          "count": 934,
          "pivot": {
            "object_id": 135101,
            "term_taxonomy_id": 5597
          },
          "term": {
            "term_id": 238401872,
            "name": "Insights secure synopsis",
            "slug": "insights-secure-synopsis",
            "term_group": 0
          }
        }
      ]

},

{
"post_title":"secondpost",
"taxonomies": [ ]

},
{
"post_title":"secondpost",
"taxonomies": [
        {
          "term_taxonomy_id": 345,
          "term_id": 345,
          "taxonomy": "category",
          "description": "",
          "parent": 0,
          "count": 1013,
          "pivot": {
            "object_id": 897,
            "term_taxonomy_id": 5593
          },
          "term": {
            "term_id": 87798,
            "name": "Current affairs",
            "slug": "current-affairs",
            "term_group": 0
          }
        },
       
      ]

}
]

Here now I want to filter the data by category name example : I want to filter the above response which has taxonomies->term->slug = "current-affairs" i am not able to do this in the above code and also if I use whereHas it is loading very slowly also I wanted to filter out empty array of taxonomies. so I have used code like below,

$taxonomies = Post::whereHas('taxonomies')->with(['taxonomies'=> function($q) {
            $q->whereIn('taxonomy',['category', 'category2']);
			
        }])->status('publish')->whereDate('post_date',$date)->get();

        return $filteredCollection = $taxonomies->filter(function($store) {
            return $store->taxonomies->count() > 0;
        });

this has some good speed now.

But I want to filter the above response by taxonomies term slug name i.e category name.

If I pass term->slug as "current-affairs" then it should display only matched response. Please help me with this.

Activity icon

Replied to Secured Storage Of Client Secret And Client Id To Communicate Between Mobile App And Laravel Api

Thank you for the reply. yes, will check this. And also please let me know what the will be a procedure if I change the client_credentials later. do I need to build the android app and update it again?

Activity icon

Started a new Conversation Secured Storage Of Client Secret And Client Id To Communicate Between Mobile App And Laravel Api

we are working on android where the API is given using laravel. this app is just an information site with article categories so here there is no user authentication or registration.

But to protect the public API where particular API should be accessible from app only I have used laravel passport Client Credentials Grant Tokens.

I have created a client using the below command,

php artisan passport:client --client

Now what I am doing is whenever the user first opens the app I am calling this API to generate the token,

https://www.example.com/oauth/token

Post Json:

{
    "grant_type": "client_credentials",
    "client_id": "3",
    "scope": "*",
    "client_secret": "client_id_3_secret_goes_here"
}

Now my concern is where to store this client id and client_secret? shall I hard code client_id and client_secet in android code so that every time user first opens the app will call this API using hardcoded secret and client_id?

what if I change the client_secret in the future I should edit the android code as well to make changes.. Please help me out with a possible solution for this.

Apr
09
2 days ago
Activity icon

Replied to Fetch Non Checked Checkbox Values From Dynamic Form With Array Name

Thank you for the reply. I have add more button where they can add same fields more than 1 time. So I have added array as name and I solved it by adding hidden input with same name.

Activity icon

Started a new Conversation Fetch Non Checked Checkbox Values From Dynamic Form With Array Name

i have a fields like below,

 <form method="post" id="authorinfoform" action="http://localhost/journalportal/public/submission/submit-article/first-step" enctype="multipart/form-data">
<input type="hidden" name="_token" value="aqv36AUVeNVqKtPiUgUDdWJ0zVRCZjN0hYdflfVb">
    

        <div class="list_wrapper">  
            <div class="row">

                <div class="col-xs-4 col-sm-4 col-md-4">

                    <div class="form-group">
                        First Name
                        <input name="first_name[]"  type="text" placeholder="First Name" class="form-control" required="">
                        
                    </div>
                </div>

                <div class="col-xs-4 col-sm-4 col-md-4">
                    <div class="form-group">
                        Last Name
                        <input autocomplete="off" name="last_name[]"  type="text" placeholder="Last Name" class="form-control" required="">
                    </div>
                </div> 
                <div class="col-xs-4 col-sm-4 col-md-4">
                    <div class="form-group">
                        <div class="checkbox">
                          <label for="corresponding"><input type="checkbox" name="corresponding[]" id="corresponding" value="1" checked="">Corresponding author</label>
                        </div>
                        
                    </div>
                </div> 

                <div class="col-xs-1 col-sm-1 col-md-1">
                    
                   <button class="btn btn-primary list_add_button" type="button">+</button>
                </div>
            </div>
        <div class="row">
<div class="col-xs-4 col-sm-4 col-md-4">
<div class="form-group">
First Name 
<input name="first_name[]" type="text" placeholder="First Name" class="form-control" required="">
</div>
</div>
<div class="col-xs-4 col-sm-4 col-md-4">
<div class="form-group">
Last Name 
<input name="last_name[]" type="text" placeholder="Last Name" class="form-control" required="">
</div>
</div>
<div class="col-xs-4 col-sm-4 col-md-4">
<div class="form-group">
<div class="checkbox">
<label for="corresponding_1">
<input type="checkbox" name="corresponding[]" id="corresponding_1" value="1">Corresponding author
</div>
</div>
</div>
<div class="clearfix"></div>
<div class="col-xs-1 col-sm-7 col-md-1"><a href="javascript:void(0);" class="list_remove_button btn btn-danger">-</a></div></div></div>


<div class="text-right">
<button type="submit" class="btn btn-info btn-sm pull-right">Save</button>
</div>
</form>

Here i have checkbox field with array name,

and i am trying to save these details in controller like below,

$updatedata = [
                    'author_contribution' => request('contribution'),
                    'third_step'   => 1,
                ];

        if($checkJournalExists->status == "I")
        {
            $updatedata['status'] = "P";

        } 

        $updatedatadb = $checkJournalExists->update($updatedata);

        $checkStatus = $checkJournalExists->third_step;

       

        $insert = array();
        foreach($request->first_name as $key => $firstname) {
            $insert[$key]['first_name'] = $firstname;
            $insert[$key]['article_submission_id'] = $checkJournalExists->id;
        }
        foreach($request->last_name as $key => $lastname) {
            $insert[$key]['last_name'] = $lastname;
            $insert[$key]['article_submission_id'] = $checkJournalExists->id;
        }
        foreach($request->email as $key => $email) {
            $insert[$key]['email'] = $email;
            $insert[$key]['article_submission_id'] = $checkJournalExists->id;
        }
        foreach($request->title as $key => $title) {
            $insert[$key]['title'] = $title;
            $insert[$key]['article_submission_id'] = $checkJournalExists->id;
        }

        foreach($request->affiliation as $key => $affiliation) {
            $insert[$key]['affiliation'] = $affiliation;
            $insert[$key]['article_submission_id'] = $checkJournalExists->id;
        }

        foreach($request->department as $key => $department) {
            $insert[$key]['department'] = $department;
            $insert[$key]['article_submission_id'] = $checkJournalExists->id;
        }

$authorinsert = ArticleAuthor::insert($insert);

Here non selected checkbox values are not coming in array and also i want non selected checkbox return as 0 like below,

[1,0]

now what is happening is it is returning only checked checkbox field values. how to get non checked and checked field both with 0 and 1 value?

Activity icon

Replied to Secure Laravel Api Endpoints For Non User Login Api's

i am trying like below, when user installs the app i will call this api to generate the token,

http://localhost/insightsapp/public/oauth/token

then store in localstorage and pass this token in authorization header to fetch all other API details.

Once token expired i will let to call token generate api again.

is this approach is fine or please let me know any other approach i can follow.?

Apr
08
3 days ago
Activity icon

Replied to Secure Laravel Api Endpoints For Non User Login Api's

@martinbean thanks for the reply. i have some confusions. please check this.

i have followed documentation and added the route like below in api.php

Route::get('/test-api', function (Request $request) {
    return 'here';
})->middleware('client');

I have created a client as well using below command,

php artisan passport:client --client

But the problem is now how the client (android app ) generates the token.

right now i can create the token like below,

http://localhost/insightsapp/public/oauth/token

the response will be like below,

{"token_type":"Bearer","expires_in":31536000,"access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiI2IiwianRpIjoiN2VmNzgxZDU3ZTkOGRkMjlhNWZiNWVlNzZkM2I3M2U5NDgyZmI0YjA5YzdmODA5M2U5MmFiNzllMDA0MDk3MGE0YTdlZGYiLCJpYXQiOjE2MTc4OTUyMjUuMTM4OTg3LCJuYmYiOjE2MTc4OTUyMjUuMTM4OTk3LCJleHAiOjE2NDk0MzEyMjUuMDIyODQxLCJzdWIiOiIiLCJzY29wZXMiOlsiKiJdfQ.gYpbzoC2xfv_ixYISRgk6ZbEGHG8f-e3-n87dXwZEi0IGU1kvoV6McxNUnCRRxMiaz0JU1HCD1eXQw5R77DpUTB9gH6xe93LLlvHr0pSNX4ZpQ-Oxe5yrGHqW5pEZp0nztC9T-UqqvGzOPHFdqQH9e6JebAUgQiv3gxQGNot88osG1AUbbQAVgqxwTNOK5fTN1JaKsWnPgWrdNIN6LbQIoST4htnReelAaxpVCOFLD4dYj_u8fK5v5IvTfTbXxJ972FoejQSQIOsWZi4NvJQ2qDbjXENB-2ljYth2K5xQJAKWnB4xJTA-Rb-bQ0GEGNhyPcHpDultqUJaBgJBLGcbtLoes-8FI1iq1ghJSV8g07-o8okA0-5K6vVoRcwaxm5udA9S_vLOlmlhzY-VZKY1StOmxDJ1ncfyQKX6S6gypfq_s34D3NUcc3Z17hQxCDj1Gvnhc2H5MumakqQdDVPREbwn0PnCjrSwu1Oy-YOwOjuZZtlybrZK57zzHYoEDVHJ20wqiz8Gkif4-g2UD6WeImFmXM3FVaJq7W-r_5sHySbTmhOdrN3AkOs53SYMN3tPa56vMLKBcKTB5zdde6vk45Ymp2ua_8oNgpfCK9h8vkJ0QsGHOtd9HacoXd4p27x_95hR2ekYfj7cvqDIZpvaGbzyXl39lydXqluuOoGg"}

But the main confusion is how android app use this token for api calls? do i need to call this token generate api everytime whenever android user clicks normal api?

as there is no user login how to store this token for future reference and when to call this token generate api?

Please help me with this

Activity icon

Started a new Conversation Secure Laravel Api Endpoints For Non User Login Api's

i have wordpress site and working on android application for that i am creating the api using wordpress db in laravel api.php.

example :http://www.example.com/api/posts

this will retrieve all posts but i don't want this api to be accessed in public instead i want token based verification system from machine to machine.

i am not able to find the example to achieve this. as of now there is no user database in current application and it is just information portal.

any example?

Apr
05
6 days ago
Activity icon

Replied to How To Add Logic To Store Data In Blocks Using Save And Continue

File uploading are present and now what i am doing is, once user initiated the submission i am storing user id along with UUID of article submission and once user completes first step then i fill respective fields in column and added first_step boolean to track in which step user is present. this is fine right?

Activity icon

Started a new Conversation How To Add Logic To Store Data In Blocks Using Save And Continue

I have different Steps in form like, first step => adding files and images then user clicks on Save and continue

second step => enter details about the project and click save and continue.

if the user refreshes the page it should continue from the previously stopped section. I should add a flag for each section.

how to design DB for this? single table with null values is enough?

Activity icon

Started a new Conversation Display Editor Data Using Ajax And Prevent Xss Attack.

i have ckeditor data with html tags in laravel and also I used laravel pufier to purify the input.

Now I am using the on change ajax function to get particular type details and this detail data will have HTML tags. i am using like below in ajax,

function articletypechange(selval)
{
    var selval = selval.value;

    var data = {
        yowe: selval,
        _token: "{{ csrf_token() }}"
    }
    var type = 'post';
    var url = "{{ url('get-article-type-detail') }}";

            // process the form
      $.ajax({
          type : type,
          url  : url,
          data : data,
          dataType : 'json', // what type of data do we expect back from the server
          encode  : true
      }).done(function(data) {
         console.log(data);

         if(data)
         {

            $('#articletypedetail')
                  .html("")
                  .append($('<div class="card">').text())
                  .append($('<div class="card-body">').text())
                  .append($('<h5 class="card-title"></h5>').text(data.article_type_name))
                  .append($('<p class="card-text"></p>').text(data.description))
                  .append($('<h5 class="card-title"></h5>').text('GUIDELINES (LIMITS)'))
                  .append($('<p class="card-text"></p>').text(data.guidelines))
                  .append($('</div></div>').text());

            // $('#articletypedetail').html('');
            // $('#articletypedetail').$("<div>").text(appendHtml).html();


         } else {

         }
            
              // here we will handle errors and validation messages
          }).fail(function(err) {
            //do something when something is wrong
            alert(err.responseJSON.message);
            console.log(err.responseJSON.message);
            return false;
          }).always(function() {
             //do  something whether request is ok or fail
          });
}

if I use text here HTML tags are directly displaying in view file like below in guidelines section,

<p>GUIDELINES (MAX. LIMITS) Abstract length: 350 words Figures and tables: 15 Manuscript length: 12000 words</p>

How to securely escape HTML tags in ajax?

Apr
01
1 week ago
Activity icon

Replied to How To Convert Mysql Column Content To Citation .ris File

@sirik still no use as this fastexcel works with get but I want to download citation in .ris format for each article. can you please send me one example code so that I will try also It is not in proper format if i use get()

$articleid = JournalArticle::where('id',1)->select('citation')->get();

(new FastExcel($articleid))->export('citation1.ris', function ($user) {
        return [
            'citation' => $user->citation,
        ];
    });

Activity icon

Started a new Conversation Logic Behind The Plese Wait Before Retrying In Reset Password Form

I am using laravel default auth scaffolding for registration and log in.

In the reset password form if we try more than 1 time continuously then it will show please wait before retrying the error message. what logic they have applied for this and I want to check the logic of the code. where can I find this? anyone tell me how it works?

Mar
31
1 week ago
Activity icon

Replied to Get Null Values At Last In Query OrderBY

in db it is zero but i have used in model to replace the value,

public function getProjectNumberAttribute($value)
    {
        if($value == "0")
        {
            return NULL;

        } else {

            return $value;
        }
    }
Activity icon

Started a new Conversation Get Null Values At Last In Query OrderBY

i have a query like below,

public function getTest()
    {
     return StudentMap::orderBy('project_number')
        ->get();
    }

The model is,

public function getProjectNumberAttribute($value)
    {
        if($value == "0")
        {
            return NULL;

        } else {

            return $value;
        }
    }

The response is,

[
  {
    "student_category_mapping_id": 1,
    "region_id": 1,
    "student_id": 1,
    "category_id": 11067,
    "category_id_round_two": null,
    "pref_cat_id": 11067,
    "project_number": null,
  },
  {
    "student_category_mapping_id": 6,
    "region_id": 44,
    "student_id": 6,
    "category_id": 11093,
    "category_id_round_two": null,
    "pref_cat_id": 11093,
    "project_number": null,
  },
  {
    "student_category_mapping_id": 7,
    "region_id": 2,
    "student_id": 6,
    "category_id": 11093,
    "category_id_round_two": null,
    "pref_cat_id": 11093,
    "project_number": null,
  },
  {
    "student_category_mapping_id": 8,
    "region_id": 44,
    "student_id": 7,
    "category_id": 11101,
    "category_id_round_two": null,
    "pref_cat_id": 11101,
    "project_number": null,
  },
  {
    "student_category_mapping_id": 10,
    "region_id": 44,
    "student_id": 8,
    "category_id": 11099,
    "category_id_round_two": null,
    "pref_cat_id": 11099,
    "project_number": null,
  },
  {
    "student_category_mapping_id": 2,
    "region_id": 2,
    "student_id": 2,
    "category_id": 11095,
    "category_id_round_two": null,
    "pref_cat_id": 11095,
    "project_number": "BCHM001MS",
  },
  {
    "student_category_mapping_id": 5,
    "region_id": 2,
    "student_id": 5,
    "category_id": 11094,
    "category_id_round_two": null,
    "pref_cat_id": 11094,
    "project_number": "BEHA001MS",
  },
  {
    "student_category_mapping_id": 4,
    "region_id": 2,
    "student_id": 4,
    "category_id": 11099,
    "category_id_round_two": null,
    "pref_cat_id": 11099,
    "project_number": "CHEM001MS",
  },
  {
    "student_category_mapping_id": 11,
    "region_id": 2,
    "student_id": 8,
    "category_id": 11099,
    "category_id_round_two": null,
    "pref_cat_id": 11099,
    "project_number": "CHEM002MS",
  },
  {
    "student_category_mapping_id": 9,
    "region_id": 2,
    "student_id": 7,
    "category_id": 11101,
    "category_id_round_two": null,
    "pref_cat_id": 11101,
    "project_number": "EAEV001MF",
  },
  {
    "student_category_mapping_id": 12,
    "region_id": 1,
    "student_id": 9,
    "category_id": 11061,
    "category_id_round_two": null,
    "pref_cat_id": 11061,
    "project_number": "ENMC001MS",
  },
  {
    "student_category_mapping_id": 3,
    "region_id": 2,
    "student_id": 3,
    "category_id": 11099,
    "category_id_round_two": null,
    "pref_cat_id": 11099,
    "project_number": "qwertyu",
  }
]

Here I want to apply orderby for column project_number and I want to display null values of the project_number column at last. non null values of project_number column should come first,

I tried code like below,

 return StudentMap::select(['*', DB::raw('project_number IS NULL AS projectnumberNull')])
                  ->orderBy('projectnumberNull','ASC')
                  ->orderBy('project_number')->get();

But no use,

I want the response like below,

[
{
    "student_category_mapping_id": 2,
    "region_id": 2,
    "student_id": 2,
    "category_id": 11095,
    "category_id_round_two": null,
    "pref_cat_id": 11095,
    "project_number": "BCHM001MS",
  },
  {
    "student_category_mapping_id": 5,
    "region_id": 2,
    "student_id": 5,
    "category_id": 11094,
    "category_id_round_two": null,
    "pref_cat_id": 11094,
    "project_number": "BEHA001MS",
  },
  {
    "student_category_mapping_id": 4,
    "region_id": 2,
    "student_id": 4,
    "category_id": 11099,
    "category_id_round_two": null,
    "pref_cat_id": 11099,
    "project_number": "CHEM001MS",
  },
  {
    "student_category_mapping_id": 11,
    "region_id": 2,
    "student_id": 8,
    "category_id": 11099,
    "category_id_round_two": null,
    "pref_cat_id": 11099,
    "project_number": "CHEM002MS",
  },
  {
    "student_category_mapping_id": 9,
    "region_id": 2,
    "student_id": 7,
    "category_id": 11101,
    "category_id_round_two": null,
    "pref_cat_id": 11101,
    "project_number": "EAEV001MF",
  },
  {
    "student_category_mapping_id": 12,
    "region_id": 1,
    "student_id": 9,
    "category_id": 11061,
    "category_id_round_two": null,
    "pref_cat_id": 11061,
    "project_number": "ENMC001MS",
  },
  {
    "student_category_mapping_id": 3,
    "region_id": 2,
    "student_id": 3,
    "category_id": 11099,
    "category_id_round_two": null,
    "pref_cat_id": 11099,
    "project_number": "qwertyu",
  },
  {
    "student_category_mapping_id": 1,
    "region_id": 1,
    "student_id": 1,
    "category_id": 11067,
    "category_id_round_two": null,
    "pref_cat_id": 11067,
    "project_number": null,
  },
  {
    "student_category_mapping_id": 6,
    "region_id": 44,
    "student_id": 6,
    "category_id": 11093,
    "category_id_round_two": null,
    "pref_cat_id": 11093,
    "project_number": null,
  },
  {
    "student_category_mapping_id": 7,
    "region_id": 2,
    "student_id": 6,
    "category_id": 11093,
    "category_id_round_two": null,
    "pref_cat_id": 11093,
    "project_number": null,
  },
  {
    "student_category_mapping_id": 8,
    "region_id": 44,
    "student_id": 7,
    "category_id": 11101,
    "category_id_round_two": null,
    "pref_cat_id": 11101,
    "project_number": null,
  },
  {
    "student_category_mapping_id": 10,
    "region_id": 44,
    "student_id": 8,
    "category_id": 11099,
    "category_id_round_two": null,
    "pref_cat_id": 11099,
    "project_number": null,
  },
  
]

Please help me with this.

Activity icon

Replied to Best Editor To Add Content For Journal Website

i want to show modal or tooltip window on click of link. any example?

Activity icon

Started a new Conversation Best Editor To Add Content For Journal Website

i am working on a journal website where we will post articles for journals and users can view the article data in HTML view.

TO add content to articles right now I am using ckeditor.

The problem is I should add links in text if the user clicks that text then it should scroll up/down for part a particular part of the page.

example:

resistance in BC cases.[15] In our study,

Here [15] is the link if the user clicks that it should scroll down to the div which matches a particular id. how to do this in ckeditor? or any other powerful and secured editors which you guys recommend?

Activity icon

Started a new Conversation Add Tooltip Or Modal In Ckeditor

Hello, Sorry for the out of topic.

I have ckeditor on textarea and if i add a link for a text i can only add the URL but i want to add a link when the user clicks that link it should show tooltip/model with custom data based on that text value. how can i do this?

Mar
30
1 week ago
Activity icon

Started a new Conversation How To Convert Mysql Column Content To Citation .ris File

I have a citation where I am storing citation content and now I want to convert it to citation file .ris format.

Mar
29
1 week ago
Activity icon

Replied to Implement Manual Email Verfication.

not only with email verification, but every user will also have their own dashboard like user dashboard, admin, and vendor. in this case, I have to extend the default authentication system.

If I use default laravel auth is there any link where I can manage the roles by overriding the default authentication? also in the future mobile verification will come as well.

Activity icon

Replied to Implement Manual Email Verfication.

@martinbean i have more than 3 to 4 role types if I write manually I can extend this without more complexity that's the reason. also when the user wants to update his email address I am using this approach.

Activity icon

Started a new Conversation Implement Manual Email Verfication.

I have manually created the registration controller code and now I want to add email verification after registration. I have some doubts about generating verification links. right now I am following like below,

  1. User completes the registration

then I have a code like the below in the registration controller method.

EmailVerification::where('user_id', $user->id)->delete();
$newtoken = \Password::broker()->getRepository()->createNewToken();

 EmailVerification::create(['user_id' => $user->id, 'email' => $new_email, 'token' => $newtoken,'generate_time'=> getexpirttimestamp(45)]);

  $mailer->sendNewEmailVerify(siteConfig('site_email'), $new_email, $newtoken);

The above code enters a new entry to the email_verification table.

mailer code is,

 /**
     * 
     * Deliver new email update token verify email.
     *
     * @param  User $user
     * @return void
     */
    public function sendNewEmailVerify($adminemail,$toemail,$token)
    {  
        $profileurl = url('profile'); 
        $messageval = "like";

        $this->to = $toemail;
        $this->from = $adminemail;
        $this->subject = "Verify New Email- ".siteName();
        $this->view = 'emails.verifynewemail';
        $this->data = ['token'=>$token];

        $this->deliver();
    }

in verify email blade I have link like below,

<a href="{{ url('verifynewemail') }}/{{ $token }}" class="button button-blue button-primary" target="_blank">Verify Email Address</a>

In controller,

public function verifyNewEmail($token) 
    {
        $currentdatetetime = getCurrentDateTime();

        $tokenCheck = EmailVerification::where('token',$token)
                        ->where('generate_time','>=',$currentdatetetime)
                        ->first();

        if(!$tokenCheck) {

            EmailVerification::where('token',$token)->delete();

            flash()->error('Link expired please update the email and try again.');


            return redirect('/forums');

        }

        $userUpdate = User::where('id',$tokenCheck->user_id)
                            ->update(['email'=>$tokenCheck->email,'email_verified_at'=>$currentdatetetime]);


        $tokenCheck->delete();

        flash()->success('Link Verified successfully and your email address has been updated. login again if you are not able to view profile.');

        return redirect('/profile');

    }

now I want to reduce the steps as there is a signed URL in laravel how can I use that? or is this more secure enough to continue this way?

Activity icon

Started a new Conversation Format To Proper Json Format And Display In Select Dropdown

i have a helper function like below,

function getCurrencyTypes()
  {
  $currencies =  {
  	"USD": {
  		"symbol": "$",
  		"name": "US Dollar",
  		"symbol_native": "$",
  		"decimal_digits": 2,
  		"rounding": 0,
  		"code": "USD",
  		"name_plural": "US dollars"
  	},
  	"EUR": {
  		"symbol": "€",
  		"name": "Euro",
  		"symbol_native": "€",
  		"decimal_digits": 2,
  		"rounding": 0,
  		"code": "EUR",
  		"name_plural": "euros"
  	},
  	"GBP": {
  		"symbol": "£",
  		"name": "British Pound Sterling",
  		"symbol_native": "£",
  		"decimal_digits": 2,
  		"rounding": 0,
  		"code": "GBP",
  		"name_plural": "British pounds sterling"
  	},
  	"INR": {
  		"symbol": "Rs",
  		"name": "Indian Rupee",
  		"symbol_native": "টকা",
  		"decimal_digits": 2,
  		"rounding": 0,
  		"code": "INR",
  		"name_plural": "Indian rupees"
  	},
  };

  return $currencies;
  }

I want to create a proper json format where I can use this in the blade to display the currency.

Mar
28
2 weeks ago
Activity icon

Replied to Validate Mobile Or Email

@sergiu17 if i want to add custom message for unique validation i can add like below right,

i tested below code it is working fine,

$validatormobile = Validator::make($request->all(), [ 
		      'emailphone' =>'required|regex:/^[6-9][0-9]{9}$/|digits:10|unique:users,mobile', 
    	],[
    		'emailphone.unique' => 'This Mobile number has already been taken.', 
    	]);
Activity icon

Replied to Validate Mobile Or Email

@sergiu17 Perfect thank you so much it worked.

Activity icon

Started a new Conversation Validate Mobile Or Email

i have a registration form with fields like below,

first_name,
last_name,
emailphone,
password,
password_confirmation,

Here user can enter either mobile number or email in emailphone field.

So my controller code is like below,

public function register(Request $request) 
  { 
    $validator = Validator::make($request->all(), [ 
      'first_name' => 'required', 
      'last_name' => 'required',
      'password' => 'required', 
      'password_confirmation' => 'required|same:password', 
    ]);
 
    if ($validator->fails()) { 
      return response()->json([ 'error'=> $validator->errors() ]);
    }

    $message = '';
    $data = [
	 	'first_name' => request('first_name'),
	 	'last_name' => request('last_name'),
	 	'role_id' => 2,
	 	'password' => bcrypt(request('password')),
	 	];

    if(is_numeric($request->get('emailphone'))){
    	
    	$validatormobile = Validator::make($request->all(), [ 
		      'emailphone' =>'required|regex:/^[6-9][0-9]{9}$/|digits:10|unique:users', 
    	]);

    	if ($validatormobile->fails()) { 
      		return response()->json([ 'error'=> $validatormobile->errors() ]);
    	}

    	$message = "OTP sent to registered mobile number. please check your mobile and enter here, and it is valid only for 60 min.";

    	$data['mobile'] = $request->get('emailphone');
            // return ['phone'=>$request->get('email'),'password'=>$request->get('password')];
    } else {

    	$validatoremail = Validator::make($request->all(), [ 
		      'emailphone' =>'required|email|unique:users', 
    	]);

    	if ($validatoremail->fails()) { 
      		return response()->json([ 'error'=> $validatoremail->errors() ]);
    	}

    	$message = "OTP sent to registered email. please check your email and enter here, and it is valid only for 60 min.";

    	$data['email'] = $request->get('emailphone');
    }
 	
	
	 $user = User::create($data); 
	 // $newtoken = \Password::broker()->getRepository()->createNewToken();

	 OtpConfirm::where('user_id',$user->id)->delete();

	 $otpdata = generateOtp($user->id);

	 if($otpdata)
	 {
	 
	 	return response()->json(['info'=>$message,'token'=>$otpdata->token], 500);
	 } else {

	 	return response()->json(['info'=>'Something went wrong. try again.'], 500);
	 }

  }

But here the problem is validation giving below errors,

Column not found: 1054 Unknown column 'emailphone' in 'where clause'

User table has below columns,

id, first_name,last_name,mobile,email,password

Here if emailphone is numeric then i should validate for mobile number and store in mobile column and if it is not numeric then i should validate for email and should store in email column.

How to do this?

Mar
23
2 weeks ago
Activity icon

Replied to Provide Both API Passport Authentication And Default Session Auth

Thank you for the clarification :-)

Mar
22
2 weeks ago
Activity icon

Started a new Conversation Provide Both API Passport Authentication And Default Session Auth

i have admin dashboard where admin can manage the website and here i am using default Auth::attempt for login purpose and it is session based. same application has api routes where i should share api for reactjs for login and register purpose (i am planning to use passport for this). how to combine both and does this affect normal login flow if i install passport and make necessary changes for User mode?

Mar
19
3 weeks ago
Activity icon

Started a new Conversation Set Authorization For Laravel API Call From Reactjs

i have api like below,

https://example.com/api/posts

this will display all posts in json format when we access this URL directly in browser or postman.

i am sharing this api to react js. right now there is no user authentication as this is open access website. but I want it to be only consumed by my application (reactjs), and prevent someone from the public access this api. Anyway to achieve this?

i have one approach like below,

create api key table in database and store str_random token. pass this this api key from reactjs axios header as authorization key

create one middleware where it will fetch authorization key header value and match with db key token and if it is same allow if not block.

is this fine?

Activity icon

Replied to Session Variable Not Fetching In Listener

@snapey Thank you for the suggestions it reduced some functions.

and i have altered code like below,

session(['timezone' => $request->timezone]); // saving to session
session()->save();

But still it is not taking and can i do like this?

creating timezone column in user table and whenever user logged in update the timezone column of user and later in listener fetch the timezone from column instead of session?

also if i store created_at in LoginActivity in UTC format and i want to display the last created_at date based on user timezone. i tried to set timezone dynamically using helper during fetch but it is not working.

function getLastLoginTime()
{
	$timezone = !is_null($event->user->timezone) ? $event->user->timezone : 'UTC';
     config(['app.timezone' => $timezone]);
      date_default_timezone_set($timezone);
  $user_id = Auth::user()->id;
  $getLatestLogin = LoginActivity::where('user_id',$user_id)->orderBy('id','DESC')->first();
  return $getLatestLogin;
}

Activity icon

Started a new Conversation Session Variable Not Fetching In Listener

I am try to store login activity along with user timezone i have code like below,

in login page i have used below jquery cdn,

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.33/moment-timezone-with-data.min.js" crossorigin="anonymous"></script>

i have input field with hidden type like below and script to append client timezone,

  <input type="hidden" name="timezone" id="timezone">
<script>
  var timezone = moment.tz.guess();
  $('#timezone').val(timezone);
</script>

i have login code like below. i set timezone in session.

public function postAdminLoginPage(Request $request)
      {
        
        request()->validate([
            'email' => 'required|email',
            'password' => 'required',
        ]);

          $credential = [
            'email' => request('email'),
            'password' => request('password'),
            'role_id' => 1
          ];

        $remember_me  = ( !empty( $request->remember_me ) )? true : false;

        if(Auth::attempt($credential,$remember_me)){
            session(['timezone' => $request->timezone]); // saving to session

            return redirect('admin/dashboard');
        } else {
          return redirect('adminlogin')->withErrors('Email/Password is wrong. try again');
        }
      }

Now after login i am storing login activity in login_activities table

i have table like below,

login_activities

id, user_id, ip, user_agent, timezone

EventServiceProvider.php

'Illuminate\Auth\Events\Login' => [
        'App\Listeners\LogSuccessfulLogin',
    ],

inside Listeners i have file called, LogSuccessfulLogin.php

public function handle(Login $event)
    {
        //
        LoginActivity::create([
          'user_id'       =>  $event->user->id,
          'user_agent'    =>  \Illuminate\Support\Facades\Request::header('User-Agent'),
          'ip_address'    =>  \Illuminate\Support\Facades\Request::ip(),
          'timezone'      =>  getTimezone(),
        ]);
    }

In helper.php i hav function like below,

function getTimezone()
{
  return (Session::has('timezone') ? Session::get('timezone') : 'UTC');
}

But i am not able to fetch the session variable in listeneres. if i test in seperate route it is displaying properly. may be it will take one refresh. how to this session variable to listers so that i will store in activity to display the last login date based on timezone.

Mar
10
1 month ago
Activity icon

Replied to Format Categories And All Child Categories In Array

@michaloravec @awsqed Perfect it worked. thank you so much. if you don't mind please explain this part @awsqed

$model = $model ?? $this;

        $result = [];

        if ($model !== $this) {
            array_push($result, $model->id);
        }

and if i want to add main parent category id in children array i can remove this condition right?

//if ($model !== $this) { //remove this
            array_push($result, $model->id);
        //}
Mar
09
1 month ago
Activity icon

Replied to Format Categories And All Child Categories In Array

@michaloravec perfect it is working fine for first level but what if on category has children and this children has another level i want all children id in the same array for example,

Event managment is main category and it has a child category with name "Event Organizer"

now child category Event Organizer has another child category with name "event organizers 1"

now the main category Event managment should have an array with both ['Event Organizer id','event organizers 1 id']

Please help me with this.

Activity icon

Started a new Conversation Format Categories And All Child Categories In Array

i have a query like below,

$categories = Category::with('children')->where('parent_id',0)->where('status',1)->get();

the response is,

[
  {
    "id": 12,
    "name": "Event Management",
    "status": "1",
    "parent_id": "0",
    "image": "categoryimage_1607426054.jpg",
    "slug": "event-management",
    "created_at": "2020-01-07 17:23:50",
    "updated_at": "2021-03-04 19:41:08",
    "children": [
      {
        "id": 13,
        "name": "Event Organizer",
        "status": "1",
        "parent_id": "12",
        "image": null,
        "slug": "event-organizer",
        "created_at": "2020-01-07 17:24:52",
        "updated_at": "2020-01-07 17:24:52",
        "children": [
          {
            "id": 192,
            "name": "event organizers 1",
            "status": "1",
            "parent_id": "13",
            "image": null,
            "slug": "event-organizers-1",
            "created_at": null,
            "updated_at": null,
            "children": []
          }
        ]
      },
      {
        "id": 14,
        "name": "Wedding Planner",
        "status": "1",
        "parent_id": "12",
        "image": null,
        "slug": "wedding-planner",
        "created_at": "2020-01-07 17:26:03",
        "updated_at": "2020-01-07 17:26:03",
        "children": []
      },
      {
        "id": 18,
        "name": "Event managers",
        "status": "1",
        "parent_id": "12",
        "image": null,
        "slug": "event-managers",
        "created_at": "2020-01-29 15:37:52",
        "updated_at": "2020-01-29 15:37:52",
        "children": []
      },
      {
    	"id": 12,
        "name": "Celebrity Management",
        "status": "1",
        "parent_id": "12",
        "image": null,
        "slug": "celebrity-management",
        "created_at": "2020-01-29 15:39:04",
        "updated_at": "2020-01-29 15:39:04",
        "children": []
      },
]

Here i want to format above response like below,

[
  {
    "id": 12,
    "name": "Event Management",
    "status": "1",
    "parent_id": "0",
    "image": "categoryimage_1607426054.jpg",
    "slug": "event-management",
    "created_at": "2020-01-07 17:23:50",
    "updated_at": "2021-03-04 19:41:08",
    "children": [13,192,14,18,12]

	}
]

i want to get all child categories in one array inside each category. any help?

Activity icon

Started a new Conversation Display Only Active Categories Based On City

i have table structures like beloe,

categories

id, name,slug,parent_id

store_categories

id, store_id,category_id,order_id

stores

id, storename,slug,city_id,address,user_id

orders

id,user_id,from_date,to_date,txn_id,date,

Here if user select a city then i should display only active categories.

i will get category and children with below code,

Category::with(['children')->where('parent_id',0)->where('status',1)->get();

Category.php

public function children()
    {
    return $this->hasMany('\App\Category','parent_id')->with('children');
    }

public function nestedStructure()
    {
      $today_date = date('Y-m-d');
       return $this->children()->with([
             'nestedStructure',
             'getstores' => function($q) use($today_date) {
               
              $q->join('orders','store_categories.order_id','=','orders.id')
              ->where('orders.from_date','<=',$today_date)
              ->where('orders.to_date','>=',$today_date);
             },
       ]);
    }

and in controller i have code like below,

return $getCategories = Category::with(['nestedStructure'])->where('parent_id',0)->where('status',1)->get();

But here how to pass city id to model as a parameter as i am not getting how to add city_id where condition for getstores

Mar
08
1 month ago
Activity icon

Replied to Remove Empty Relationsip Data From Response

@michaloravec thank you for the reply. but still i am getting old response,

i have models like below,

Category.php

public function getstores()
    {
      return $this->belongsToMany('\App\Store','store_categories');
    }

Store.php

public function orderdetails()
    {
      return $this->hasMany('App\Order','user_id','user_id');
    }

here getstores is belongsto many and it has nested hasMany relation.

Activity icon

Started a new Conversation Remove Empty Relationsip Data From Response

I have a query like below,

$getCategories = Category::with(['getstores'=> function($q) {
                                $q->where('status',1);
                            }, 'getstores.orderdetails'=> function($q) use($today_date) {
                                    $q->where('from_date','<=',$today_date)
                                    ->where('to_date','>=',$today_date);
                            }])->where('status',1)->where('parent_id',0)->get();

and below is the response,

[
  {
    "id": 12,
    "name": "Event Management Company",
    "status": "1",
    "parent_id": "0",
    "image": "categoryimage_1608041864.jpg",
    "slug": "event-management-company",
    "created_at": "2020-01-07 17:23:50",
    "updated_at": "2020-12-15 19:47:44",
    "getstores": [
      {
        "id": 44,
        "title": "Vinn Events",
        "store_slug": "vinn-events-2",
        "description": "<p>Event Management</p>",
        "user_id": "81",
        "city_id": "1",
        "area_id": "23",
        "state_id": "1",
        "address": "address",
        "cover_photo": "1588048303.jpg",
        "contact_numbers": "",
        "main_phone": "",
        "website": "",
        "year_established": "2010",
        "banner_image": null,
        "status": "1",
        "feature": "0",
        "created_at": "2020-04-28 10:01:43",
        "updated_at": "2020-04-28 10:01:49",
        "pivot": {
          "category_id": "12",
          "store_id": "44"
        },
        "orderdetails": []
      },
      {
        "id": 46,
        "title": "A1 Events & Addworld",
        "store_slug": "a1-events-addworld",
        "description": "<p>We organize all types of decorations, marriage events, birthday party&#39;s &amp; school events</p>",
        "user_id": "84",
        "city_id": "1",
        "area_id": "47",
        "state_id": "1",
        "address": "address",
        "cover_photo": "1588052198.jpg",
        "contact_numbers": "",
        "main_phone": "",
        "website": null,
        "year_established": null,
        "banner_image": null,
        "status": "1",
        "feature": "0",
        "created_at": "2020-04-28 11:06:38",
        "updated_at": "2020-04-28 11:06:38",
        "pivot": {
          "category_id": "12",
          "store_id": "46"
        },
        "orderdetails": [
          {
            "id": 48,
            "user_id": "84",
            "package_id": "4",
            "mode": "Cash",
            "cheque_date": "1970-01-01",
            "cheque_no": null,
            "bank_name": null,
            "reference_no": null,
            "amount": "365.00",
            "txn_id": null,
            "status": "Success",
            "from_date": "2020-04-28",
            "to_date": "2021-04-28",
            "created_at": "2020-04-28 11:03:05",
            "updated_at": "2020-04-28 11:03:05"
          }
        ]
      },
]

Here in first part of response orderdetails array is empty and in second part it is present so i want filter out first one becuase orderdetails is empty. where to use the whereHas for this as i am using nested realtionsip? i want to skip the data which orderdetails in empty.

Mar
05
1 month ago
Activity icon

Replied to Fetch Wordpress Posts And Other Details And Display In Laravel Admin

@snapey Thank you. Yes i have database access and after connecting the db to laravel application, i am planning to create api in laravel where it will display posts, categories etc and sharing laravel api for mobile app development is better idea right?

Activity icon

Started a new Conversation Fetch Wordpress Posts And Other Details And Display In Laravel Admin

i want to fetch the wordpress posts, count and other details and display in laravel admin dashboard where admin can see the posts. i have two options to do this

  1. using default REST api. example : https://www.example.com/wp-json/wp/v2/posts

using Guzzle fetch details of above api

  1. creating new db configuration in laravel and create new connection and fetch details.

which way is better when considering the security and speed

Also i should work on API for mobile APP too. shall i share the same default wordpress API for mobile app too?

Any suggestions?

Mar
04
1 month ago
Activity icon

Replied to Writing Query Inside Map

Thanks for the reply. and here i have to match based on column values and put where condition thats why i have used join here. can i right it in nested where condition?

Activity icon

Started a new Conversation Writing Query Inside Map

i am trying to display category based exam stats display using below query,

$categoryDetails = QuestionCategory::whereIn('question_category_id',$categories)->get();

        $sortcollection = $categoryDetails->map( function($category) use($test_id,$user_test_id,$user_tests_det) {

            $catcorrectCount = UserAnswer::join('questions','user_answers.question_id','=','questions.question_id')->where('questions.test_id',$test_id)->where('questions.language',$user_tests_det->test_language)->where('user_answers.user_test_id',$user_test_id)->where('questions.question_category',$category->question_category_id)->whereRaw('user_answers.user_answer = questions.correct_option')->count();
            
            $catincorrectCount = UserAnswer::join('questions','user_answers.question_id','=','questions.question_id')->where('questions.test_id',$test_id)->where('questions.language',$user_tests_det->test_language)->where('user_answers.user_test_id',$user_test_id)->where('questions.question_category',$category->question_category_id)->whereRaw('user_answers.user_answer != questions.correct_option')->count();
            
            $cattotalAttempted = UserAnswer::join('questions','user_answers.question_id','=','questions.question_id')->where('questions.test_id',$test_id)->where('questions.language',$user_tests_det->test_language)->where('questions.question_category',$category->question_category_id)->where('user_answers.user_test_id',$user_test_id)->count();

            $cattotalQuestion = Question::where('test_id',$test_id)->where('language',$user_tests_det->test_language)->where('question_category',$category->question_category_id)->count();


            $catmarksDetails = json_decode($this->getMarksScoredDetailsTrait($user_tests_det,$cattotalQuestion,$catcorrectCount,$catincorrectCount),true);

            $cat_not_answer = $cattotalQuestion - $cattotalAttempted;

            return [
                'category_id' => $category->question_category_id,
                'category_name' => $category->question_category_name,
                'catcorrectCount' => $catcorrectCount,
                'catincorrectCount' => $catincorrectCount,
                'cattotalAttempted' => $cattotalAttempted,
                'cattotalQuestion' => $cattotalQuestion,
                'catnotattempted' => $cat_not_answer,
                'cattotalmarks' => $catmarksDetails['totalMarks'],
                'catmarksscored' => $catmarksDetails['marksScored'],
            ];

        });

Here the concept is every question has a single category and i am displaying category based stats like category 1 => correct , incorrrect, not attempted, total marks etc.

i have used queries inside the map and i am getting proper result but i want to know is this correct way to do this? any improvisations?