kumar92varun

kumar92varun

Member Since 2 Years Ago

Experience Points
790
Total
Experience

4,210 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
6
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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.

Level 1
790 XP
19 Aug
1 year ago

kumar92varun left a reply on CORS Access-Control-Allow-Origin Headers Not Being Added In Api Subdomain

@haizone Initially I was using core PHP to convert the data as JSON response and then echo it:

    $api_response = json_encode($return_data);
    echo $api_response;

I was not using Laravel's inbuilt functionality to return API responses as JSON. As I started using Laravel's JSON Responses method (https://laravel.com/docs/5.6/responses#json-responses), my API responses started to add all the headers I was expecting to be added:

    return response()->json($return_data);
14 Dec
1 year ago

kumar92varun left a reply on Laravel Session Helper Always Returning Null For First Time On Page

I fixed the problem by commenting the "Encrypt Cookies" middleware in /app/Http/Kernel.php:-

// \App\Http\Middleware\EncryptCookies::class,

After commenting the above middleware, here's how my Kernel looks like:-

protected $middlewareGroups = [
    'web' => [
        //\App\Http\Middleware\EncryptCookies::class,
        \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
        \Illuminate\Session\Middleware\StartSession::class,
         \Illuminate\Session\Middleware\AuthenticateSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        \App\Http\Middleware\VerifyCsrfToken::class,
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
    ],

    'api' => [
        'throttle:60,1',
        'bindings',
    ],
];

Thanks all for your answers!

13 Dec
1 year ago

kumar92varun left a reply on Laravel Session Helper Always Returning Null For First Time On Page

Hey Kishore, Thanks for your answer.

The first line:-

$session = session('paramount', []);

Is trying to get the value of session key "paramount", and the second argument [] is the default value supplied if the session key "paramount" doesn't exists. []

Anyways I removed the second argument, the first var_dump output changed to NULL instead of array(0) {}

Every time on a page hit the session global helper returning NULL for the key "paramount".

kumar92varun started a new conversation Laravel Session Helper Always Returning Null For First Time On Page

I am using Session via File driver in Laravel 5.5. The issue is that on every page request I check if session key "paramount" is set or not (for first time visit by the visitor). If not, I am setting the session and if it exists, it should not do anything. Here is the code for the same:-

$session = session('paramount', []);
var_dump($session);
if(empty($session))
{
    initSession();
}
var_dump($session);


function initSession()
{
    session(['paramount.user' => [
        'loggedIn' => 0,
        'id' => null,
        'fullName' => null,
        'firstName' => null
    ]]);

    session(['paramount.cart' => [
        'products' => [],
        'summary' => [
            'noOfProducts' => 0,
            'productTotal' => 0
        ]
    ]]);
}

The output of the above code is:-

    array(0) { }
    array(2) { ["user"]=> array(4) { ["loggedIn"]=> int(0) ["id"]=> NULL ["fullName"]=> NULL ["firstName"]=> NULL } ["cart"]=> array(2) { ["products"]=> array(0) { } ["summary"]=> array(2) { ["noOfProducts"]=> int(0) ["productTotal"]=> int(0) } } }

This output means that for the first visit (when session wasn't setup) the var_dump shows empty array, and after setting the session for key "paramount", it shows dump as expected.

When I refresh the page, I should expect that the session has been setup and the first time var_dump should show result as:-

array(2) { ["user"]=> array(4) { ["loggedIn"]=> int(0) ["id"]=> NULL ["fullName"]=> NULL ["firstName"]=> NULL } ["cart"]=> array(2) { ["products"]=> array(0) { } ["summary"]=> array(2) { ["noOfProducts"]=> int(0) ["productTotal"]=> int(0) } } }
array(2) { ["user"]=> array(4) { ["loggedIn"]=> int(0) ["id"]=> NULL ["fullName"]=> NULL ["firstName"]=> NULL } ["cart"]=> array(2) { ["products"]=> array(0) { } ["summary"]=> array(2) { ["noOfProducts"]=> int(0) ["productTotal"]=> int(0) } } }

But on every page refresh the first time var_dump of session key "paramount" shows an empty array.

array(0) {}

And second dump as expected:-

array(2) { ["user"]=> array(4) { ["loggedIn"]=> int(0) ["id"]=> NULL ["fullName"]=> NULL ["firstName"]=> NULL } ["cart"]=> array(2) { ["products"]=> array(0) { } ["summary"]=> array(2) { ["noOfProducts"]=> int(0) ["productTotal"]=> int(0) } } }

Don't know why this is happening, can someone help?

05 Nov
1 year ago

kumar92varun left a reply on CORS Access-Control-Allow-Origin Headers Not Being Added In Api Subdomain

I updated the question. Now the question is complete.

kumar92varun started a new conversation CORS Access-Control-Allow-Origin Headers Not Being Added In Api Subdomain

I am creating a multi-sub-domain web application using Laravel 5.5 with 3 sub-domains right now:- store.example.com admin.example.com api.example.com

Since store.example.com and admin.example.com need to interact with api.example.com for all the back-end operations via jQuery AJAX, I need to add a "Access-Control-Allow-Origin" header on all requests of api.example.com

I created a middleware in /app/Http/Middleware/CORS.php with the following content:-

<?php

namespace App\Http\Middleware;
use Closure;
class CORS
{
    public function handle($request, Closure $next)
    {
        $response = $next($request);
        $response->header('Access-Control-Allow-Origin' , '*');
        $response->header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE');
        return($response); 
    }
}
?>

And registered it in /app/Http/Kernel.php under:-

protected $middleware = [
    ...
    ...
    ...
    \App\Http\Middleware\CORS::class,
];

I have also disabled the VerifyCsrfToken Middleware from Kernel. I don't want to use CSRF protection, at least for now.

The main issue is that my store and admin sudbomain are successfully having the above headers on all GET / POST requests, but not the api subdomain. Don't know what's wrong, but api subdomain won't add these headers in any of it's GET or POST request.

Can someone please tell me what's going wrong in adding the above headers in api subdomain particularly when it's working great with every other subdomain?

Thanks.