Nakov

Nakov

Member Since 3 Years Ago

Skopje

at SOLID Solutions

Experience Points 75,220
Experience Level 16

4,780 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 672
Lessons
Completed
Best Reply Awards 14
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

20 Feb
2 days ago

Nakov left a reply on How To Check Or Uncheck All Checkbox From One Button

You can do it with a single function and using the state from the first checkbox only, so here is one solution:

function checkAll1() {
  let checkboxes = document.getElementsByName('check1');
  let state = checkboxes[0].checked;

  for(let i=0, n = checkboxes.length; i < n; i++) {
    checkboxes[i].checked = state;
  }
}

I use the same function name as you do for checking all, but you can rename that to be more descriptive.

Nakov left a reply on Custom Service Provider Gives Purify Errors In PHPUnit Test

@thyrosis as a last piece of advice, have you tried opening an issue on the github page for the library and see if some of the maintainers of the code would give you an answer?

16 Feb
6 days ago

Nakov left a reply on Laravel Relation One To Many (Polymorphic)

The error is because you don't have an admin_id in your jobs table. Is the Admin a Client?

If it is then modify your jobs function in your Admin model as such:

public function jobs()
{
    return $this->hasMany('App\Job',  'client_id'); // client_id here is the foreign_key.
}

If the admin should be able to see all the jobs, then you don't need that function, and check if the user is admin and get all the jobs using Job::all()

15 Feb
1 week ago

Nakov left a reply on Laravel Eloquent Where Date Is Equal Or Smaller Than DateTime

@sinres you can change the format of the date using the $casts field in the model, but that won't help with the query. So if you just want to display the date in a different format, add this in your model class containing the inspection_date field:

protected $casts = [
    'inspection_date' => 'date:d-m-Y'
];

Nakov left a reply on Laravel Eloquent Where Date Is Equal Or Smaller Than DateTime

Are you sure that the format in the database is d-m-Y, is it maybe Y-m-d which is the default for a date?

13 Feb
1 week ago

Nakov left a reply on Custom Validator (using Extensions) Pass Parameter

So, using your approach, you will need to have the product value in the validate array in order to access it within your custom method:

$request->validate([
    'product' => 'required',
    'amount' => 'required|integer|canPlaceOrder',
]);

Then in your custom function you can get the value:

public function placeOrder($attribute, $value, $parameters, $validator){
     $product = array_get($validator->getData(), $parameters[0], null); // using array_get in case the parameter is not found so it defaults to null.
// and I believe you can access the current user like this
$user = auth()->user();

}

But a much better approach I believe would be if you instead create a custom rule:

class PlaceOrder implements Rule
{
    private $product;
    private $user;

    public function __construct($product, $user)
    {
        $this->product = $product;
        $this->user = $user;
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
         // return a boolean here matching your rule. and you can access the user and product
         // $this->user, $this->product..
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return 'The :attribute must match product.';
    }
}

Then in order to use it:

$request->validate([
     'amount' => ['required', 'integer', new PlaceOrder($product, $request->user())],
]);

Nakov left a reply on Custom Service Provider Gives Purify Errors In PHPUnit Test

This is true if you have cached the wrong configuration, because once cached it defaults to that version, and it will never call the setupDefinitions. So whenever you change something I think that you should clear the cache, here is a note from the library itself:

Note: Remember that after this definition is created, and you have ran Purify::clean(), the definition will be cached, and you will have to clear it from your storage/app/purify folder if you want to make changes to the definition.

Otherwise, you will have to change the definition version number or ID for it to be re-cached.
11 Feb
1 week ago

Nakov left a reply on Custom Service Provider Gives Purify Errors In PHPUnit Test

I tried to google your problem, and the only thing that I've found that makes sense and I don't know if you have tried it, is to add the allowed frame target. Change _blank with whatever target you use.

$config->set('Attr.AllowedFrameTargets', array('_blank')); 

Other than that I don't think that the problem is specific to the testing env only. You can try removing the custom code in the provider and you will see that the error will be different. Which means that the provider will be booted, but some of the configs are wrong, I am saying all of this based on your error message.

Nakov left a reply on Custom Service Provider Gives Purify Errors In PHPUnit Test

Okay, so based on your provider, I think that you should add the logic within the boot function instead of register.

Nakov left a reply on Custom Service Provider Gives Purify Errors In PHPUnit Test

I think that the Service provider is being booted but the thing that does not work is that you don't have the target attribute in your allowed HTML attributes list. So open the purify.php config file, and change this:

'HTML.Allowed' => 'h1,h2,h3,h4,h5,h6,b,strong,i,em,a[href|title],ul,ol,li,p[style],br,span,img[width|height|alt|src]',

