Nakov

Nakov

Member Since 3 Years Ago

Skopje

at SOLID Solutions

Experience Points 139,320
Experience Level 28

680 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 1074
Lessons
Completed
Best Reply Awards 55
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.

22 May
2 days ago

Nakov left a reply on Authorise In Controller, FormRequest

@rffred, Yes @willjohnathan is right, this becomes an endless loop hence the 500. So based on the documentation you can peform the authorization methods on the user itself.

So in your case you are not validating against a logged in user but to the admin model which will always return false unless your default value from the hasPermissionTo method returns true.

What you need instead is to modify your policy method to this:

public function create(User $user, Admin $admin)
{
    return $user->hasPermissionTo('create-admin');
}

Then you do the check in your custom form request if the currently authenticated user is authorized to create an admin:

public function authorize()
{
    return $this->user()->can('create', Admin::class); // import the Admin class on top.
}

Nakov left a reply on Find($id) Instead Of Find(1,3,4....)

@EMFINANGA - Okay, so this means that the select option with a name of clientName contains the id of the client.. so use this line instead:

$clientName=Customeraddress::find($request->clientName);

you can maybe change the clientName to clientId but change the name attribute on the select element to match that as well.

Nakov left a reply on Find($id) Instead Of Find(1,3,4....)

@EMFINANGA - So this is the line that throws the exception:

$clientName=Customeraddress::find($id);

That's because the $id does not exist by this point and you are trying to use it. Do you pass the id in the request? If you do then you should be using this:

$clientName=Customeraddress::find($request->id);

Nakov left a reply on Find($id) Instead Of Find(1,3,4....)

You are not sharing the whole function, do you have $id variable initialized above this line:

$clientName=Customeraddress::find($id);

Nakov left a reply on Authorise In Controller, FormRequest

If you have Custom Form request than the policy code should be performed there so it will look like this:

class AdminStoreRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return $this->authorize('create', Admin::class);
    }

and you can remove the check from the controller. If you don't have a custom form request class then it is okay for that line to be in the controller. So that's the point of the method there, it is not just to return plain true or false.

Nakov left a reply on Local Scopes - Explanation Needed

@DJOLEFJC - if $naziv is null then using ->where('Naziv', 'like' , '%%'); it will look for any value but not null. So if you need the null values as well, then might be better to just to this:

public function scopeOfNaziv($query, $naziv)
{

        if($naziv)
        {
            return $query->where('Naziv','LIKE',  "%$naziv%");
        }

        return $query;
}

Nakov left a reply on Local Scopes - Explanation Needed

Session has a use if you need the value in a request later on, but in this case doesn't make sense at all as it is getting removed just before the return statement. So in this case the code can be written like this:

public function scopeOfNaziv($query, $naziv)
{

        if($naziv)
        {
            $naziv = '%'.$naziv.'%';
        }
        else
        {
            $naziv = '%%';
        }


        return $query->where('Naziv','LIKE',  $naziv);
}

In any case the scope is used in order to perform an action on the query builder. Such as this:

Model::ofNaziv('naziv here');

Nakov left a reply on Group By And Count On Pivot Table.

When you use the Query Builder you should tell from which table you are trying to query the results because from your query the table is unknown even though you use it in your select. So try this instead:

$appearances = DB::table('match_player')
                   ->select('player_id', DB::raw('count(match_id) match_id'))
                   ->groupBy('player_id')->get();
16 May
1 week ago

Nakov left a reply on Helper Not Accessible

You can autoload the helper file using composer so you won't need the Service provider for this, because your helper file contains only functions and not a class that can be instantiated. So in your composer.json add this:

"autoload": {
        ...
        "files": [
          "app/Helpers/Helper.php"
        ],
        ...
    },

Once you have this run composer dump-autoload and you should be good to go.

Nakov left a reply on Error On Migration

I cannot see anything wrong with this. I would debug this by commenting out the foreign key on the tag_id and make sure that the videofile_id foreign key works. If it does compare what you do in one place and you are missing on the other.

Nakov left a reply on Error On Migration

