faraz73

Member Since 1 Year Ago

Experience Points
13,060
Total
Experience

1,940 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
120
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 3
13,060 XP
Dec
17
4 weeks ago
Activity icon

Replied to Error : Trait Is Not Found (using In Models)

the whole Services dir is in Models dir

Activity icon

Replied to Error : Trait Is Not Found (using In Models)

Hi, did u catch any errors?

Dec
16
4 weeks ago
Activity icon

Replied to Error : Trait Is Not Found (using In Models)

Yes! HasRoles trait can use perfectly .. but HasPermissions

Activity icon

Replied to Error : Trait Is Not Found (using In Models)

it is a practice (thank god !)... I shouldn't take such error logically .. or I'm doing something wrong.

Activity icon

Replied to Error : Trait Is Not Found (using In Models)

i did :( .. but nothing changed

Activity icon

Replied to Error : Trait Is Not Found (using In Models)

it is valid .. but removing it did not solve the problem, unfortunately.

Activity icon

Replied to Error : Trait Is Not Found (using In Models)

the current IDE doesn't support the return data type method syntax like

function fn() :bool { ... }

that is not so serious, I just ignored it.

Activity icon

Replied to Error : Trait Is Not Found (using In Models)

guys .. little Help here .. please

Activity icon

Replied to Error : Trait Is Not Found (using In Models)

i did look at first image User.php line : 6

Dec
15
1 month ago
Activity icon

Started a new Conversation Error : Trait Is Not Found (using In Models)

Hi, I have some trait that I want to use it in my models.

here I have two traits that I want to use :

my_problem

the error is: a trait is not found.

Imgur

<?php

namespace App\Models;



use App\Models\Services\Permissions\Traits\HasPermissions;
use App\Models\Services\Roles\Traits\HasRoles;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;


class User extends Authenticatable
{
    use HasFactory, Notifiable , HasRoles , HasPermissions;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name',
        'email',
        'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];


}
<?php

namespace App\Models\Services\Permissions\Traits;

use App\Models\Permission;
use Illuminate\Support\Arr;

trait HasPermissions
{
    /* ===== permissions ===== */
    public function permissions()
    {
        return $this->belongsToMany(Permission::class);
    }

    protected
    function getAllPermissions(array $permissions)
    {
        return Permission::whereIn('name', Arr::flatten($permissions))->get();
    }

    public function givePermissions(... $permissions)
    {
        $permissions = $this->getAllParmissions($permissions);

        if ($permissions->isEmpty()) return $this;

        $this->permissions()->syncWithoutDetaching($permissions);

        return $this;

    }

    public function withdrawPermissions(... $permissions)
    {
        $permissions = $this->getAllParmissions($permissions);
        $this->permissions()->detach($permissions);
        return $this;
    }

    public function refreshPermissions(... $permissions)
    {
        $permissions = $this->getAllParmissions(Arr::flatten($permissions));
        $this->permissions()->sync($permissions);
        return $this;
    }

    public function hasPermission(Permission $permissions)
    {
        return $this->permissions->contains($permissions);
    }
}
<?php

namespace App\Models\Services\Roles\Traits;

use App\Models\Role;
use Illuminate\Support\Arr;
trait HasRoles
{
    /* ==== roles ==== */


    public function roles()
    {
        return $this->belongsToMany(Role::class);
    }

    protected function getAllRoles(array $roles)
    {
        return Role::whereIn('name', Arr::flatten($roles))->get();
    }

    public function giveRoles(... $roles)
    {
        $roles = $this->getAllRoles($roles);

        if ($roles->isEmpty()) return $this;
        $this->Roles()->syncWithoutDetaching($roles);

        return $this;
    }

    public function withdrawRoles(... $roles)
    {
        $roles = $this->getAllRoles($roles);

        $this->roles()->detach($roles);

        return $this;
    }

    public function refreshRoles(... $roles)
    {
        $roles = $this->getAllRoles($roles);
        $this->roles()->sync($roles);
        return $this;
    }

    public function hasRole(string $role)
    {
        return $this->roles->contains('name', $role);
    }
}
Activity icon

Replied to How To Upload Image In Laracasts ?

so ... should I upload the image to another site and give a URL ?

How to do that?

where I should upload it?

Activity icon

Started a new Conversation How To Upload Image In Laracasts ?

Hi, I just want to ask a question with an image ... but the new discussion form don't have a button to upload an image ...

How to upload images in the discussion that we have created in laracasts forum?

Dec
14
1 month ago
Activity icon

Replied to In This Forum How To Post Details With Image

@nakov @jlrdw How to upload an image from a local system?

should we upload the image to another place and give URL to that place/server ???

Nov
22
1 month ago
Activity icon

Started a new Conversation Why I'm Getting More Threads ?

Hi, i have ReadThreadsTest.php that i want to sort threads by popularity (number of replies ) :

class ReadThreadsTest extends TestCase
{
    use DatabaseMigrations;

    protected $thread;

    public function setUp(): void
    {

        parent::setUp();

        $this->thread = Thread::factory()->create();

    }
/** @test */
    public function a_user_can_filter_threads_by_popularity()
    {
        // Given we have 3 threads

        $thread2 = Thread::factory()->create();

        Reply::factory()->count(3)->create(['thread_id' => $thread2->id]);

        $thread3 = Thread::factory()->create();

        //Reply::factory()->count(2)->create(['thread_id' => $thread3->id]);


        dd(Thread::all()->count());
        // with  2 , 3 ,  0 replies
        // when i filter all threads by popularity
        // then they should be returned from most replies to least.


    }


}


I want to have 3 threads and each has 0, 3, 2 replies respectively.

the problem is that if I factory three replies for $thread2 I get more threads ... it should stay 3! ( i get 6 threads ! )

what am I doing wrong?

this is ThreadFactory:

public function definition()
    {
        return [
            'user_id' => User::factory(),
            'channel_id' => Channel::factory(),
            'title' => $this->faker->title,
            'body' => $this->faker->paragraph,
        ];
    }

and this is ReplyFactory :

public function definition()
    {
        return [
            'thread_id' => Thread::factory()->create(),
            'user_id' => User::factory()->create(),
            'body' => $this->faker->paragraph,
        ];
    }
Activity icon

Replied to Laravel 8 From Scratch?

agreed

Nov
21
1 month ago
Activity icon

Replied to Relation Method Model Wont Work

slapping my face 🤦🤦

Activity icon

Started a new Conversation Relation Method Model Wont Work

Hi,

I have created a method in Thread.php named creator()

public function creator()
    {
        return $this->belongsTo('App\Models\User','id');
    }

but when I want to get the creator's name: like $thread->creator->name;

it won't work, i have done it tinker .. it just won't work : \

error : ErrorException Trying to get property 'name' of non-object

Nov
10
2 months ago
Activity icon

Replied to Can't Modify SetUp()

yeah it works :D .. thanks everybody

Activity icon

Replied to Can't Modify SetUp()

not for me .. is it working for you ?

Activity icon

Replied to Can't Modify SetUp()

unfortunately.. the same error

Activity icon

Started a new Conversation Can't Modify SetUp()

Hi, I just want to set up some factory in my test class .. but this error occurs :

Fatal error: Declaration of Tests\Feature\ReadThreadsTest::setUp() must be compatible with Illuminate\Foundation\Testing\TestCase::setUp(): void in ....

this is my test :

namespace Tests\Feature;

use App\Models\Thread;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase;

class ReadThreadsTest extends TestCase
{
    use DatabaseMigrations;


    public function setUp()
    {
        parent::setUp();

        $this->thread = Thread::factory()->create();

    }
}
Nov
09
2 months ago
Activity icon

Started a new Conversation Error : No Such Table Exist In Test Laravel 8

Hi .. i just want to factory a model in my test .. and I got an error like this

SQLSTATE[HY000]: General error: 1 no such table: threads  ...

but it does exist and I have modified phpunit.xml

and I have done migration and factoring (i can factory my model in tinker )

idk where is my problem

This is my test

<?php

namespace Tests\Feature;

use App\Models\Thread;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Tests\TestCase;

class ThreadsTest extends TestCase
{
    use DatabaseMigrations;

    /** @test */
    public function a_user_can_browse_threads()
    {
        $this->withoutExceptionHandling();
        $thread = Thread::factory()->create();
        $response = $this->get('/threads');
        $response->assertSee($thread->title);
    }
}

this is my migrtion

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateThreadsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('thread', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id');
            $table->string('title');
            $table->text('body');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('thread');
    }
}

