orest

orest

Member Since 3 Months Ago

Experience Points
39,680
Total
Experience

320 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
381
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.

Level 8
39,680 XP
Jun
03
11 hours ago
Activity icon

Started a new Conversation Categories, Sub-categories And Threads

I'd like to create a forum which has different categories of threads.

Each category might have a sub-category.

Therefore, when i click on a category there are 2 options

  1. If this category has sub-categories, then display the sub-categories

    1. If i click on a sub-category, it should display the threads associated to that sub-category
  2. If this category doesn't have sub-categories, then display the threads associated with that category

For example

Category with sub-category :

Category: iOS Sub-category: iOS 13

Category without sub-category:

Category: General

I'm trying to figure out a way to define a relationship between threads and category/sub-category

Any ideas ?

Jun
01
2 days ago
Activity icon

Replied to Web And Api Middleware - Use Cases

@bobbybouwmann

Therefore if I understand correctly, the use cases for the api middleware are either when you have an SPA or if you have a public api that anyone can access

Activity icon

Commented on The Skeleton

there is a difference between laravel routes and vue routes and the difference is that with vue routes whenever you click on a link you don't fetch a new page from the server, instead you re-render the current page.

Activity icon

Replied to Web And Api Middleware - Use Cases

@bobbybouwmann thanks!

To get a better understanding, let's say that i have a multi page application and in some parts of it i use ajax requests to communicate with the server. Does it make sense to use the web middleware for both ajax and non-ajax requests ? I'm trying to understand why did Jeffrey put even the ajax requests through the web middleware. Is it more complex if you use api middleware for the ajax requests, with regards to authentication and authorization ?

May
31
3 days ago
Activity icon

Started a new Conversation Web And Api Middleware - Use Cases

Jeffrey in his videos puts in the web.php all the routes, even routes from Ajax requests, and then he used to get the authenticated user from sessions using auth()->user()

In case that I want to put the Ajax requests in api.php should I use the api middleware for stateless requests and then token based authentication to access the authenticated user Or I can use the web middleware even in api.php ?

May
23
1 week ago
Activity icon

Commented on Consider Strategizing

Here Jeffrey uses both strategy and factory pattern.

There are multiple different ways to register a user therefore, we encapsulate the logic of each different way using strategy pattern. One way is RegisterTeamMember, so we create a new class and we put that logic in there.

But, in order to decide which strategy to use, you need to have if statements to create the respective class. Thus, we can encapsulate the creation of an object using the factory method pattern.

As a result, you call getRegistrationStrategy() which is the factory method And then we call handle() on whatever is returned from the factory.

Activity icon

Commented on Encapsulated UseCases

I've been thinking whether we can dispatch a job in each strategy.

For example, instead of creating multiple methods in each Registration Strategy class, to dispatch a job in the handle() method, that will take care of all the necessary steps to complete the registration

Activity icon

Replied to Difference Between Command And Jobs

@bobbybouwmann

I have another question already :D

Instead of creating a job we can just create a simple class or a service and put the logic that we want in there.

I guess that the benefit of a job is that it comes with a set of extra functionalities, such as queues, middlewares, attempts etc.

My question is, if i don't need any of these extra functionalities, is there any disadvantage ( or just a reason ) of using a class/service instead of a job ?

May
22
1 week ago
Activity icon

Replied to Difference Between Command And Jobs

@bobbybouwmann

This example made it a lot more clear! Thanks

No i don't have a use case yet, i was just trying to understand the differences in order to make a proper use of events/listeners and jobs in the future.

Activity icon

Replied to Difference Between Command And Jobs

@bobbybouwmann

My mistake.

I meant that an event listener is similar to a job.

Regarding the events and jobs though, why would you dispatch a job in an event listener ?

If an event happens, for instance a user is registered, then we can have one or more listeners that can take actions.

My understanding was that we use jobs because we can dispatch them wherever we are and jobs can be reusable.

It is a bit confusing though, currently it seems to me like a circle. I've read a lot of other discussions but yet it's not quite clear when to use jobs and when to use event/listeners

Activity icon

