abdobargush

Member Since 7 Months Ago

Experience Points
15,540
Total
Experience

4,460 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
147
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 4
15,540 XP
Apr
16
3 weeks ago
Activity icon

Commented on SPA Authentication With Sanctum

@drehimself I'm wondering whether sanctum supports multi level sub domains? for example: backend on test.example.com SPA on app.test.example.com

Apr
13
3 weeks ago
Activity icon

Replied to Sanctum Not Working With Sub Domain

looks like it's hosting related issue, for some reason when I moved to another server it's working just fine. Thank you @neilstee for your time.

Apr
12
3 weeks ago
Activity icon

Replied to Sanctum Not Working With Sub Domain

Thank you for your reply. I tried to add the domain to the allowed allowed_origins even the full url like https://app.stg.mydomain.com but still not working

Apr
11
3 weeks ago
Activity icon

Started a new Conversation Sanctum Not Working With Sub Domain

I have my app on app.stg.mydomain.com trying to connect with stg.mydomain.com I tried to setup sanctum with the following configuration

SESSION_DOMAIN=.stg.mydomain.com
SANCTUM_STATEFUL_DOMAINS=app.stg.mydomain.com

also tried

SESSION_DOMAIN=.mydomain.com
SANCTUM_STATEFUL_DOMAINS=*.mydomain.com

But It keeps throwing the error

Access to XMLHttpRequest at 'https://stg.mydomain.com/api/user' from origin 'https://app.stg.mydomain.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Mar
17
1 month ago
Activity icon

Awarded Best Reply on How To Allow Database Column To Be True Only If Another Column Is True?

Thank you @jlrdw, @michaloravec for mentioning database triggers. I got it to work by adding the following db trigger to run with the migration

Schema::create('subscribers', function (Blueprint $table) {
    $table->id();
    $table->string('email')->index();
    $table->boolean('is_subscribed')->default(true);
    $table->boolean('is_active')->default(true);
    $table->timestamps();
});

/**
 * Run db trigger to change is_active to false on is_subscribed = false
 */
$query = "CREATE TRIGGER update_is_active BEFORE UPDATE ON subscribers
    FOR EACH ROW
    BEGIN
        IF NEW.is_subscribed = 0 THEN
            SET NEW.is_active = 0;
        END IF;
    END;
";
DB::connection()->getPdo()->exec($query);

As you mentioned @jlrdw it may be very easy to handle it in the code with Eloquent observers or closure, The downside is it will need independent handling if any other app updates the data.

@michaloravec I was wondering why it would be better to have them both false as default? What I think is once the subscriber joins the initial state is to be subscribed and active.

Activity icon

Started a new Conversation Error With Mail::later() When Specifying Queue Name

I'm trying to use the following to queue mail, when I don't provide newsletter as the queue name it works just fine, but when I use Mail::later() as following

foreach ($subscribers as $index => $subscriber) {
      Mail::later(
        now()->addMilliseconds(500 * $index),
        new NewsletterMail($issue, $subscriber),
        'newsletter'
      );
}

I get the error Argument 2 passed to Illuminate\\Mail\\Mailable::later() must implement interface Illuminate\\Contracts\\Queue\\Factory, string given

My NewsletterMail class looks like this

class NewsletterMail extends Mailable implements ShouldQueue
{
  use Queueable, SerializesModels;

  public $issue;
  public $subscriber;

  public function __construct($issue, $subscriber)
  {
    $this->issue = $issue;
    $this->subscriber = $subscriber;
  }

  public function build()
  {
    return $this->subject($this->issue->subject)
		->to($this->subscriber)
        ->view('newsletter.templates.template1.email');
  }
}
Feb
15
2 months ago
Activity icon

Replied to Undefined Variable: Generals In Inner Page!

Hi @karangautam, You may consider using blade components for this kind of behavior.

generate a header component then fetch the data you need in the render() method https://laravel.com/docs/8.x/blade#components

Activity icon

