Nidal

Nidal

Member Since 10 Months Ago

Experience Points
16,440
Total
Experience

3,560 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
155
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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.

Level 4
16,440 XP
Nov
18
2 months ago
Activity icon

Started a new Conversation $this->post Passes, $this->json Fails In This Case, Why ?

Controller :

public function store(Request $request)
    {
        auth()->user()->bamboos()->create(request()->validate([
            'name' => ['required'],
            'link' => ['required', 'url', 'unique:bamboos'],
        ]));

        return ['message' => 'Bamboo Created !'];
    }

Table :

Schema::create('bamboos', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('owner_id');
            $table->string('name');
            $table->string('link')->unique();
            $table->unsignedInteger('sugar')->default(0);
            $table->timestamps();

            $table->foreign('owner_id')->references('id')->on('users')->onDelete('cascade');
        });

Test with $this->post()

OK (1 test, 3 assertions)
public function test_bamboo_link_has_to_be_unique()
    {
        $this->asRegistered();

        factory(Bamboo::class)->create(['owner_id' => auth()->id(), 'link' => 'http://panda.com']);

        $bamboo_data = factory(Bamboo::class)->raw(['link' => 'http://panda.com']);

        $this->post('/bamboos', $bamboo_data)->assertSessionHasErrors('link');

        $this->assertDatabaseMissing('bamboos', $bamboo_data);
    }

Test with $this->json()

There was 1 failure:

1) Tests\Feature\BambooRequirementsTest::test_bamboo_link_has_to_be_unique
Session is missing expected key [errors].
Failed asserting that false is true.
public function test_bamboo_link_has_to_be_unique()
    {
        $this->asRegistered();

        factory(Bamboo::class)->create(['owner_id' => auth()->id(), 'link' => 'http://panda.com']);

        $bamboo_data = factory(Bamboo::class)->raw(['link' => 'http://panda.com']);

    $response = $this->json('POST', '/bamboos', $bamboo_data);

        $response->assertSessionHasErrors(['link']);

        $this->assertDatabaseMissing('bamboos', $bamboo_data);
    }
Nov
13
2 months ago
Activity icon

Replied to Event.$on('somethingHappened'. () => This.doStuff()); <- Where To Put This ?

ah, i found the problem

problem:

onSubmit() {

    this.form.submit('post', '/questions')

                .then(response => console.log(response.data) )

                .catch(data => console.log(data.errors));

            
    Event.$emit('questionCreated')
            
}

solution:

onSubmit() {

            this.form.submit('post', '/questions')

                .then(response => Event.$emit('questionCreated'))

                .catch(data => console.log(data.errors));
            
}
Activity icon

Replied to Event.$on('somethingHappened'. () => This.doStuff()); <- Where To Put This ?

Basically the root Vue component is submitting a post request to create a model in the database and emitting an event when that is done and another component is listening for that event to make a get request to refresh it's data to have the new record.

Activity icon

Replied to Event.$on('somethingHappened'. () => This.doStuff()); <- Where To Put This ?

I think the issue is that i make a get request the moment the post request emits an event. how do i solve this ?

Activity icon

Started a new Conversation Event.$on('somethingHappened'. () => This.doStuff()); <- Where To Put This ?

Where to put the line of code in the title to make it trigger whenever another a component fires the 'somethingHappened' event ?

Activity icon

Commented on Object-Oriented Forms: Part 1

i love this.

Nov
09
2 months ago
Activity icon

Started a new Conversation Can I Write This Test Better ?

Goal : Admin can create a page with title and body, and optionally a cover image.

Test OK (1 test, 3 assertions)

public function test_admin_can_store_page()
    {
        $this->asAdmin();

        Storage::fake('public');

        $attributes = factory(Page::class)->raw();

        $this->withoutExceptionHandling();
        $this->post('/pages', $attributes);

        $page = Page::first();

        $attributes['cover'] = 'pages/'. $page->id .'/cover/' . $attributes['cover']->hashName();

        $this->assertEquals($attributes['cover'], $page['cover']);

        $this->assertDatabaseHas('pages', $attributes);

        Storage::disk('public')->assertExists($attributes['cover']);
    }

