Nakov

Nakov

at SOLID Solutions

Member Since 4 Years Ago

Skopje

Experience Points
724,720
Total
Experience

0 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
1684
Lessons
Completed
Best Reply Awards
928
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 50
724,720 XP
May
30
1 day ago
Activity icon

Replied to How Get Parent If Child Have Data

@ethar if you just consider following the rules of the framework, and do it per the documentation everything will work as it should :) and you did not even tried what I gave you, but considered it as just doesn't work or gives you error. And do you expect me to guess your error, or you can share it so someone here might help you more :)

Activity icon

Awarded Best Reply on Using "with" After "hasMany"

@zizi_ove then you've got a lot more reading to do my friend :) a simple answer here will not give you much better result.

The problem to solve here is to load a Tree of data, like a Category can have a Sub Category, and the Sub Category can have another Sub Category. The with() helper in Laravel will eager load, which means will perform one query to fetch all the results, otherwise you will have to do them in multiple separate queries.

https://laravel.com/docs/7.x/eloquent-relationships#eager-loading

Activity icon

Replied to How Get Parent If Child Have Data

@ethar if you set it up correctly there is no reason why not to work.

So I see you have track_id in your Course table, so in your track model, you can just add this:

public function courses()
{
    return $this->hasMany(Course::class);
}	

And then to get it, you just use:

Track::has('courses')->get();

https://laravel.com/docs/master/eloquent-relationships#querying-relationship-existence

May
29
2 days ago
Activity icon

Replied to Get Last 4 Digits Of Card From PaymentIntent Object In Stripe PHP

Not really directly, but you can work around that.

Here are all the properties available on the payment intent: https://stripe.com/docs/api/payment_intents/object

So in order to get the last4 you will have to fetch all the payment methods for the customer, and then from the payment intent check which payment_method_types are used for the payment, if card is in it, then from the payment methods you will have the card object, and get the last4 from there.

https://stripe.com/docs/api/payment_methods

Activity icon

Replied to Using "with" After "hasMany"

@zizi_ove then you've got a lot more reading to do my friend :) a simple answer here will not give you much better result.

The problem to solve here is to load a Tree of data, like a Category can have a Sub Category, and the Sub Category can have another Sub Category. The with() helper in Laravel will eager load, which means will perform one query to fetch all the results, otherwise you will have to do them in multiple separate queries.

https://laravel.com/docs/7.x/eloquent-relationships#eager-loading

May
28
3 days ago
Activity icon

Awarded Best Reply on Multiple File Upload Validation

I believe the issue here is that the size of the array is unknown, hence you don't get any validation errors for the rest of the images.

You might be good if you send the total number of images that needs to be validated in a hidden field or something, and then iterate in your request validator and add a rule for each index.

This is what worked for me:

<form action="/testing-upload" method="post" enctype="multipart/form-data">
                    @csrf
                    <input class="fileUpload @error('image.0') is-invalid @enderror" name="image[]" type="file" value="{{ old('image.0') }}">
                    <input class="fileUpload @error('image.1') is-invalid @enderror" name="image[]" type="file" value="{{ old('image.1') }}">
                    <input class="fileUpload @error('image.2') is-invalid @enderror" name="image[]" type="file" value="{{ old('image.2') }}">
                    <input class="fileUpload @error('image.3') is-invalid @enderror" name="image[]" type="file" value="{{ old('image.3') }}">

    <input type="hidden" name="images" value="4">
 <button type="submit">Submit</button>
</form>

NOTE the hidden field with total number of images expected, you can also get that dynamically if you need to.

Then in the controller:

$images = $request->input('images');

$rules = [];
for ($i = 0; $i < $images; $i++) {
    $rules['image.' . $i] = 'required|image|mimes:jpeg,png,jpg|max:10000';
}

$validate = Validator::make($request->all(), $rules);

dd($validate->fails(), $validate->errors());

You can do the same in the form request as well, instead of $request->input it will be $this->input()

And this is the result that I got from selecting only the first image:

Illuminate\Support\MessageBag {#1249 ▼
  #messages: array:3 [▼
    "image.1" => array:1 [▼
      0 => "The image.1 field is required."
    ]
    "image.2" => array:1 [▼
      0 => "The image.2 field is required."
    ]
    "image.3" => array:1 [▼
      0 => "The image.3 field is required."
    ]
  ]
  #format: ":message"
}

3 other error messages which is expected.

Activity icon

Replied to Multiple File Upload Validation

I believe the issue here is that the size of the array is unknown, hence you don't get any validation errors for the rest of the images.

You might be good if you send the total number of images that needs to be validated in a hidden field or something, and then iterate in your request validator and add a rule for each index.