Replied to Difference Between Command And Jobs

Isn't the job that you are referring to, an event listener ?

Activity icon

Replied to Difference Between Command And Jobs

@bobbybouwmann thanks for the information.

I watched a video here at Laracasts, where Taylor explained that Jobs ( named Commands at the time of the video ) are used when we have to execute a number of correlated tasks whereas commands are used for a single action. More specifically, he gave an example of purchasing a podcast. When a use purchases a podcast a number of tasks have to be executed, such as send a confirmation email, confirm payment etc. From what i understood, jobs are similar to events.

Regarding the differences between commands and jobs, there is a section on the documentation named Scheduling Jobs that confused me.

Activity icon

Replied to Web And Api Use Cases

@uhoh @martinbean Thanks!

What about the middlewares that are applied on web.php and api.php ?

For example, on the client-side i make AJAX requests to either fetch or store data and the respective routes are stored in the api.php.

Which middleware should i use for that route ? It's not clear to me when should i use the web middleware and when should i use the api middleware.

Activity icon

Started a new Conversation Difference Between Command And Jobs

I'm trying to understand what are the differences between jobs and commands.

I was reading the documentation and it seems that both jobs and commands have similar structure and both of the can be scheduled with the difference that jobs can also be queued.

And i was wondering if the only difference is that jobs can be queued.

Activity icon

Started a new Conversation Web And Api Use Cases

I am trying to wrap my head around the use cases of web routes and api routes.

So far, from what i understand

  1. Web routes, are used when we want to return views.

  2. Api routes, are used when we want to return json ( Api resource/collection ).

However both of these cases are referring to GET requests.

What about when we make a POST or PUT request, do we put these routes in api.php or web.php. Does it depend on whether the request is through an AJAX call ?

Additionally, i can't figure out in what cases should we use the api middleware and web middleware By default, the web.php uses web middleware, whereas the api.php uses the api middleware.

In the case where we are already signed in and we want to make an AJAX call, do we have to put that route in the api.php or web.php.

Do we use the api middleware only when we sign in using token based authentication ?

May
16
2 weeks ago
Activity icon

Commented on WYSIWYG

The following line

<wysiwyg v-model="form.body"></wysiwyg>

equals the following line

<wysiwyg :value="form.body" @input="form.body = $event.target.value"></wysiwyg>

As a result, you are passing a prop to which is the :value.

Therefore, in wysiwyg component, you can accept that prop and pass it to the input element like

<template>
<div>
<input :value="value" :name="name" id="trix" type="hidden" />
 <trix-editor ref="trix" input="trix"></trix-editor>
</div>
</template>
export default {
props : ['value']
}

Finally, in the wysiwyg component, we fire an input event and we pass the innertHTML of the input. Consequently, the wysiwyg component listens to that input event and updates the form.body

If it is confusing you can watch the custom input components at vuecasts as Jeff suggested

May
10
3 weeks ago
Activity icon

Started a new Conversation Email Verification Broken Uri

I'm playing around with the built-in email verification feature and i noticed that if i brake ( change ) the verification uri then i get a 403 error. On episode #74 ( forum application ) Jeffrey is redirecting the user back to email/verify in case the verification uri is broken. I want to do the same thing, but i can't figure out where should i add that logic.

Activity icon

Commented on Users Must Confirm Their Email Address: #3 - Cleanup

That works indeed!

However, when i try to assert that a notification or email was sent, it doesn't work and i can't figure out why.

When the 'Registered' event is fired, then laravel sends a 'VerifyEmail' notification.

I tried the following :


/** @test */
    public function a_confirmation_email_is_sent_upon_registration()
    {
        Event::fake();
	Notification::fake();

        $this->post(route('register'), [
            'name' => 'John',
            'email' => '[email protected]',
            'password' => 'passwordtest',
            'password_confirmation' => 'passwordtest'
        ]);

	$user = User::first();
        Event::assertDispatched(Registered::class);
	Notification::assertSentTo($user, VerifyEmail::class);
    }

The notification assertion fails with the error ' notification was not sent. ' I even tried to assert that email was sent or queued but the test didn't pass.

