ahsan

Member Since 4 Years Ago

Pakistan

Experience Points 150,150
Experience Level 31

4,850 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 1444
Lessons
Completed
Best Reply Awards 3
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

05 Mar
3 weeks ago

ahsan left a reply on How To Mass Assignment Exception Globally For All Models

you can add Model::unguard(); in AppServiceProvider.php boot method.

like this:

<?php

namespace App\Providers;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Model::unguard();
    }
}

ahsan left a reply on I Cant Retrieve Authenticated User Data

you can get authenticated user data anywhere like this

auth()->user()

ahsan left a reply on How To Create Laravel Login With Username And Email Both

here is i have created gist for laravel login with username, email and mobile at same time.

hope it will help you.

https://gist.github.com/AhsanAbrar/2288d03af80cbfd6781370e59cc5003d

03 Feb
1 month ago

ahsan left a reply on Lazy Loading Vue Components And Laravel-mix Issue

you need to add this plugin in .babelrc

npm install -D @babel/plugin-syntax-dynamic-import

"plugins": ["@babel/plugin-syntax-dynamic-import"]

ahsan started a new conversation Can We Skip Default Create For Resource In Laravel Nova?

hi,

i want to customize default resource create request.

i know we can use observer to do some extra functionality.

there are possible to skip default create in database?

28 Jan
1 month ago

ahsan left a reply on Composer Very Slow On Windows

same here, anybody has solution for it?

ahsan left a reply on Want To Block Multiple Logins

that's awesome.

ahsan left a reply on Create Session With Laravel API

you can add api group in your web.php file like this:

Route::middleware(['auth'])
    ->prefix('api')
    ->namespace('Api')
    ->as('api.')
    ->group(function () {
        // you can write your routes here.
    });

ahsan left a reply on Laravel Query

please use start and end of the code for better understanding.

ahsan left a reply on Want To Block Multiple Logins

like this:

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/home';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    /**
     * Attempt to log the user into the application.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return bool
     */
    protected function attemptLogin(Request $request)
    {
        // write your logics here.
        // it will override core method.
    }
}

ahsan left a reply on Want To Block Multiple Logins

if you want to customize core login functionality.

just copy method from AuthenticatesUsers trail and paste into LoginController

then write your logics as per your needs.

ahsan left a reply on Want To Block Multiple Logins

this is the core trait for login

first of all you should not change anything in this file.

please tell me why you need to change this file?

ahsan left a reply on Want To Block Multiple Logins

which laravel version you are using?

27 Jan
1 month ago

ahsan left a reply on Join Table Through Eloquent Relationship

you will get this kind of result:

{
    "id": 1,
    "name": "Employee 1",
    "age": "25",
    "created_at": null,
    "updated_at": null,
    "detail": {
        "id": 1,
        "employee_id": 1,
        "address": "abc address",
        "phone": "1234567",
        "created_at": null,
        "updated_at": null
    }
}

ahsan left a reply on Join Table Through Eloquent Relationship

Employee.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Employee extends Model
{
    /**
     * Get the detail associated with the employee.
     */
    public function detail()
    {
        return $this->hasOne(Detail::class);
    }
}

Query for get result:

Employee::with('detail')->find(1);

ahsan left a reply on I Want To Sort Order By Date And Order By Priority Simultaneously.

agree with @snapey

but if you are looking for Ascending Order

it would be

Model::latest()->orderBy('priority','ASC')->get();
26 Jan
2 months ago

ahsan left a reply on How To Add Laravel Project On Github?

@msoft please mark as best answer if your problem solved.

thanks

ahsan left a reply on Why Showing This Exception? Illuminate \ Database \ Eloquent \ MassAssignmentException

this is MassAssignmentException

you need to add this in your model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    /**
     * The attributes that aren't mass assignable.
     *
     * @var array
     */
    protected $guarded = [];
}
08 Jan
2 months ago

ahsan started a new conversation Laravel Nova Index Resource Disable Filters Bar

Hi,

how can i disable resource index filters dropdown?

like this:

Laravel Nova

is there anyway to disable default filters or table top card bar?

and in the detail page why showing like this:

Laravel Nova