This is what worked for me:

<form action="/testing-upload" method="post" enctype="multipart/form-data">
                    @csrf
                    <input class="fileUpload @error('image.0') is-invalid @enderror" name="image[]" type="file" value="{{ old('image.0') }}">
                    <input class="fileUpload @error('image.1') is-invalid @enderror" name="image[]" type="file" value="{{ old('image.1') }}">
                    <input class="fileUpload @error('image.2') is-invalid @enderror" name="image[]" type="file" value="{{ old('image.2') }}">
                    <input class="fileUpload @error('image.3') is-invalid @enderror" name="image[]" type="file" value="{{ old('image.3') }}">

    <input type="hidden" name="images" value="4">
 <button type="submit">Submit</button>
</form>

NOTE the hidden field with total number of images expected, you can also get that dynamically if you need to.

Then in the controller:

$images = $request->input('images');

$rules = [];
for ($i = 0; $i < $images; $i++) {
    $rules['image.' . $i] = 'required|image|mimes:jpeg,png,jpg|max:10000';
}

$validate = Validator::make($request->all(), $rules);

dd($validate->fails(), $validate->errors());

You can do the same in the form request as well, instead of $request->input it will be $this->input()

And this is the result that I got from selecting only the first image:

Illuminate\Support\MessageBag {#1249 ▼
  #messages: array:3 [▼
    "image.1" => array:1 [▼
      0 => "The image.1 field is required."
    ]
    "image.2" => array:1 [▼
      0 => "The image.2 field is required."
    ]
    "image.3" => array:1 [▼
      0 => "The image.3 field is required."
    ]
  ]
  #format: ":message"
}

3 other error messages which is expected.

Activity icon

Replied to Multiple File Upload Validation

@kingarthur86 it will help if you share how are you validating it, not just the rules. Do you validate using the Validator Facade, or directly on the request.

Because if you use the facade you should always manually check if the validation failed or succeeded.

May
26
5 days ago
Activity icon

Awarded Best Reply on How To Automatically Verify Email Of Users Created Through Administration(not Registration)?

@CVETAN - no, because the user has to exist. You can than add

$user->email_verified_at = Carbon::now();

Then call the save method.

May
25
6 days ago
Activity icon

Replied to BelongsTo Relation Gets Null Output.

@princeoo7 why going against what the frameworks says? Why using an accessor method for a relationship?

You can have just this:

public function brand() {
    return $this->belongsTo(Brand::class);
}	

And then use it like this:

$product->brand

Which will load the relationship.

Activity icon

Replied to Middleware Check Login Not Working

@kharnam do you use the default auth guard, or you need to specify which one you use?

Auth::check() expects that you use the web guard. If you don't then specify it:

Auth::guard('your-guard')->check()
Activity icon

Replied to Middleware Check Login Not Working

@kharnam

you probably have this route('login') surrounded with the auth middleware as well, so it redirects there multiple times.

What happens if you try this instead:

public function handle($request, Closure $next)
{
    if( Auth::check() ) {
        return $next($request);
    }

    abort(403);
}
May
24
1 week ago
Activity icon

Replied to Call To A Member Function GetActiveOrder() On Null

Yes, sorry firstOrFail is not a method on the collection.

So you should check maybe if it returns null to show a message to the user, and not proceed with using the activeProject as there is none active using that ID I guess.

Activity icon

Replied to Call To A Member Function GetActiveOrder() On Null

The reason for the exception is because this line:

$activeProject = $projects->where('id', request()->project_id)->first();

->first() returns null in case no project with that ID is found in the collection. So use firstOrFail() if you want an exception to be thrown and the program should not continue.

And to dump the data you can use dd() helper within the controller, like this:

$activeProject = $projects->where('id', request()->project_id)->first();
dd($activeProject);

This will die and dump the data that is being returned.

May
23
1 week ago
Activity icon

Awarded Best Reply on Traverse All The Items In A Collection

Here is a nice post that has your answer : https://laraveldaily.com/eloquent-recursive-hasmany-relationship-with-unlimited-subcategories/

Just use Page instead of Category :)

Activity icon

Replied to Traverse All The Items In A Collection

Here is a nice post that has your answer : https://laraveldaily.com/eloquent-recursive-hasmany-relationship-with-unlimited-subcategories/

Just use Page instead of Category :)

Activity icon

Awarded Best Reply on Appear As {{ Title }}

Might be because of this:

el: '#app',

and your id on the container is app1.

Activity icon

Replied to Appear As {{ Title }}

Might be because of this:

el: '#app',

and your id on the container is app1.

May
18
1 week ago
Activity icon