PageController Store

public function store(Request $request)
    {
        $attributes = request()->validate([
            'title' => ['required'],
            'body' => ['required'],
            'cover' => ['image'],
        ]);
        
        $page = Page::create($attributes);

        $page->update([
            'cover' => $attributes['cover']->store('pages/' . $page->id . '/cover', 'public'),
        ]); 

        return redirect($page->path());
    }

PageFactory

$factory->define(Page::class, function (Faker $faker) {
    return [
        'title' => $faker->sentence,
        'body' => $faker->text,
        'cover' => UploadedFile::fake()->image('cover.jpg'),
    ];
});
Nov
08
2 months ago
Activity icon

Started a new Conversation Is There A Better Way To Get Model Id Before It's Created ?

Here I'm creating a page that has ['title', 'body', 'cover']

public function store(Request $request)
    {
        $attributes = request()->validate([
            'title' => ['required'],
            'body' => ['required'],
            'cover' => ['image'],
        ]);
        
        $page = Page::create($attributes);

        $page->update([
            'cover' => $attributes['cover']->store('/pages/' . $page->id . '/cover/', 'public'),
        ]); 

        return redirect($page->path());
    }

In the store method i create the page with only the title and body and after updated the cover field. I do this to have accurate access to the pages ID to be able to create a folder dedicated to that page in storage.

Is there a better way or is this good enough ?

Nov
06
2 months ago
Activity icon

Replied to Test Guest Did Not Create File In Storage.

unless the image is stored i wouldn't have the hash name to check if it doesn't exist. but then if it is stored .. it does exist ... which doesn't make sense for this testing case.

Activity icon

Replied to Test Guest Did Not Create File In Storage.

This is how the post request is processed.

public function store(Request $request, Article $article)
    {
        $attributes = request()->validate([
            'images.*' => ['image']
        ]);

        foreach ($attributes['images'] as $image) {
            $article->addImage( $image->store('articles/' . $article->id . '/images', 'public') );
        }

        return back();
    }
Activity icon

Replied to Test Guest Did Not Create File In Storage.

@tykus but if for some reason the image is actually stored, it would be stored with a hashed name and not the name of the uploaded file.

Activity icon

Started a new Conversation Test Guest Did Not Create File In Storage.

public function test_guest_can_not_add_article_image()
    {
        Storage::fake('public');

        $article = factory(Article::class)->create();

        // fakeImages() returns an array of fake image files using "UploadedFile::fake()".
        $request = ['images' => $this->fakeImages(2)];

        $this->post($article->path() . '/images', $request)->assertRedirect('login');

        $this->assertCount(0, $article->images);

        $this->assertDatabaseMissing('article_images', ['article_id' => $article->id]);

        // check that no images were stored.
    }

How do i implement the comment ?

Nov
02
2 months ago
Activity icon

Replied to How To Structure A Database And Relationships For This Website ?

You can see the front-end code here : nidalghonaim.github.io/MarocSportsView :)

Nov
01
2 months ago
Activity icon

Started a new Conversation How To Structure A Database And Relationships For This Website ?

Hello there :D

The website i want to design has pages.

Each page has different elements :

  • About page : has title, body, a team image, a bunch of objectives.
  • Sponsors page : has title, body, a cover image, sponsoring packages, and a list of sponsors separated into 3 categories.
  • Multimedia page : This one has a title, and a bunch of images and videos.

What do you think would be the simplest easy to maintain approach to this ?

Oct
26
2 months ago
Activity icon

Started a new Conversation A Comment Belongs To A Post And User (how To Pass Both Of Their IDs Automatically ?)

a post has many comments.

a comment belongs to a post.

so to create a comment : $post->comments()->create($comment_data); (here the post_id is passed automatically).

now so far there is no relationship between the comment and the user "Correct me if i am wrong".

so let's say a comment belongs to a user as well.

well .. now if we create the comment using : $post->comments()->create($comment_data); ... it will show an error saying that user_id doesn't have a default. (of course ... the post_id is passed automatically but user_is is not).