both scenarios are relevant i think and has same solution.

if anybody know please help me.

thanks

08 Dec
3 months ago

ahsan started a new conversation ES6 Class Does Not Work In Compiled Js

Hi,

i have this class in my /src/js/main.js

class Point {
    constructor(x, y) {
        this.x = x;
        this.y = y;
    }

    toString() {
        return `(${this.x}, ${this.y})`;
    }
}

export default Point;

here is the webpack.mix.js file

let mix = require('laravel-mix')

mix.js('src/js/main.js', 'dist/')
   .setPublicPath('dist')

so when i include in my index.html file like this:

<!DOCTYPE html>
<html>
<head>
    <title>es6 test</title>
</head>
<body>

    <!-- Scripts -->
    <script src="dist/main.js"></script>

    <script type="text/javascript">
        new Point(1, 3)
    </script>
</body>
</html>

so i have this error in console

"Uncaught ReferenceError: Point is not defined"

Actually, i want to create npm package for users to just include my script and instantiate the script

like this

new Point(1, 3)

is there any solution?

Thanks

29 Jun
8 months ago

ahsan started a new conversation Why Not Laravel Support Officially Graph DB?

Graph DB is awesome like OrientDB, Neo4j

but laravel not supporting out of the box officially graph databases.

mysql is not good for big data.

26 May
10 months ago

ahsan left a reply on How To Create Reusable For Loop With Try Catch?

finally, i figured out the solution.

it's working fine for me:

function loop(Closure $callback, $attempts = 2)
{
    for ($currentAttempt = 1; $currentAttempt <= $attempts; $currentAttempt++) {
        try {
            $callback();
            break;
        } catch (\Illuminate\Database\QueryException $e) {
            if ($currentAttempt == 2) {
                throw $e;
            }
        }
    }
}

ahsan left a reply on How To Create Reusable For Loop With Try Catch?

i want to use for something else

but how can i convert this into reusable ?

ahsan started a new conversation How To Create Reusable For Loop With Try Catch?

here is the code i'm using:

for ($i=0; $i < 2; $i++) {
    try {
        User::create([
            'name' => 'username'
        ]);
        break;
    } catch (\Illuminate\Database\QueryException $e) {
        if ($i == 1) {
            throw $e;
        }
    }
}

but i want to make reusable this code only substitute data in try loop for example:

for ($i=0; $i < 2; $i++) {
    try {
        
        // replace something here
        // all rest of the code should be ignore and resuable

        break;
    } catch (\Illuminate\Database\QueryException $e) {
        if ($i == 1) {
            throw $e;
        }
    }
}

ahsan started a new conversation Foreach Loop Is Better Or Should Use Collection?

we have items array want to attach

this code is working fine for me.

i just want to know this approach is better or something else better solution?

foreach ($this->request->items as $item) {
    $sale->items()->attach([
        $item['item']['id'] => ['quantity' => $item['quantity']]
    ]);
}

i used with collection too but foreach method is neat and clean.

$collection = collect($this->request->items);

$items = $collection->mapWithKeys(function ($item) {
    return [$item['item']['id'] => ['quantity' => $item['quantity']]];
})->all();

$sale->items()->attach($items);

i'm asking just for best practices.

both are working fine.

24 May
10 months ago

ahsan left a reply on How To Unique Increment Simultaneous Requests

@m-rk no i want to increment number column too

all working fine but not working with same time multiple requests.

ahsan left a reply on How To Unique Increment Simultaneous Requests

@Snapey but how to lock the table any idea?

ahsan started a new conversation How To Unique Increment Simultaneous Requests

we have sales table and want to add unique sale number in table

here is the code but it's duplicate the numbers with simultaneous requests.

if 5 requests at same time it's not working perfectly because when we fetch last number from database it's give us sometime old number.

$sale->create([
    'number' => optional($sale->latest('id')->first())->number + 1,
    'amount' => 20,
]);

there are 2 queries same time first fetch old number then increment. but it's not good for simultaneous requests.

any solution here?

thanks

ahsan left a reply on Last Ticket Sold Process Handle With Multiple Users Requests

there are lesson available at laracasts about this scenario if anybody know?