Replied to Use Of Undefined Constant Templates - Assumed 'templates'

Is there any chance in some place you have @extends(templates.default) without the single quotes in the blade directive?

May
17
2 weeks ago
Activity icon

Replied to Laravel Passport How To Logout User?

The error is because you are calling logout on the wrong guard. But this is what I found for handling the auth part, maybe it will help you as well: https://blog.andrewjamesbibby.com/2019/02/04/how-to-manage-authentication-with-laravel-passport-and-vue-js/

Activity icon

Replied to Laravel Passport How To Logout User?

@talion as you said you are maintaining a web session as well, so maybe you need to call Auth::logout(); after you revoke the token.

Activity icon

Replied to Problem With Custom Attribute's Model

@carpad88 I don't think that there is a right or wrong way to do things, it is all a personal stuff and based on your projects needs.

I am not sure I understand exactly what your problem to solve is here, but I would assume that each of the resources, either book, magazine or web has their own respective models in which you store their name, + their author. So if it was me personally, then I will add a custom attribute either to a Trait that they will all share, or a single method in each of the models.

So in Book model:

public function getNameTypeAttribute()
{
    	return strtoupper($this->type)." | {$this->author} | {$this->title}";
}

in Magazine model:

public function getNameTypeAttribute()
{
     // I guess you won't have `magazine` here but either title or whatever
    return strtoupper($this->type)." | {$this->magazine} | {$this->author}";
}

But again this will be my personal preference, not saying it is the right way to do things :)

Happy coding!

Activity icon

Awarded Best Reply on Problem With Custom Attribute's Model

@carpad88

Laravel stores all the values in an $attributes array which then gets returned from the model toArray() method..

So that's why when you try to return $this you are returning the whole model as an array, which you can access the value by its key.

The proper usage of the accessor functions is very well described in the documentation: https://laravel.com/docs/master/eloquent-mutators#accessors-and-mutators

so for your usage it should be:

public function getNameTypeAttribute($value)
{
    return $value; // do something with the value here.
}
Activity icon

Replied to Problem With Custom Attribute's Model

@carpad88

Laravel stores all the values in an $attributes array which then gets returned from the model toArray() method..

So that's why when you try to return $this you are returning the whole model as an array, which you can access the value by its key.

The proper usage of the accessor functions is very well described in the documentation: https://laravel.com/docs/master/eloquent-mutators#accessors-and-mutators

so for your usage it should be:

public function getNameTypeAttribute($value)
{
    return $value; // do something with the value here.
}
Activity icon

Awarded Best Reply on Call To A Member Function GetClientOriginalExtension() On Null

@billok-lab having different variables for the file instead of keeping $file and overriding it each time will help you understand where the error comes from better.

Then you use required_if rule for some of the files, which mean that if the status is not as you expect it, then a file is not required, and yet you have no check in your controller if the file is there or not and hence the error, because a file did not exists, but you still try to get it's extension.

So here is an example on how to prevent this:

$registration = new Registration; // add this below the request validation
 

if ($request->hasFile('student_report'))
{
    $file = $request->file('student_report');
    $file_student_report = 'Student_Report-' . time().'.'.$file->getClientOriginalExtension();
    $registration->student_report= $file->storeAs('file_student_report', $file_student_report);
}

...

// call save at the bottom
$registration->save();
Activity icon

Replied to Call To A Member Function GetClientOriginalExtension() On Null

@billok-lab having different variables for the file instead of keeping $file and overriding it each time will help you understand where the error comes from better.

Then you use required_if rule for some of the files, which mean that if the status is not as you expect it, then a file is not required, and yet you have no check in your controller if the file is there or not and hence the error, because a file did not exists, but you still try to get it's extension.

So here is an example on how to prevent this:

$registration = new Registration; // add this below the request validation
 

if ($request->hasFile('student_report'))
{
    $file = $request->file('student_report');
    $file_student_report = 'Student_Report-' . time().'.'.$file->getClientOriginalExtension();
    $registration->student_report= $file->storeAs('file_student_report', $file_student_report);
}

...

// call save at the bottom
$registration->save();
Activity icon

Replied to Allow Retry After Linking Wrong Google Account W/ Socialite?

@cotton9 I think I gave you the option on how to force account selection, I am not paid to work out the exact solution for your needs. You will have to do that.

May
16
2 weeks ago
Activity icon

Replied to Error Explode() Expects Parameter 2 To Be String, Array Given

@fajar I don't understand your point.

Can you give me expected result please?

Activity icon

Replied to Error Explode() Expects Parameter 2 To Be String, Array Given

@fajar if you want to store them in one column, then you use a json_encode() on the array.

Activity icon

