Hadayat

Member Since 1 Year Ago

Mianwali

Experience Points
2,010
Total
Experience

2,990 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
3
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 1
2,010 XP
Apr
09
4 days ago
Activity icon

Replied to Hot Reload When Login Using Vuejs

I am using the Laravel sanctum for authenticating the SPA, but for now, I did not implement this for component, user can access every component without authentication

Activity icon

Replied to Hot Reload When Login Using Vuejs

@trin I used this but it not work for me

Activity icon

Started a new Conversation Hot Reload When Login Using Vuejs

I am login in using vuejs in Laravel, when I pushed from login to dashboard, my sidebar widgets are not working, when I hot reload them by F5 then it works. I find many solutions how to rerender the dom in vuejs I follow this approach but still sidebar widgets are not working

export default {
    data:function(){
        return{
             componentKey: 0,
        }
    },
    mounted(){
        forceRerender() {
      this.componentKey += 1;
    }
    }
}
Apr
08
5 days ago
Activity icon

Replied to Issuing Token For SPA And Got Unauthenticated

@jlrdw Can you please tell me what is the issue

Activity icon

Started a new Conversation Issuing Token For SPA And Got Unauthenticated

I am generating a token for Vuejs SPA and when I make a request to the login with the valid credentials it says you are unauthenticated, I also test it on the POST man but still, it's not working.

Without sanctum middleware, authentication working perfectly but when I add the sanctum middleware it say's authenticated, even I pass the bearer XSRF-TOKEN but nothing is going to work.

Login.vue

login(){
           axios.get('/sanctum/csrf-cookie').then(response => {
                this.form.post('api/teacher/login')
                .then( response => {
                    if(response.status == 201){
                    this.$router.push({ name: 'Dashboard'});
                    }
                })
                .catch( error => {
                    console.log( error );
                })
            });
        }

api.php

Route::prefix('/teacher')->group(function(){
    Route::middleware('auth:sanctum')->post('/login', 'Teacher\[email protected]')->name('teacher.login');
});

RegisterController.php

public function login(Request $request)
    {
        $credentials = $request->only('email', 'password');

        if(Auth::attempt($credentials)){
          return response()->json([
              'message'=>'Login Successfully.'
          ],201);
        }
        else{
            return response(['Message'=>'Wrong Credintals'], 400);
        }
    }

I think my token is not generating correctly that's why it says unauthenticated, what you say please share your experience. I am very thankful to you. @snapy

Feb
28
1 month ago
Activity icon

Started a new Conversation Generating Mutliple Pdf Files But Only One Is Generated

I want to generate multiple files using mpdf library, but unfortunately, only one file is generated, instead of multiple, how can I do this. Thanks for showing your interest.

 for ($i=1; $i<count($sheetData); $i++)
 {
                      $name = $sheetData[$i][0];
                      $fName = $sheetData[$i][1];
                      
                      $mpdf = new \Mpdf\Mpdf(['mode' => 'utf-8', 'format' => [290, 236]]);
                      $stylesheet = file_get_contents('../assets/css/style.css');
                      $mpdf->WriteHTML($stylesheet, \Mpdf\HTMLParserMode::HEADER_CSS);
                      ob_end_clean();
                       
                      $html = $mpdf->WriteHTML('<p>My Layout is there</p>');
                      $filename = time().'.pdf';
                      $mpdf->Output($filename ,'D');
                      unset($mpdf);
}
Feb
21
1 month ago
Activity icon

Started a new Conversation Generate QR Code Which Expire After Specific Date

I am using PHP and creating a project where I need the barcode, I want to make it available at a specific time. I want to add a date picker where I add the starting date and ending date, when the due date is passed, the barcode will not be able to read again. (expire).

I already generated the code but I want to make it expirable, any idea how can I do this. If there is any lib, please suggest it to me.

Feb
05
2 months ago
Activity icon

Replied to Authenticating A SPA Using Laravel But Getting 401 Unauthenticated User.

I already did this to true. Yes I checked it without middleware it successfully logged in but when I put the middleware inside the route it says unauthenticated. Can you please drop your email so I'll contact you by email?

Activity icon

Replied to Authenticating A SPA Using Laravel But Getting 401 Unauthenticated User.

@martinbean Have you any more suggestion. I am stuck on this part.

Activity icon

Replied to Authenticating A SPA Using Laravel But Getting 401 Unauthenticated User.

@khalilm I set my web path in cors.php, also tried with api.php(I put my routes inside the api.php) This is my core file path:

'paths' => ['api/*'],

Still the same issue.

Feb
04
2 months ago
Activity icon

Replied to Authenticating A SPA Using Laravel But Getting 401 Unauthenticated User.

This is the response of the cookie.

Request URL: http://localhost:8000/sanctum/csrf-cookie
Request Method: GET
Status Code: 204 No Content
Remote Address: 127.0.0.1:8000
Referrer Policy: strict-origin-when-cross-origin
Cache-Control: no-cache, private
Connection: close
Date: Thu, 04 Feb 2021 14:36:09 GMT
Date: Thu, 04 Feb 2021 14:36:09 GMT
Host: localhost:8000
Set-Cookie: XSRF-TOKEN=eyJpdiI6IlZXTHdEWlN4bWp4QXJkK0d4dFJZdmc9PSIsInZhbHVlIjoiQlVVMHRBTEY3ZmxBdTZCOVpOUDQ3NVdoTG9DTURIWDN3QjEwSnRwUkMwbURqRWIrTXk0Q3JTSWQ4YXVKclFVS050ME1pOHFubVI0TG5UV0ZSVUNhSjFVZkx0OWp3SkhZWWJNTk1aNjUzNysyeXVMN0w4eVFRNXNhZEFWV3NVb2giLCJtYWMiOiJhZDAxMmIwZTc0NTI4YTNlNTQwYTZjNDY5ZjI5MTQzZThiN2JhM2NjNTU5NTA3OTI1MWVkOWZmMWUyZGEzMjgzIn0%3D; expires=Thu, 04-Feb-2021 16:36:09 GMT; Max-Age=7200; path=/; samesite=lax
Set-Cookie: laravel_session=eyJpdiI6Ik1Wc2I3WW9RT0tMeGRaWnBmNjhXb0E9PSIsInZhbHVlIjoiQjQ0bmk1bWdxTFczVlJnK1JUNlJVN2hDdWRyU3ZrR2VSL0N5UFVENDZpN3Vna09meTJ3UFNIR0VSKzlSTEZCakpaeFhiOEVFM1BjWkpVNnR2U1BlalBrZk9BTzk3WTZaSGxKbTRzYTY1K2FFdXVhWVk1VGNQYU0zRlc1cFYveWkiLCJtYWMiOiIyZjNlY2E5ODAwZWM4NDZjODA5MGQxZTc4ZjExY2Q5YTA1NDEzYjlhMjJlMTNjODQ2ZGVkOTBmYjU0OGI1YWEzIn0%3D; expires=Thu, 04-Feb-2021 16:36:09 GMT; Max-Age=7200; path=/; httponly; samesite=lax
X-Powered-By: PHP/7.4.8

But it still says unauthenticated.

Activity icon

Replied to Authenticating A SPA Using Laravel But Getting 401 Unauthenticated User.

When I am going to login with the correct credentials, in the network tab it says the unauthenticated request.

Activity icon

Started a new Conversation Authenticating A SPA Using Laravel But Getting 401 Unauthenticated User.

Laravel Sanctum is successfully installed and setup too.

Web.php

 Route::middleware('auth:sanctum')->post('/login', 'Teacher\[email protected]')->name('teacher.login');

Controller.php

public function login(Request $request)
    {
        $credentials = [
            'email' => $request['email'],
            'password' => $request['password'],
        ];

        if(Auth::attempt($credentials)){
            return "Success";
        }else{
            return response()->json([
                "error"=>"User does't exists"
            ]);
        }
    }

Login.vue

login(){
            axios.get('/sanctum/csrf-cookie').then(response => {
                this.form.post('/login')
                .then( response => {
                    console.log(response);
                })
                .catch( error => {
                    console.log( error );
                })
            });
        }

console response

{data: "", status: 204, statusText: "No Content", headers: {…}, config: {…}, …}

I am following the official doc, so Implemented everything which is needed but it still says unauthenticated, console response determines that my cookie is set. What is an error, what's going wrong

Jan
27
2 months ago
Activity icon

Replied to Possible Reasons For " Cannot Redefine Property " Error ?

This is happening because you added this script two times.

 <script src="{{ asset('js/app.js') }}" defer></script>
Jan
22
2 months ago
Activity icon

Replied to How To Listen An Event On Non Parent Child Component In Vuejs

Thanks, man you saved my day, God bless you.

Activity icon

Started a new Conversation How To Listen An Event On Non Parent Child Component In Vuejs

I've created a component that is getting the searched value, I want to pass this value to a component that is rendered when we click on the navbar and the component is rendered. This rendered component is not a parent or child of any component. Then how can I pass the searched value to this component?