@TASTEMEDIA - That seems good. Another thing I can think of is the order of table being created. Does your tags migration runs before this one?

Nakov left a reply on Error On Migration

This can be because of a different types of the columns. For tag_id you are using big integer, so is your id on the tags table a big integer as well?

Do you have $table->bigIncrements('id'); in your tags migration?

15 May
1 week ago

Nakov left a reply on No Message Error

You are trying to post to the index method of your controller which does nothing with your data, but it returns the same view. Maybe change the route to this:

Route::post('/adaugajob', 'Auth\[email protected]')->name('adaugajob');

Nakov left a reply on Date Format In Laravel Controller

@CORCRONJE - Or adding date_of_birth in the $dates array of the model will return back a Carbon instance.

So presumably your model is called StudentData

You can add this in the model:

protected $dates = ['date_of_birth'];

Then you can do:

StudentData::findOrFail(1)->date_of_birth->format('d/m/Y');
14 May
1 week ago

Nakov left a reply on Keep Formatted Text In Database And Display It Correctly

You should prevent the user from storing unescaped HTML data. PHP code can be stored without any problem as the PHP code gets rendered on the server side, what you should worry about is a JavaScript code as that's a client code that can mess up with your application.

Anyway to escape html special characters you can use {{ $thread->body }} blade syntax instead of what you use now. Or if there is HTML code in the body you can unescape it using {!! $thread->body !!}. The latter approach does not prevent XSS attacks. More on this in the docs.

Nakov left a reply on Laravel Distinct Query

@PORDONEZ - Happy that it worked. Please accept the answer :)

Nakov left a reply on Laravel Distinct Query

So you've tried this:

YOUR_MODEL_NAME_HERE::select('name', \DB::raw('max(final_price)'))->groupBy('name')->get();

Nakov left a reply on Laravel Distinct Query

Not knowing your column names nor the model, so give this a try and let me know:

Model::select('name', \DB::raw('max(count)'))->groupBy('name')->get();

Nakov left a reply on Keep Formatted Text In Database And Display It Correctly

Can you please give example text and how do you display it in the view?

Nakov left a reply on How To Get The User Name By Not Primary Key Field In Laravel

In the Task model you can add a method like this:

public function assignee()
{
    return $this->belongsTo(User::class, 'assigned_to');
}

Then to use it you do:

$task->assignee->name

Also I would eager load the user and assignee in order to avoid n+1 queries.

So in your controller you can add this:

// I am assuming that you have user method in the Task model, the same as the assignee that I gave you above.

$tasks = Task::with('user', 'assignee')->get();
13 May
1 week ago

Nakov left a reply on 'Method Does Not Exist' When Using WhereMonth()

The error says it all, you are trying to use the method on the collection which it does not exist. You should use it on the Query Builder, so for example the first part of your code should be this:

$files = $campaign->files()->orderByDesc('created_at');

if ($month = request('month')) {
    $files->whereMonth('created_at', Carbon::parse($month)->month);
}

if ($year = request('year')) {
    $files->whereYear('created_at', $year);
}

Then to turn it to a collection you use:

$files = $files->get();

Nakov left a reply on After Upgrading To 5.8, € Is Printed Litterally

I don't know how it worked before, but you should escape the HTML using {!! !!} blade syntax, so try this:

{!! currency($record->purchase_list_price) !!}
12 May
1 week ago

Nakov left a reply on What Folders That We Shouldn't Be Modifying?