with this:

'HTML.Allowed' => 'h1,h2,h3,h4,h5,h6,b,strong,i,em,a[href|title|target],ul,ol,li,p[style],br,span,img[width|height|alt|src]',

notice the target within the a tag.

10 Feb
1 week ago

Nakov left a reply on Stripe: Can't Attach Card Holder Name To Stripe Card Source

There is no direct name parameter when creating source, so you should pass it as the owner name like this:

stripe.createSource(cardNumberElement,  { owner: { name: self.cardHolder}).then(function(result) {
    if (result.error) {
       self.cardErrors = result.error.message;
    }  else {
       stripeSourceHandler(result.source);
    }
});
04 Feb
2 weeks ago

Nakov left a reply on Can I Cancel After The Free Trial Without Being Charged?

Forge asks for payment details before you register. So 5 day free trial means you have 5 days to test and decide. If you haven't cancelled within the 5 day free trial period, you are considered to like the service and keep using it, which means you will have to pay. You can cancel anytime after the 5 days free trial, but you will pay for that month.

03 Feb
2 weeks ago

Nakov left a reply on Issue With Eloquent's Collection Put Method.

@GABOTRONIX - You can still use firstOrFail as the get() will return a collection but I guess here you just need the first item that has been found by the query. So simply instead of using put you can set the custom property itself:

// instead of
$discount->put('stockLeft', $stockLeft);

// change it to
$discound->stockLeft = $stockLeft;

Nakov left a reply on Issue With Eloquent's Collection Put Method.

put() is a method of a collection, but firstOrFail() returns an instance of the model, so hence the error trying to call a method that does not exist on the model.

30 Jan
3 weeks ago

Nakov left a reply on Email Verification Not Being Sent First Time

You will need to register the Registered event in your event service provider which will fire the SendEmailVerificationNotification listener.

So in your EventServiceProvider add this in your $listen array:

protected $listen = [
        Registered::class => [
            SendEmailVerificationNotification::class,
        ],
];

And the imports on top:

use Illuminate\Auth\Events\Registered;
use Illuminate\Auth\Listeners\SendEmailVerificationNotification;
26 Jan
3 weeks ago

Nakov left a reply on Custom Login

Laravel uses email as a default username. So in your custom login controller, you should use the AuthenticatesUsers trait, and override the username function to match your field as I see you use email_id field.

Put this in your controller:

public function username()
  {
      return 'email_id';
  }
23 Jan
4 weeks ago

Nakov left a reply on Help In Eloquent

In order to get the extra attributes from the pivot table, like the job_status you can change your function like this:

public function technicians(){
    return $this->belongsToMany('\App\Technician')->withPivot('job_status');
}

Then in your Job model, you can add a function:

public function scopeCompletedBy($query)
{
    return $query->whereHas('technicians', function($query) {
        $query->where('job_status', 'completed');
    });
}

Nakov left a reply on Remove Comma From Double Integer Value

Comma is , so you have no comma in your value. But you can cast the result to an int value:

$cents = (int) (2.99*100);
22 Jan
1 month ago

Nakov left a reply on Default Value For Nova Number Field

@GOATSHARK - There is an ongoing discussion on github here. So one guy has mentioned that it might not work for a Number field if the default value you try to set is 0. Just keep that in mind. As I saw that your min value is 1, I thought that this should work.

Nakov left a reply on Default Value For Nova Number Field

Have you tried this:

Number::make('Quantity')->min(1)->max(1000)->step(1)->withMeta(['value' => 1]);
20 Jan
1 month ago

Nakov left a reply on How To Use External Javascript Function In Blade

One thing I can think of is you are not at your homepage, so if your url is for example example.com/test your js file should exist in public/test/js.. for that reason you can try to use the absolute path to the public directory by prefixing your script with /, so you should use the following:

{{ mix('/js/search.js') }}

Note the starting /. That will look in public/js directory.

19 Jan
1 month ago

Nakov left a reply on I Need Explain The Relationship Code

It means to cast the result to a boolean true or false the count should return total number of items by your check, if the result is > 0 then it will return true otherwise false.

14 Jan
1 month ago

Nakov left a reply on Prevent Login Of A User, If $user->status == "blocked"

The most elegant way for such a thing is creating your own middleware, you can read more about it here.

Nakov left a reply on Using Parameters In The URL

Yes it will, but you gotta make sure that the request contains that attribute in a query string like this, because if you forget to pass it, or the user deletes it, the request will return 404.

Nakov left a reply on Using Parameters In The URL

You can easily define your route without the parameters. For example:

Route::get('/test/create', '[email protected]');

Then in your controller function:

public function index()
{
    dd(request()->all()); // here you will receive an array ['id' => 1];
}

Nakov left a reply on Where Are All The Functions Of "Model"

There are good series on the site for this here

this is not really a PHP thing only, but it is inheritance which is an OOP concept.

13 Jan
1 month ago

Nakov left a reply on Image Is Not Showing In Index Page From Admin Panel

@AAAA1111 - sorry, but not having your code I can't help you much more than what I've already said. I am 100% sure that it is something with the URL used, so inspecting the image element in the index page, and looking at the src after the page has been loaded should give you more info on where to look at. Or just try to use url() helper function instead of the asset() and see if that helps.

Nakov left a reply on Image Is Not Showing In Index Page From Admin Panel

@AAAA1111 - Does the store method works for you? Can you look in your project public/images/... directory and make sure that when you upload an image the image can be found there? The error says 404 because the image cannot be found, so you need to make sure that you use the correct URL. I assume that the error shows in which location it tries to find the image, so based on that you should check your public folder.

Nakov left a reply on Image Is Not Showing In Index Page From Admin Panel

@AAAA1111 - Can you please check in your browser, inspect the image element and make sure that the url is correct and the picture can be found on that location. Or share the exact error that you are getting here.

Nakov left a reply on Image Is Not Showing In Index Page From Admin Panel

I believe that the problem is because of missing / at the beginning of the URL, so I assume that your images folder is within the public directory, then just changing it with this:

  <img src="{{ asset('/images/backend_images/products/small/'.$product->image) }}" 

will do the work. Because when you are on the index page, it uses the correct path, but when you are on different page, for example yourdomain.com/products it will try to find the image in products/images ... instead of just yourdomain.com/images. Hope this helps.

11 Jan
1 month ago

Nakov left a reply on SQLSTATE[42S01]: Base Table Or View Already Exists ? Install Admin Panel Issue !

The error is self-explanatory. The database that you are using already contains table named settings. Do you maybe accidentally renamed one of your migrations, or removed the row in the migrations table which creates the settings table so when you run php artisan migrate you get this error? You might wanna start fresh if you don't have any important data in your database.

Nakov left a reply on How To Access Json Data From Database

You are casting your address to an array, so you should be able to access the street from an array as such $address['street'].

Nakov left a reply on Custom Validation Rule Returns Incorrect Validation Message

Have you read the documentation for the custom validation rules? Here is the [link] (https://laravel.com/docs/master/validation#custom-validation-rules)

$rules = [
    'field_name' => [new Foo]
];

should be the usage, which then will use the overriden message function.

Otherwise if you just extend the Validator instance your message should be placed in your validation.php language file, within the custom array, so there you should have

'custom' => [
        'foo' => 'Your message here',
],
10 Jan
1 month ago

Nakov left a reply on Class App\Http\Controllers\ContactRequest Does Not Exist

In your controller you are using the wrong import for the ContractRequest class, try changing this:

use App\Http\Controllers\ContactRequest; to use App\Http\Requests\ContactRequest;

07 Jan
1 month ago

Nakov left a reply on Laravel @include Path - How To Go Back

You will first need to register a path to your custom views, in config/view.php add it to the list of paths

'paths' => [
        resource_path('views'), 
        resource_path('custom'),
    ],

Then you can create your custom blade views within your custom resource directory, and including them is the same as any other view existing in the views folder.

02 Jan
1 month ago

Nakov left a reply on Trim All Values In A Collection

When you iterate over the $records why don't you trim the whitespaces then before making the array? Like this:

foreach ($records as $offset => $record) 
{ 
    $data[] = trim($record); 
}
30 Dec
1 month ago

Nakov left a reply on Generate Navigation Menu Links In The Layout

I think that what you are looking for is a View composer, so take a look at this: https://laravel.com/docs/master/views#view-composers

29 Dec
1 month ago

Nakov left a reply on Custom Exception (get Message)

You can do that when you catch the custom exception.

try {
   // call out the code/function that throws the custom exception
} catch (ConnectionExceptionCustom $exception) {
    \Log::error('Exception message here: ' . $exception->getMessage());
}

Nakov left a reply on Validation If One Field Is Filled Then Others Are Required

@MUBEENALI - Now it is easier to test, so try this validation:

$validator = Validator::make(request()->all(), [
        'holidays_title.*'         => 'min:1|required_with:opening_holidays_hours.*,closing_holidays_hours.*',
        'opening_holidays_hours.*' => 'required_with:holidays_title.*,closing_holidays_hours.*',
        'closing_holidays_hours.*' => 'required_with:holidays_title.*,opening_holidays_hours.*',
    ], [
        'opening_holidays_hours.*' => 'Testing' // you can override the test message with this third parameter, because you don't want holidays_title.0 field is required to be your message.
    ]);
28 Dec
1 month ago

Nakov left a reply on Validation If One Field Is Filled Then Others Are Required

@MUBEENALI - The problem is because your first field is an array and it always contains value as it seems. You need to work that one out. I tested what have shared with you, and if all 3 fields are empty the form passes otherwise if only one field has a value it requires the other two fields to contain value as well.

you can share your view code so I can check what type of input fields you are using based on your validation.

27 Dec
1 month ago

Nakov left a reply on Validation If One Field Is Filled Then Others Are Required

@MUBEENALI - Sorry friend, the correct validation to be used is required_with instead of required_with_all

$validator = Validator::make($request->all(), [
        'holidays_title'   => 'array|min:1|required_with:opening_holidays_hours,closing_holidays_hours',
        'opening_holidays_hours' => 'required_with:holidays_title,closing_holidays_hours',
        'closing_holidays_hours' => 'required_with:holidays_title,opening_holidays_hours',
    ]);

Nakov left a reply on Question About Models?

And this series are helpful regarding your question:

https://laracasts.com/series/advanced-eloquent

26 Dec
1 month ago

Nakov left a reply on Validation If One Field Is Filled Then Others Are Required

@MUBEENALI - but are you printing out errors in your view? Do you get redirected back, or by you are not getting anything you mean the form submission passes and the resource is being saved?

Nakov left a reply on Validation If One Field Is Filled Then Others Are Required

You can easily do that applying the required_with_all validation to each of your fields, so:

$rules = . [
 'field1' => 'required_with_all:field1,field2,field3',
 'field2' => 'required_with_all:field1,field2,field3',
 'field3' => 'required_with_all:field1,field2,field3'
];
25 Dec
1 month ago

Nakov left a reply on I Can't Submit My Form

First the url helper function should be lowercased not Url And second, do you maybe forget to pass the csrf token?

You can do that by adding the field in one of this 3 ways:

  1. @csrf blade directive within your form tag in the view
  2. {{ csrf_field() }}
  3. `
22 Dec
2 months ago

Nakov left a reply on Use Curly Brackets Insite Double Curly Brackets In Laravel Template

And why do you want to access the property within a curly braces? Are you going to have multiple properties and you want to access them dynamically?

You can show it using plain php, so within your blade you can have

@php
echo $object->$property;
@endphp

If you know the property name, then declaring it as public in your class, you can access it without the $ like this:

class User {
    public $property = 'name';
}

and within your view

{{ $user->property; }}

Nakov left a reply on Accessing Values Inside The Model

You will have to return anything from the relationship method in order to work, so this logic does not belongs here I think.

A better approach would be to filter the results after you fetch them. So there are two options for that:

  1. Assuming that your field is null if the type is not equal to item, based on your check, you can do it like this:
$items = PurchasableItem::has('item_data')->get();

or

  1. Getting all the items with their relationship, and filter based on their type and the relationship containing template data.

$items = PurchasableItem::with('item_data')->get()->filter(function($item) {
      return $item->type === 'item' && $item->item_date !== null;
});

21 Dec
2 months ago

Nakov left a reply on Your Local Changes To The Following Files Would Be Overwritten By Merge

The problem is because you are compiling the assets on production server as well as on your local machine.

So when you develop you probably use npm run dev it creates both of those files on your local machine, so before pushing to production you should run npm run production locally and remove the npm run production from the deploy script so it won't do that twice hence no merge conflicts.

At the moment what you can do is git checkout public/css/app.css public/js/main.js on your server, compile the assets locally and deploy to production again, just before remove the npm run production from the deploy script so you don't experience the same conflict again.

01 Nov
3 months ago

Nakov left a reply on Custom Error Page (not Custom HTTP Error Page)

Which version of Laravel are you using? Because a default template in Laravel 5.7 looks like this:

@extends('errors::illustrated-layout')

@section('code', '500')
@section('title', __('Error'))

@section('image')
<div style="background-image: url('/svg/500.svg');" class="absolute pin bg-cover bg-no-repeat md:bg-left lg:bg-center">
</div>
@endsection

@section('message', __('Whoops, something went wrong on our servers.'))
23 Oct
3 months ago

Nakov left a reply on SQLSTATE[42S02]: Base Table Or View Not Found:1146 Table 'zerodocs_db.products,divison Etc

What do you mean by No database migration? Have you run the migrations? Do you have products table in your database? Because the error is pretty obvious?

When you say connection is okay, is it okay through a MySQL client or through your laravel application?