BezhanSalleh

Application Developer at Roshan - https://roshan.af

Member Since 4 Years Ago

Kabul

Experience Points
105,980
Total
Experience

4,020 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
739
Lessons
Completed
Best Reply Awards
46
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 22
105,980 XP
Dec
06
1 month ago
Activity icon

Replied to Could I Use Make:auth Command For Make Login/registration For Laravel 8

to scaffold authentication in laravel you have the following three choice of packages so based on your needs you can choose anyone...

Laravel UI Frontend Bootstrap + other presets

Laravel Jetstream Livewire/InsertiaJS + Tailwind

Laravel Breeze Frontend Tailwind

Nov
29
1 month ago
Nov
28
1 month ago
Activity icon

Awarded Best Reply on How To Link Two Databases In Different Domains ? ( PHP Native ).

Your best bet is Replication. Which can be achived with MySQL Replication have look 👇 https://www.digitalocean.com/community/tutorials/how-to-set-up-master-slave-replication-in-mysql

Activity icon

Replied to Nuxt.js Axios Call -> Laravel Api

create the following method and check your devtools to see if your setup is correct or something else is going on with your stores or anything else

methods:{
	fetchSomeCategories(){
  		this.$axios.$get('/').then(response => {
  			console.log(response.data)
		}).catch(err => {
			console.error(err.response.data)
		})
 	}
},
mounted() {
	this.fetchSomeCategories()
}
Activity icon

Replied to Test That The Elements In A Collection Belongs To An User ?..

first of all, do format your code properly... your issue might be in the blade component (livewier.habit.index) you need to handle if the user doesn't have any habits... the livewire quack might be about that

@forelse($habits as $habit)
	<li>{{ $habit->title }}</li>
@empty
	<li> You haven not added any habits yet</li>
@endforelse
Activity icon

Replied to Laravel How To Prevent Deletion Of A Permission If It Linked With Any Role

From the Docs

You can determine if a role has a certain permission:

$role->hasPermissionTo('edit articles');

A permission can be revoked from a role:

$role->revokePermissionTo('edit articles');
Activity icon

Replied to Nuxt.js Axios Call -> Laravel Api

the culprit might be the forgotten. '/' 👇

let response = await this.$axios.$get('/categories')

Activity icon

Replied to Open Quiz Based On Scheduled Date And Time In Laravel

your best bet is to use UTC as your default timezone... Wiki Weather forecasts and maps all use UTC to avoid confusion about time zones and daylight saving time. ... This ensures that all pilots, regardless of location, are using the same 24-hour clock..

Or if you want you could get each visitors' localtime and adjust it accordingly.

--Helper function...
if(! function_exists('getVisitorsLocalTime')) {
        function getVisitorsLocalTime(){
    
            $ip = file_get_contents("http://ipecho.net/plain");
            $url = 'http://ip-api.com/json/'.$ip;
            $tz = file_get_contents($url);

            return  json_decode($tz,true)['timezone'];
        }
 }

now you can use the above helper function to get each visitor's local time and compare it with your quizez open time and adjust accordingly...

 //time based on Visitor/User of your website's timezone
Carbon::now(getVisitorsLocalTime());

//time based on your application's timezone
Carbon::now()
Nov
17
1 month ago
Activity icon

Replied to Two Laravel Project With API

Suppose you have a products table and you want to have access to this table on both projects then You have to create model for Product on both projects as normally you would on a single project.

Activity icon

Replied to API

Depends on the application really, there isn’t any straightforward guide on these sorta things... experience and instinct.

Nov
13
2 months ago
Activity icon

Replied to API

@jokerdz all of the above, though it depends what do you wanna use the api for?

  1. Passport : Passport provides a full OAuth2 server implementation for your Laravel application in a matter of minutes. It is therefore necessary to have a brief knowledge of OAuth2.

  2. Sanctum : Sanctum it is a simple package to issue API tokens to your users without the complication of OAuth. Also has built-in functionality for SPA authentication.