i want to do with mysql redis is not required.

ahsan started a new conversation Last Ticket Sold Process Handle With Multiple Users Requests

for example last ticket left to sale

multiple users requests at same time but processing take little time.

how to handle this scenario?

there are 1 lesson at laracasts about this scenario but can't find at this time.

23 May
10 months ago

ahsan left a reply on How To Sort By Best Selling Items With Pivot Table?

@lostdreamer_nl good idea but it's not working.

we are getting all items but not sorting items with sales count.

ahsan started a new conversation How To Sort By Best Selling Items With Pivot Table?

i want to sort best selling items

here is the scenario

items table:

| id | name | | --- | --- | | 1 | Item 1 | | 2 | Item 2 | | 3 | Item 3 |

sales table:

| id | user_id | amount | --- | --- | --- | | 1 | 1 | 200 | 2 | 1 | 300 | 3 | 1 | 400

pivot table item_sale:

| item_id | sale_id | quantity | --- | --- | --- | | 1 | 1 | 5 | 2 | 1 | 5 | 3 | 2 | 10 | 2 | 2 | 10

how to get all items but sort by most selling item like item 2 should be top because it's 15 sales.

how to query this scenario?

anybody here to help me this complex query?

thanks

10 Sep
1 year ago

ahsan started a new conversation How Can We Take Benefit To Learn Laravel & VueJs?

Hi,

there are vast community at @laracasts but i have a question.

how can we earn money with clients or own projects?

what laravel community does to earn money?

i'm from Pakistan, how can i earn money?

how to take clients for small projects?

any help, any guide?

02 Dec
2 years ago

ahsan left a reply on Product Attribute Has Many Values

@Snapey yes, example is right i think.

1 shirt has many colors and many sizes.

how to tackle this?

i think Attribute table with parent_id

maybe it's work.

ahsan left a reply on Product Attribute Has Many Values

you are right, we can create another pivot table for attribute values but problem is this 1 item has different values how to combine 1 attribute values for 1 product.

ahsan started a new conversation Product Attribute Has Many Values

item.php

class Item extends Model
{
    public function attributes()
    {
        return $this->belongsToMany('App\Attribute');
    }
}

$item = Item::with('attributes')->find(1);

This code is working fine with item has 1 attribute with 1 value

getting this result:

{
    "id": 1,
    "name": "Item Name",
    "attributes": [
        {
            "name": "attribute 1",
            "value": "attribute 1 Value",
        },
        {
            "name": "attribute 2",
            "value": "attribute 2 Value",
        },
    ]
}

but my question is i want to add multiple values for 1 attribute like this:

{
    "id": 1,
    "name": "Item Name",
    "attributes": [
        {
            "name": "attribute 1",
            "value": [
                "value 1",
                "value 2"
    
                ]
        },
        {
            "name": "attribute 2",
            "value": [
                "value 1",
                "value 2"
    
                ]
        },
    ]
}

this is really complex query i think, i'm struggling to find solution but failed so i posted here for get some solution.

how to get multiple values for 1 single attribute for same item.

please help me.

14 Oct
2 years ago

ahsan started a new conversation Vuejs Autocomplete

Hi,

i want vuejs autocomplete solution.

i saw this but it's not work with arrow keys like down arrow, up arrow select.

http://jsfiddle.net/Phunky/tm8k8907/

if anybody help me for this.

i also saw others but they are all heavy weight.

and i only want to fetch data via object like above example not via ajax request.

actually, i need in invoice table, i used twitter typeahead but it does not work with add new row.

26 Sep
2 years ago

ahsan left a reply on Which Forums Used By Laracasts?

yes, similar to Flarum Forum but not sure.

ahsan started a new conversation Which Forums Used By Laracasts?

Hi,

i want to know which forums used by laracasts?

or these forums created by Jeffrey way himself?

actually, i saw same forum somewhere else too so i curious to know about this forums.

Thanks

08 Sep
2 years ago

ahsan left a reply on [BETA TESTERS] Laralum - Laravel 5.3 Administration Panel

wow, it's really cool idea.

it will be more cool if you add social integration too.

by the way your work is really appreciate keep it up guys.