Any idea what i'm missing here ?

May
09
3 weeks ago
Activity icon

Commented on Thread Views: Design #2 - Extract Class

Doesn't this break the law of demeter ?

$thread->visits()->record();
Activity icon

Commented on Thread Views: Design #1 - Trait

I have a question about this approach.

We already store the score of each thread using the Trending class. In [email protected] we call

$trending->push($thread)

Which increases the score of the thread each time we click on it.

Is it a bad idea to use the same class to just get the score in order to display the number of visits ?

For example in the Trending class we can do

public function visits($thread)
{
return Redis::zscore('trending_threads', json_encode([
	'title' => $thread->title,
	'path' => $thread->path()
	]) ;
}

and in Thread.php we can do

public function getVisitsAttribute()
{
return app(Trending::class)->views($this) ?: 0;
}
May
06
4 weeks ago
Activity icon

Started a new Conversation Json Response Confusion

Hi,

I'm trying to understand the following concepts:

  1. Laravel automatically converts arrays, collections, model to json
  2. toJson()
  3. response()->json()

According to laravel's documentation, laravel converts automatically arrays and collections to json format and adds to the header the content-type to be equal to application/json. Therefore, from what i understand, whenever you want to return a single row or a collection of rows from the database to the front-end, there is no need to convert anything to json, because laravel takes care of that.

But then i also read on laravel's documentation the following

'To convert a model to JSON, you should use the toJson method.'

The only difference that i noticed when i called this method is that the content-type actually is not 'application/json' but 'text-html'.

Activity icon

Commented on Instant Username Autocompletion

One change that i would made in your implementation, is to change the order of take and pluck

From this

$val =  User::where('name', 'LIKE', "$search%")
            ->take(5)
            ->pluck('name');

To this

$val =  User::where('name', 'LIKE', "$search%")
	->pluck('name')
        ->take(5);         

That way, i think it is a little bit more efficient since you retrieve only the column name of 5 records, instead of retrieving all columns of 5 rows and then filtering out the names.

Correct me if I am wrong

May
04
4 weeks ago
Activity icon

Commented on A User May Not Reply More Than Once Per Minute

i have the exact same question

May
03
1 month ago
Activity icon

Replied to ParticipateInThreadsTest Error

I kind of have an issue as well and i am at episode 49 ( Spam detection )

When i throw an Exception in the Reply Controller, for some reason it is not detected in the test.

/** @test */
    public function replies_that_containt_spam_may_not_be_created()
    {
        $this->signIn();
        $thread = create('App\Thread');
        $reply = make('App\Reply', [
            'body' => 'Yahoo Customer Support',
        ]);

        $this->expectException(\Exception::class);

        $this->post($thread->path() . '/replies', $reply->toArray());

    }

And the controller looks like this. It has to be mentioned that the if statement works and anything inside the if statements is executed. So the if statement is not the problem.


 public function store($channelId, Thread $thread)
    {

        request()->validate([
            'body' => 'required',
        ]);

        if (stripos(request('body'), 'yahoo customer support') !== false) {

            throw new \Exception('Your reply contains spam');
        }

The error that i get is

Failed asserting that exception of type "Exception" is thrown.

However if i try to trow the Exception within the test then it works.


 public function replies_that_containt_spam_may_not_be_created()
    {
        $this->signIn();
        $thread = create('App\Thread');
        $reply = make('App\Reply', [
            'body' => 'Yahoo Customer Support',
        ]);

        $this->expectException(\Exception::class);
	
	throw new \Exception('Your reply contains spam');

        $this->post($thread->path() . '/replies', $reply->toArray());

    }

Additionally if i check the type of the exception that is thrown inside the controller, then again it works, which means that the dd('Bingo') is executed;

 try {
            if (stripos(request('body'), 'yahoo customer support') !== false) {

                throw new \Exception('Your reply contains spam');
            }
        } catch (Exception $e) {
            if ($e instanceof \Exception) {
                dd('Bingo');
            }
        }

Any idea what might be the issue ?

------ UPDATE --------

I just noticed that the test is passing when i include the following line in my test

$this->withoutExceptionHandling();

However i don't understand why is this happening and if that solves the issue or whether it is just a workaround

May
02
1 month ago
Activity icon

Commented on Thread Subscriptions: Part 4

Is there a reason for not using a many-to-many relationship between threads and users for the subscription ?

What i mean is the following :

class Thread extends Model {


public function subscribers()
{
	return $this->belongsToMany('App\User', 'thread_subscriptions');
}
}

class User extends Model {

public function subscriptions()
{
	return $this->belongsToMany('App\Thread', 'thread_subscriptions');
}

}

Because in my mind it makes things more clear and it also avoids creating an extra model for the subscriptions. For example in the addReply() method

Jeffrey did

foreach ($this->subscriptions as $subscription)
{
	$subscription->user->notify(new ThreadWasUpdated($this, $reply)
}

Whereas if we use many-to-many relationship we could replace that with

foreach ($this->subscribers as $subscriber)
{
	$subscriber->notify(new ThreadWasUpdated($this, $reply)
}
Apr
23
1 month ago
Activity icon

Commented on Build A Like/Dislike System

Can we eager load the likes relationship in the Tweet model instead of in the User model when we implement the function

isLikedBy(User $user) 

To explain further, does it make a difference if we add a protected $with variable to eager load the likes for each tweet such as

class Tweet extends Model {

protected $with = ['likes']

}

And then in the isLikedBy function

public function isLikedBy(User $user)
{
	$this->likes->where('user_id', $user->id)->where('liked', true) 
}

Apr
21
1 month ago
Activity icon

Commented on Build The Explore Users Page

Using a form request, in the controller we can get all the validated attributes with

$request->validated()

The returned value of the method above, includes the 'avatar' attribute. Is there a way to exclude the 'avatar' attribute when the user doesn't upload a new avatar in the edit form ? Such as to avoid

if (reqeust('avatar')){
	$attributes['avatar'] = request('avatar')->store('avatars');

and instead of that to directly update the database

$user->update($request->validated());

EDIT

The solution was to add 'nullable' in the validation rules. For example

'avatar' => 'nullable'

and add a mutator as well

 public function setAvatarAttribute($value)
    {
        $this->attributes['avatar'] = $value->store('avatars');
    }
Apr
11
1 month ago
Activity icon

Replied to Laravel Bug In Traits Boot Method Auth Access?

I have the same issue

Activity icon

Commented on How To Construct An Activity Feed With TDD

For some reason the authentication check doesn't work inside the Trait. For me both auth()->guest() and auth()->check() are true inside the Trait

Apr
10
1 month ago
Activity icon

Commented on Open-Closed

In the beginning the, in order to follow the SRP, the calculation of the area was a separate class but then in order to follow the OCP, the calculation of the area was added back to each shape ( Circle, Square). Doesn't this break the SRP ?

Mar
28
2 months ago
Activity icon

Commented on Beware False Positives

why don't we take advantage of the project_members pivot table with a belongsToMany relationship.

My point is that in the accessibleProjects() function to use something like this

return $this->belongsToMany(Project::class, 'project_members') 

which can be merged with the projects owned by a user.

Therefore, we will have access to both shared projects and projects owned by a user, as well as a function to fetch all projects

public function projects()
    {
        return $this->hasMany('App\Project', 'owner_id')->latest('updated_at');
    }
    public function sharedProjects()
    {
        return $this->belongsToMany('App\Project', 'project_members')->latest('updated_at');
    }

    public function allProjects()
    {
        return $this->sharedProjects->merge($this->projects);
    }
Mar
12
2 months ago
Activity icon

Commented on Go Go Gadget Tailwind

hi,

For some reason when i enter the "mx-auto" class in the containers, nothing happens. In addition, the shadows don't change. it still pulls from the app.css where the value is different even after it compiles.

However the compilation works because when i try to change the background color for example using the "bg-white", it does affect the page.

Does anybody know what might be the issue ?

Mar
07
2 months ago
Activity icon

Commented on Limit Access To Authorized Users

is there a github link for the code that was already written ?