ideas on how to make it passed automatically and cleanly ?

Sep
29
3 months ago
Activity icon

Commented on Testing Avatar Uploads

if you got Call to undefined method UploadedFile::fake() ... make sure you included the correct one use Illuminate\Http\UploadedFile; .. there's another UploadedFile from the Symfony package that does not include fake().

Sep
27
3 months ago
Activity icon

Replied to Tutorial For 6.0 That Doesn't Require Laravel/ui For Creating Auth

In addition to what @diego1araujo proposed. perhaps there is a way to create a custom artisan command that would add exactly and only what you want.

Activity icon

Replied to Tutorial For 6.0 That Doesn't Require Laravel/ui For Creating Auth

I think he is asking if he could scaffold the routes and views of "Auth" without adding Vue to the composer dependencies.

Sep
18
4 months ago
Activity icon

Replied to How To Subscribe To Forge ?

I hope they give clearer subscription feedback in the future with perhaps email notifications.

Sep
16
4 months ago
Activity icon

Started a new Conversation How To Subscribe To Forge ?

When i choose the plan and click update nothing happens :/

How it looks like: https://i.imgur.com/fXVuvb5.gif

Note: i did add me credit card in the section below.

Sep
12
4 months ago
Activity icon

Started a new Conversation Can I Deploy From Forge On Multiple D.O. Accounts ?

Hello there !

Context: Planning to do Laravel freelancing work.

I would like to know if i could deploy and manage multiple web apps from one Forge account, where each web app lives on a server that's on a different Digital Ocean account (owned by the client).

Goal: i want the clients to own their servers and be responsible of paying their server/domain costs in the long run.

Thank you for taking the time :)

Activity icon

Replied to TDD (Given, When, Then) Snippets For VSC

LARACASTS_SNIPPET_PLACEHOLDER should be changed to $0

Activity icon

Started a new Conversation TDD (Given, When, Then) Snippets For VSC

I made this to help me write tests.

It's a snippet for the 3 comments used in the from scratch TDD episode.

It uses placeholders and some options for easy use.

I don't think it's too flexible at the moment as i haven't been introduced to too many testing cases. I might try to keep this post updated as i go.

The snippets:

"TDD Given" : {
        "prefix": "given",
        "body": [
            "$LINE_COMMENT GIVEN i am a {${1:User}}, whos is {${2:logged in}}.LARACASTS_SNIPPET_PLACEHOLDER"
        ],
        "description": "",
    },

    "TDD When" : {
        "prefix": "when",
        "body": [
            "$LINE_COMMENT WHEN i request the route {/${1:ROUTE}}, to {${2|create,read,update,delete|}} , while passing {${4:DATA}}.LARACASTS_SNIPPET_PLACEHOLDER"
        ],
        "description": "",
    },

    "TDD Then" : {
        "prefix": "then",
        "body": [
            "$LINE_COMMENT THEN there should be a new {${1:ENTITY}} row in the database table {${2:TABLE}}.LARACASTS_SNIPPET_PLACEHOLDER"
        ],
        "description": "",
    },

To use them in Visual Studio Code you do ctrl+shift+p and look for user snippets -> php -> and paste them in :)

Sep
11
4 months ago
Activity icon

Commented on Better PHPUnit Execution

Make sure you don't have spaces in the files that lead to your Laravel app, otherwise it would break this extension (something like c:/username/documents/my file/app/..) wouldn't work ... change "my file" to "myfile" or something..

Sep
09
4 months ago
Activity icon

Commented on At A Glance

YES YES OH GOD YES ! this is beautiful and gets the information into the brain of the viewer more than any other method could, at least to this viewer ! THANK YOU

Activity icon

Commented on Authorization Essentials

For create() and store() in the ProjectsController : $this->authorize('create', Project::class);

Activity icon

Commented on A Full Registration System In Seconds

If you are using laravel 6, you can not make:auth anymore. see https://laravel.com/docs/6.0/authentication#included-routing for more information.

Sep
08
4 months ago
Activity icon

Commented on Create New Project Tasks

It sees the passed id {project} and fetches the Project instance in the database with that id.