In a small application use Sanctum. it's simple and easy

  1. JWT : Auth (Authentication) is the process of identifying the user credentials. In web applications, authentication is managed by sessions which take the input parameters such as email or username and password, for user identification. If these parameters match, the user is said to be authenticated.

https://stackoverflow.com/questions/61179166/laravel-auth-vs-passport-vs-sanctum

Activity icon

Replied to API For Application

@adsofts in this case passport is your best bet ... horray... mark the question as answered.

Activity icon

Replied to API For Application

Not based on your assumptions about the OP's intended use case, though OP sounds confused.

your way the interaction is through terminal and passport is heavy. I suggested jetstream which gives a gui and uses sanctum(kind of a starting point...) which is light.

Create a model named Applications extend Autheticatable, setup guard and bob is your uncle. but in all fairness it depends on the criteria, sanctum is best as an MVP and easy to swap to passport if required.

Activity icon

Replied to Put Model::create() Inside A Transaction

@david1024812048 a little context on what you are trying to achieve would help out more but you would do something like below

DB::beginTransaction();

try {
	//if this is the only place your ending balance gets updated 
	//then you won't need the lock
	
	$lastEndingBalance = Balance::whereUserId($user_id)->lockForUpdate()->first()->ending_balance;

	$balance = new Balance;
         ... // rest of your fileds/columns
	$balance->ending_balance = request('amount') + $lastEndingBalance;
        $balance->save();

} catch (Exception $e) {
	DB::rollback();
            	
	return back()->with([
                "title"   => "{$e->getMessage()}",
        	"type"  => "error"
	]);
}

DB::commit();

return redirect()->route('purchases.index')
->with([
	"message"   => 'Horray!',
	"type"  => "success"
]);

~cheers!

Activity icon

Replied to Two Laravel Project With API

@emfinanga yea you can, all you need is to duplicate models for the tables you use on both projects

Activity icon

Replied to API For Application

@adsofts laravel jetstream already comes up with the solution you are looking for outta box! Easy simple and ready to start. https://jetstream.laravel.com/1.x/introduction.html

Jul
20
5 months ago
Activity icon

Awarded Best Reply on New Laravel HTTP Facades & Verify (guzzle)

@cerbix https://laravel.com/docs/7.x/http-client#guzzle-options

$response = Http::withHeaders([
      'Accept'        => 'application/json',
      'Content-Type' => 'application/json',
])
->withOptions([
    'verify' => true,
])
->get(url('api/'));

2nd question: it would be just the same. how you doing it now? show us code snippet?

Jul
18
5 months ago
Activity icon

Replied to New Laravel HTTP Facades & Verify (guzzle)

@cerbix https://laravel.com/docs/7.x/http-client#guzzle-options

$response = Http::withHeaders([
      'Accept'        => 'application/json',
      'Content-Type' => 'application/json',
])
->withOptions([
    'verify' => true,
])
->get(url('api/'));

2nd question: it would be just the same. how you doing it now? show us code snippet?

Activity icon

Replied to Laravel Database Seeding Class Not Found

@jeroenvanrensen the one thing i can think of is since you are not using the prefered way of creating seeders. I know sometimes we need a dirty quick way to get away with stuff and get our desired functionality and creating seeders for each model gets kinda hectic but in the long run it helps you and gives more control

for your scenario i would have started with following:

//factories
ProductFactory
StockFactory
RetailerFactory

//seeders
ProductSeeder
StockSeeder
RetailerSeeder

//DatabaseSeeder
    public function run()
    {
        $this->call([ProductSeeder::class]);
        $this->call([StockSeeder::class]);
        $this->call([RetailerSeeder::class]);
    }

//Observers

class RetailerObserver
{
    public function created(Retailer $retailer)
    {
	$retailer->addStock(App\Product::first(), App\Stock::first());
    }
}
Activity icon

Awarded Best Reply on Laravel Database Seeding Class Not Found