Replied to What Is The Best Practice For Using Traits?

Thank you @martinbean, I think I'm getting your point here. Yes, it can be wrapped in a class of its own. I thought of using trait as a code that can be reused by several classes.

Activity icon

Replied to What Is The Best Practice For Using Traits?

@fylzero Thank you for bringing up polymorphic relationship, I imagine it would be better approach if I needed more advanced thumbnail functionality as it adds complexity on the database level.

In my application every resource will have only one thumbnail and I don't need to store any additional data associated with it, size and directory are only used during the upload.

Activity icon

Started a new Conversation What Is The Best Practice For Using Traits?

Hello everyone, I've several models that shares thumbnail functionality, so extracted it to a trait and used it like this, I think it's kinda clear and can easily be documented

namespace App\Traits;

/**
 * Add Thumnial functionality to models
 */
trait ThumbnailTrait
{
	private function setThumbnail(?string $value, string $directory, array $size) : void
	{
		// ...
	}
	
	private function getThumbnail(?string $value, string $default) : string
	{
		// ...
	}

}
namespace App\Models;

class Tool extends Model
{
	use \App\Traits\ThumbnailTrait;

	public function setThumbnailAttribute($value)
	{
		$this->setThumbnail($value, 'tools', [256, 256]);
	}

	public function getThumbnailAttribute($value)
	{
		return $this->getThumbnail($value, 'images/[email protected]');
	}
}

but I was thinking that it may be used with properties to alter traits like the following

class Tool extends Model
{
	use \App\Traits\ThumbnailTrait;

	protected $thumbnail = [
		'default' => 'images/[email protected]',
		'directory' => 'tools',
		'size' =>  [256, 256]
	];
}

then rename the trait functions to setThumbnailAttribute and getThumbnailAttribute and make then access the property directly with $this keyword without additional calls in the model

I'm just wondering what is the better way to do it, or if there is a best practice I'm not aware of?

Nov
07
6 months ago
Activity icon

Replied to How To Allow Database Column To Be True Only If Another Column Is True?

is_subscribed is used to indicate if the is subscribed or unsubscribed

The Subscriber may be subscribed but not active regarding the account limits, the account owner won't be able to send newsletters to him unless the account limits is raised.

Activity icon

Replied to How To Allow Database Column To Be True Only If Another Column Is True?

Thank you @jlrdw, @michaloravec for mentioning database triggers. I got it to work by adding the following db trigger to run with the migration

Schema::create('subscribers', function (Blueprint $table) {
    $table->id();
    $table->string('email')->index();
    $table->boolean('is_subscribed')->default(true);
    $table->boolean('is_active')->default(true);
    $table->timestamps();
});

/**
 * Run db trigger to change is_active to false on is_subscribed = false
 */
$query = "CREATE TRIGGER update_is_active BEFORE UPDATE ON subscribers
    FOR EACH ROW
    BEGIN
        IF NEW.is_subscribed = 0 THEN
            SET NEW.is_active = 0;
        END IF;
    END;
";
DB::connection()->getPdo()->exec($query);

As you mentioned @jlrdw it may be very easy to handle it in the code with Eloquent observers or closure, The downside is it will need independent handling if any other app updates the data.

@michaloravec I was wondering why it would be better to have them both false as default? What I think is once the subscriber joins the initial state is to be subscribed and active.

Nov
06
6 months ago
Activity icon

Commented on Using Vue 3 With Laravel

Thank you @andre, I was wondering if laravel-mix should be installed as dev dependency?

Activity icon

Started a new Conversation How To Allow Database Column To Be True Only If Another Column Is True?

Hi, I'm working on Newsletter's subscribers table. The subscriber can be active only if the subscribed status is true How may I implement this on the database level?

That's how the migration looks like

Schema::create('subscribers', function (Blueprint $table) {
    $table->id();
    $table->string('email')->index();
    $table->boolean('is_subscribed')->default(true);
    $table->boolean('is_active')->default(true);
    $table->timestamps();
});