The vendor folder contains all the packages and the framework classes, so everything installed using `composer.

node_modules contains everything installed using npm.

Those should not be manually edited. Everything else you should follow upgrade guides whenever you need to upgrade in case something is different there, or the framework expects it one way or the other.

Nakov left a reply on Create Custom Validator

In the AppServiceProvider you have this import use App\Rules\Spamfree; Try it with camel-case as your class is, this one use App\Rules\SpamFree;

10 May
2 weeks ago

Nakov left a reply on FormRequest $validator->after() Times Out

Based on the documentation, the after hook is to add something to the Validator allowing you to call any of its methods before the validation rules are actually evaluated. Which means you cannot call passes nor fails within the hook. You can call a custom method and append error message in case the method fails.

So:

$validator->after(function ($validator) {
      Log::info($validator->passes()); // this fails
});

$validator->passes(); // after the after hook it does work.

Nakov left a reply on Dropdown Using Ajax Data Fetch

You cannot use a php foreach loop within a JavaScript. What you can do is add a data attribute to each option in your blade containing the job id, and then when you change the city, it will take the selected job title id and use that one for the request.

I see you use the title for the selected option, you should be using the id there, but any case, if your use case is different here is another approach.

<select class="form-control m-input" id="jobtitle" name="jobtitle" >
    @foreach($jobtitle as $job)
        <option data-id="{{ $job->id }}" value="{{$job->jobtitle}}"> {{$job->jobtitle}} </option>
    @endforeach
</select>

Then your script can be this:

<script>
    // you use POST request below, so if you don't have this code in your main JS file, you can add it here, otherwise delete it
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    function getCity(val) {
        let jobID = $('select[name=jobtitle] :selected').data('id');
        // if you decide to set the id as the value of the option then you use this:
        // let jobID = $('select[name=jobtitle] :selected').val();

        $.ajax({
            type: "POST",
            url: "{{route('job.store', [ 'id' => jobID] ) }}",
            data:{ 'jobtitle_id': val },  
            success: function(data){
                $.("#city").html(data);
            }
    });
}
</script>
09 May
2 weeks ago

Nakov left a reply on Laravel Telescope In Production Affects Performance?

Telescope provides list of watchers that you can enable or disable based on the environment. You can look at all here.

But also there is a nice play/pause button on telescope which you can use whenever you want to debug something that happened on the production server for example. The only modification that I do is I allow the telescope dashboard only for my personal email address, so that only I have access to it, but I still use it on production, it is a really nice tool.

Nakov left a reply on Need Help With An Axios Problem

  • Were the logs added at the same time when you wrote the axios call? If not make sure that you re-compile the scripts using npm run dev or npm run watch which will compile anytime there is a change in a script.

  • There is a log level in the Chrome inspect tool, so check if the info level is for some reason unchecked?

08 May
2 weeks ago

Nakov left a reply on Manually Add Value To Request

@OZIEL - Or you can try to use:

$request->merge(['user_id' => $user_id ]);

Nakov left a reply on Manually Add Value To Request

I don't understand. I don't see any validation done here. You can try to debug it using dd($input); and make sure that the $input array contains the user_id.

Nakov left a reply on Manually Add Value To Request

You can do this easier I think with union array like this:

$input = $request->all() + ['user_id' => $user_id ];

Nakov left a reply on Question On Boot() Method In Event Service Provider

There are already great videos explaining this process in details here on Laracasts, so please take a look at Service Container and Service providers.

It will become much clearer to you, and explaining them visually is much better then in a written form.

07 May
2 weeks ago

Nakov started a new conversation Clicking On Profile Image Leads To 404

@JeffreyWay Clicking on my profile picture to visit my profile page adds quotes to the URL which leads to a 404 page.

Nakov left a reply on Email Verification

The verify=true option just registers few routes. You can also register them using:

Route::emailVerification();

Make sure that you use the verified middleware to protect your other routes from unverified access.

Nakov left a reply on Looking For Wrong Table Column

@OZIEL - Great, please mark the answer as a solution to your question. Happy coding :)

Nakov left a reply on Looking For Wrong Table Column

I believe the issue is in the model state function:

public function state()
{
    // first is the foreign key, and second is the owner key on the state table, which you changed from id to state_id
    return $this->belongsTo('App\Models\State', 'state_id', 'state_id');
}

Nakov left a reply on Modifying Input Type On Chrome Inspect

So do you want to prevent the user from hacking himself? :D He cannot see while you are typing on your computer unless you let him to sit on your desk and open the console and edit the field.

A lot of programs even online web apps provide an extra eye to the password field, just so that the user can see a plain version of the text in case a mistake on the password entering was made.

06 May
2 weeks ago

Nakov left a reply on Issue In Date Sorting Of Yajra Datatable

The problem here is sorting using a string value instead of a timestamp. So you are sorting given your formatted date.

If you are not using ajax in order to render your datatable, then you can use the data-sort or data-order attributes on the cell containing your date to let the library know which value to use for sorting, and you should give the timestamp of the date.

As I can see you are using ajax, so in that case your date column should return the timestamp like this:

...
->editColumn('created_at', function($data_rem) {
            return $data_rem->created_at->timestamp; // I guess the created_at is a Carbon instance
        })

Then in your JavaScript, I override the rowCallback function on the DataTable and I format the date there:

rowCallback: function (row, data, index) {
    let dateCell = data.created_at;

    if (dateCell !== undefined && dateCell > 0) {
        let date = moment.unix(dateCell).format('d F Y'); // I am not sure that the format is the same using moment js. Or you can use your format here
        $('td:eq(3)', row).html(date); // 3 here is equal to the cell in which the date should be placed in the table.
    }
}

Hope this helps.

Nakov left a reply on Store() Method For Polymorphic One To Many Relationship

@PMUSA - That's not a polymorphic relationship what he has there. So just saying, you might be looking at the wrong place. The blog post that I have shared uses your exact scenario.

Nakov left a reply on Limit() Method Is Not Working Properly

Here is a way you can work around this issue.

Nakov left a reply on Store() Method For Polymorphic One To Many Relationship

Just so happens that there is a blog post for your exact scenario. And I would go with separate controllers instead of 1 to handle them all. As you said PostCommentsController is a good name for it, or VideoCommentsController even with a single store method.

05 May
2 weeks ago

Nakov left a reply on Eloquent Get 2 Columns As [column1Value => Column2Value]

@ANDREWK - You can mark it as solved.

Nakov left a reply on Eloquent Get 2 Columns As [column1Value => Column2Value]

What about :

DocCategory::all()->pluck('name', 'hash')->toArray();

Nakov left a reply on Laravel File View Response - Download Prompted With File Name As Last Part Of Route

I have tried this now:

public function viewFile(Request $req)
{
    header('Content-Disposition: filename="imageToDownload.jpg"');
    return response()->file(Storage::disk('files')->url(urldecode($req->rel_path)));
}

And it seems to work fine. Make sure that you use the correct name instead of the example one above.

Nakov left a reply on How To Select Multiple Dropdown Option?

Here a good example of multiple select of dropdown element.

Nakov left a reply on Cannot Add Foreign Key Constraint

I guess you are trying to add a foreign key to a user in the posts table, so your migration should look like this:

Schema::create('posts', function ( Blueprint $table ) {
      ...
      $table->unsignedInteger('user_id');
      $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
    });

Nakov left a reply on Call To A Member Function Store() On Null

Can you post the full form?

Are you maybe missing the enctype="multipart/form-data" attribute on your form?

Nakov left a reply on How Can I Rename Column In Database? Can I Do That Manually?

You get nothing to migrate because the migration has already been run. The proper way is to create another migration and then use:

$table->renameColumn('amount', 'count');

But if the migration has been used only locally, then you can remove the row from the migrations table and run your migration again, then it will take effect.

Nakov left a reply on Taskscheduler 'No Scheduled Commands Are Ready To Run.'

@MOHAMMADABUSALEH - The path to the projects in your examples above are different. Are you using the correct path?

On the first one you use /home/me/Sites/booking.dits and on the second /home/me/Sites/testsite.

Also just as a check in your Kernel add the full path to the command, for example:

protected $commands = [
        'App\Console\Commands\IntegrityCheck'
];

Nakov left a reply on Taskscheduler 'No Scheduled Commands Are Ready To Run.'

@MOHAMMADABUSALEH - I don't understand the last part on your comment "I have to setup the cronjobs manually instead of using Laravel Task Scheduler". You should have them both, as your code above seems fine to me. The only other thing I can think of is checking on your command line if the crontab is running, so for example, check if crontab -l lists your command, and also to check if the cron daemon is running using ps -ef | grep crond