Replied to Error Explode() Expects Parameter 2 To Be String, Array Given

@fajar Look at the error message, and then you result what does it says?

The error message says I don't want you to give me array ( your result ) I want a string..

So if you try just this:

explode('-', "Deaved Covid-19");

then you will get an array like this:

=> [
     "Deaved Covid",
     "19",
   ]
Activity icon

Awarded Best Reply on Message That Is Displayed Only Once To The User.

Hey @joaquinvilchez

My approach to this would be to reuse the Laravel built in notification system. So you dispatch a notification to all the users in the system called ReleaseNotes for example, and on the home page, check if there are unread notifications when the user logs in, display them. You can filter just those notifications in case you have more types.

And there is an option to mark the notification as read, so the user can do that with a button on the same modal, in which case the next time won't appear.

Take a look at the docs: https://laravel.com/docs/master/notifications#database-notifications

Activity icon

Replied to Message That Is Displayed Only Once To The User.

Hey @joaquinvilchez

My approach to this would be to reuse the Laravel built in notification system. So you dispatch a notification to all the users in the system called ReleaseNotes for example, and on the home page, check if there are unread notifications when the user logs in, display them. You can filter just those notifications in case you have more types.

And there is an option to mark the notification as read, so the user can do that with a button on the same modal, in which case the next time won't appear.

Take a look at the docs: https://laravel.com/docs/master/notifications#database-notifications

May
15
2 weeks ago
Activity icon

Replied to URL 404 Issue

You have a prefix that you are not applying so maybe try this:

{{ url('cuser/checkout/basic') }}
May
14
2 weeks ago
Activity icon

Awarded Best Reply on Response Status Code [404] Is Not A Redirect Status Code.

@browniecoffee I think your error is here:

$response = $this->post(('loginPost'), [
            'email' => $user->email,
            'password' => $user->password,
        ]);

you should write:

$response = $this->post(route('loginPost'), [
            'email' => $user->email,
            'password' => $user->password,
        ]);

missing route() helper for the loginPost

Activity icon

Replied to Response Status Code [404] Is Not A Redirect Status Code.

@browniecoffee I think your error is here:

$response = $this->post(('loginPost'), [
            'email' => $user->email,
            'password' => $user->password,
        ]);

you should write:

$response = $this->post(route('loginPost'), [
            'email' => $user->email,
            'password' => $user->password,
        ]);

missing route() helper for the loginPost

Activity icon

Awarded Best Reply on How To Get Only One KeyBy Value Instead?

Have you tried using pluck() instead:

$settings = Settings::all()->pluck('value', 'key');
Activity icon

Replied to How To Get Only One KeyBy Value Instead?

Have you tried using pluck() instead:

$settings = Settings::all()->pluck('value', 'key');
May
13
2 weeks ago
Activity icon

Awarded Best Reply on Issue With Dependency Injection In Controller Method

It should essentially do just

$bulk = new Bulk;

but if that's the case then why injecting it ? You can just initialize it yourself :)

Activity icon

Replied to Issue With Dependency Injection In Controller Method

It should essentially do just

$bulk = new Bulk;

but if that's the case then why injecting it ? You can just initialize it yourself :)

Activity icon

Replied to {{$posts->links()}} : Call To Undefined Method

@captainburah the comment by @wingly should solve your issue:

@foreach($posts as $post)
    <div class="card card-body mt-3">
        <h3><a href="/posts/{{$post->id}}">{{$post->title}}</h3>
         <small>Written on {{$post->created_at}}</small>
    </div>
@endforeach		
{{$posts->links()}}
Activity icon

Replied to {{$posts->links()}} : Call To Undefined Method

Are you copy pasting the full files or just partials? Because your controller does not look good if that's the full content.

you place it below the initialization in the controller:

$posts = Post::orderBy('title', 'desc')->paginate(10);

dd($posts);
Activity icon

Replied to {{$posts->links()}} : Call To Undefined Method

Bootstrap has nothing to do with it.

I just doubt that on the page where you use $posts->links() you are not using a paginated results.

Try dumping the results of $posts in your controller and make sure that the object is an instance of a Paginator.

You can do that using dd($posts);. If it doesn't stops, that means that the posts are coming in from somewhere else. In case you use a View Composer and you share the posts from within the composer, than this values will be overwritten.

Activity icon

Replied to Issue With Dependency Injection In Controller Method

And what do you have in your Bulk class in the constructor? Are you telling the service container how to initialize a new Bulk object?

Activity icon

Replied to {{$posts->links()}} : Call To Undefined Method

@captainburah how sure are you that the error comes from using $posts->links()?

Can you remove that from the page, and try to reload to ensure that the page loads without using that?