you have a spelling mistake in your class and its file name

//RetailerWithProductSeeder.php

<?php

use App\Product;
use App\Retailer;
use App\Stock;
use Illuminate\Database\Seeder;

class RetailerWithProductSeeder extends Seeder
{
    public function run()
    {
        $product = Product::create([
            'name' => 'Nintendo Switch'
        ]);

        $retailer = Retailer::create([
            'name' => 'Best Buy'
        ]);

        $stock = new Stock([
            'price' => 10000,
            'url' => 'https://www.example.org/',
            'sku' => 12345,
            'in_stock' => false
        ]);

        $retailer->addStock($product, $stock);
    }
}

then

php artisan db:seed --class=RetailerWithProductSeeder
Activity icon

Replied to Laravel Database Seeding Class Not Found

you have a spelling mistake in your class and its file name

//RetailerWithProductSeeder.php

<?php

use App\Product;
use App\Retailer;
use App\Stock;
use Illuminate\Database\Seeder;

class RetailerWithProductSeeder extends Seeder
{
    public function run()
    {
        $product = Product::create([
            'name' => 'Nintendo Switch'
        ]);

        $retailer = Retailer::create([
            'name' => 'Best Buy'
        ]);

        $stock = new Stock([
            'price' => 10000,
            'url' => 'https://www.example.org/',
            'sku' => 12345,
            'in_stock' => false
        ]);

        $retailer->addStock($product, $stock);
    }
}

then

php artisan db:seed --class=RetailerWithProductSeeder
Activity icon

Replied to @permission And @endpermission Of Entrust Not Work In Blade Laravel 7

They have a beautiful documentation and in there, they have links to some tutorials too. Its pretty much self explanatory. https://docs.spatie.be/laravel-permission/v3/introduction Cheers!

Activity icon

Replied to Laravel Datatatables

Code snippet will help us help you better? Be specific like you are using datatables as a service or ajax or html?

Activity icon

Replied to Laravel Database Seeding Class Not Found

I run into this but didn’t really search for the exact solution but you can try the following: Also try renaming the seeder as ‘RetailerWithProductSeeder’

php artisan db:seed --class=RetialerWithProduct

Cheers!

Jul
17
6 months ago
Activity icon

Replied to How To Make Confirmation Alert In Livewire

//livewiere component

    public function destroy($orderId)
    {
        Order::find($orderId)->delete();

        session()->flash('message','Order deleted successfully!');
    }

//blade

//deleteButton -> triggers the sweetAlert

<a href="#"  wire:click="$emit('triggerDelete',{{ $order->id }})">
	<span class="ua-icon-alert-close text-danger"></span>
</a>

//scripts stack

@push('scripts')
<script type="text/javascript">
    document.addEventListener('DOMContentLoaded', function () {

        @this.on('triggerDelete', orderId => {
            Swal.fire({
                title: 'Are You Sure?',
                text: 'Order record will be deleted!',
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: 'var(--success)',
                cancelButtonColor: 'var(--primary)',
                confirmButtonText: 'Delete!'
            }).then((result) => {
		//if user clicks on delete
                if (result.value) {
		     // calling destroy method to delete
                    @this.call('destroy',orderId)
		    // success response
                    responseAlert({title: session('message'), type: 'success'});
                    
                } else {
                    responseAlert({
                        title: 'Operation Cancelled!',
                        type: 'success'
                    });
                }
            });
        });
    })
</script>
@endpush

Cheers mate!

Jul
16
6 months ago
Activity icon

Replied to HasOneTrough / HasManyTrough Relations

I'm not sure that's possible for your situation but you can do it through collections as follow: using memoization will help out regarding performance. User.php

private $courses;

    public function courses()
    {
        if(!$this->courses) {

            return $this->enrollments->flatMap(fn ($enrollment) => $enrollment->courses);
        }

        return $this->courses;
    }

and then you can query it as

User::first()->courses();

cheers!