Jan
21
2 months ago
Activity icon

Replied to Getting Null From Laravel Gate

@armani My DB column type is boolean. Even I passed the return true in Gate but it's not authorizing me in the controller. it's working in the blade.

Activity icon

Replied to Getting Null From Laravel Gate

I already did this with all of your same syntaxes. I tried it with Laravel blades with can property it's working but it's not working in the controller. authorize method is not working for me. Can you suggest why it's not working?

Activity icon

Replied to Laravel Auth Showing Wrong User

OK, please share the full code.

Activity icon

Started a new Conversation Getting Null From Laravel Gate

I want to authorize the user to perform some action so that's why I define the gate in Laravel. AuthServiceProvider

public function boot()
    {
        $this->registerPolicies();

        Gate::define('isAdmin', function ($user) {
            return $user->type === 'admin';
        });
    }

controller

Gate::authorize('isAdmin');

I also tried

if(Gate::allows('isAdmin')){
// not going to work
}
Activity icon

Replied to Laravel Auth Showing Wrong User

@adityar15 remove the label from the details array and try it.

Jan
16
2 months ago
Activity icon

Awarded Best Reply on Installed Laravel Sanctum But Faced A Weird Error During Creating Token

I am answering my self because I found a solution

In Laravel Sanctum documentation, they added the passport class at the top so that's why I unfortunately added the passport class at the top. like below

use App\Models\Passport\PersonalAccessToken;
use Laravel\Sanctum\Sanctum;

When I remove this passport class my code works successfully. documentation link:

https://laravel.com/docs/8.x/sanctum#issuing-mobile-api-tokens
Activity icon

Replied to Installed Laravel Sanctum But Faced A Weird Error During Creating Token

I am answering my self because I found a solution

In Laravel Sanctum documentation, they added the passport class at the top so that's why I unfortunately added the passport class at the top. like below

use App\Models\Passport\PersonalAccessToken;
use Laravel\Sanctum\Sanctum;

When I remove this passport class my code works successfully. documentation link:

https://laravel.com/docs/8.x/sanctum#issuing-mobile-api-tokens
Activity icon

Started a new Conversation Installed Laravel Sanctum But Faced A Weird Error During Creating Token

I installed the Laravel sanctum for creating token, but when I am going to create a API token I faced this error:

Error: Class 'App\Models\Passport\PersonalAccessToken' not found in file E:\Laravel-WebApps\Vue-CMS\vendor\laravel\sanctum\src\Guard.php on line 63

Even I did not install the Laravel passport.

User Model

use Laravel\Sanctum\HasApiTokens;
use Notifiable, HasApiTokens;

API Route

Route::middleware('auth:sanctum')->get('/user-profile', 'Admin\API\[email protected]');

User Controller

public function profile(Request $request)
    {
        return auth('sanctum')->user();
        or 
        return auth('api')->user();
    }

auth.php

'api' => [
            'driver' => 'token',
            'provider' => 'users',
            'hash' => false,
        ],

Profile Vue

mounted(){
            axios.get('/api/user-profile')
            .then( response => {
                console.log( response );
            })
            .catch( error => {
                console.log( error );
            } )
        }

composer.json

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.2.5|^8.0",
        "fideloper/proxy": "^4.4",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^6.3.1|^7.0.1",
        "laravel/framework": "^7.29",
        "laravel/sanctum": "^2.8",
        "laravel/tinker": "^2.5",
        "laravel/ui": "2.4"
    },
    "require-dev": {
        "facade/ignition": "^2.0",
        "fakerphp/faker": "^1.9.1",
        "mockery/mockery": "^1.3.1",
        "nunomaduro/collision": "^4.3",
        "phpunit/phpunit": "^8.5.8|^9.3.3"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "autoload": {
        "psr-4": {
            "App\": "app/"
        },
        "classmap": [
            "database/seeds",
            "database/factories"
        ]
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true,
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    }
}

AppServiceProvider

public function boot()
    {
        Sanctum::usePersonalAccessTokenModel(PersonalAccessToken::class);
    }

In the console, it always returns unauthenticated

And when I am going to create an API token using tinker it throws this above error. Any suggetion

Jan
12
3 months ago
Activity icon

Replied to How To Close Modal From Vue Method ?

This is the simplest answer, I tried it and it works like a charm :)

https://stackoverflow.com/questions/56177694/bootstrap-modal-hide-from-vue-method
Nov
24
4 months ago