This is factory

<?php

namespace Database\Factories;

use App\Models\Thread;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

class ThreadFactory extends Factory
{
    /**
     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = Thread::class;

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        return [
            'user_id' => User::factory(),
            'title' => $this->faker->title,
            'body' => $this->faker->paragraph,
        ];
    }
}

this is phpunit.xml

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
         bootstrap="vendor/autoload.php"
         colors="true"
>
    <testsuites>
        <testsuite name="Unit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>
        <testsuite name="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>
    </testsuites>
    <coverage processUncoveredFiles="true">
        <include>
            <directory suffix=".php">./app</directory>
        </include>
    </coverage>
    <php>
        <server name="APP_ENV" value="testing"/>
        <server name="BCRYPT_ROUNDS" value="4"/>
        <server name="CACHE_DRIVER" value="array"/>
        <server name="DB_CONNECTION" value="sqlite"/>
        <server name="DB_DATABASE" value=":memory:"/>
        <server name="MAIL_MAILER" value="array"/>
        <server name="QUEUE_CONNECTION" value="sync"/>
        <server name="SESSION_DRIVER" value="array"/>
        <server name="TELESCOPE_ENABLED" value="false"/>
    </php>
</phpunit>

Nov
06
2 months ago
Activity icon

Commented on Squash A Massive Migrations Folder

php artisan schema:dump in 1:39

result :

'mysqldump' is not recognized as an internal or external command, operable program or batch file.

what should i do ??