Nakov

Nakov

Member Since 3 Years Ago

Skopje

at SOLID Solutions

Experience Points 118,520
Experience Level 24

1,480 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 995
Lessons
Completed
Best Reply Awards 33
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.

24 Apr
21 hours ago

Nakov left a reply on Laravel Maintenance Mode Troubles

Can you please show the commands that you are trying to execute and what is the response on the command line?

Also check your log files (storage/logs) it might give you some insight on what is going on.

23 Apr
1 day ago

Nakov left a reply on Migrations: Adding Foreign_key When Table Is Yet To Be Created?

Why would you have each table referencing each other? If you really have a good use case on doing this then you should do it in a separate migration, at least for the one foreign key, but I think that a proper One to Many relationship in your case a Conversation can have many messages could be achieved just by having a conversation_id in your messages table. Then to get the last message from a conversation you can do it easily like this:

$conversation->messages->last()
22 Apr
2 days ago

Nakov left a reply on Handle Image Upload Laravel 5.8

@CALLUMCARLSTROM - Change hasfile to hasFile or just file to make sure that that condition passes, and try printing out in the block there to make sure you are reaching that point at all.

Nakov left a reply on Handle Image Upload Laravel 5.8

On your form element you are missing the enctype. So change it to this:

<form method="POST" action="{{ action('[email protected]') }}" id="submitRecipeForm" enctype="multipart/form-data">

Nakov left a reply on Array To String Conversion ???

Because you are trying to store it as an array instead of a JSON value:

So try this:

$author = Role::create([
            'name' => 'Admin',
            'slug' => 'admin',
            'permissions' => json_encode([ 'is-admin' => true])
        ]);
21 Apr
3 days ago

Nakov left a reply on How To Add A Foreign Key To A Table After Migration Done Laravel

What I do in this case is if the migration is not already pushed to a production site and it is only locally, you can:

  1. Edit your current migration and add the extra field with the foreign key constraint.
  2. Delete the product table from the database.
  3. Delete the row that contains the migration file name from the migrations table manually.
  4. Run php artisan migrate again.

If it is already used by other people in the team or on production, you can create a new migration adding the extra field.

19 Apr
5 days ago

Nakov left a reply on How To Join Table Using Eloquent?

@GALIH56 - Okay, please consider the answer that helped you as Best answer, it helps others to find solution for similar problem.

Nakov left a reply on How To Join Table Using Eloquent?

@GALIH56 - make sure that for the user that you are checking you have a role_id in the table. To me it seems like the id is missing. Either from the user table or a role with that id does not exists.

18 Apr
6 days ago

Nakov left a reply on How To Join Table Using Eloquent?

When you are doing

Auth::user()->role()

this returns the relation. So you should either call ->get() before you get the column, or just simply call it like this:

Auth::user()->role->nama

Nakov left a reply on Changing The GitHub Username?

No, that was it for me. I also use another server not through Forge for a production site, I changed to the new remote there, and it all worked well.

The warning on Github is more if you have open source projects and people depend on some of your repositories, but if you have control on most of them, you are fine. Even with the old username the repo will continue to work for a while, but it is good if you can change them asap.

Nakov left a reply on Changing The GitHub Username?

I've changed mine recently and I've been using Forge for 4 years now. No side effects, you just need to set the new remote URL to your repositories, following the docs here and for Forge you update it through the admin panel.

17 Apr
1 week ago

Nakov left a reply on How To Access DB As A Class Instance?

You can do it like this:

$db = DB::table('table');
if ($something) {
    $db->whereIn('field', ['a','b']);
}

// and get the result at the end 
$result = $db->get();

Nakov left a reply on Dateformat Showing Current Year

You can use Carbon for this:

Carbon\Carbon::createFromFormat('d F, Y', '16 July, 2014')->format('Ymd');

Nakov left a reply on Auth::user() Returns Null Value

@GALIH56 - It is an object, but it won't be null is what I was saying.

Nakov left a reply on Auth::user() Returns Null Value

In your HomeController constructor you can place what you have read on StackOverflow. So you first should register the middleware and then use a callback to get the user from the session, so your HomeController constructor should look like this:

public function __construct()
{
        $this->middleware('auth');

    $this->middleare(function($request,$next){
        $this->user=Auth::user(); // here the user should exist from the session
        return $next($request)
    });
}

Nakov left a reply on Array_merge(): Expected Parameter 2 To Be An Array, String Given

Your controller action is never used by the way, because when you define the route, you use a closure which renders the view. And maybe that's the error that you get there so change your route to this:

Route::get('temp', '[email protected]');
16 Apr
1 week ago

Nakov left a reply on How Can I Implement Laravel Email Verification In Other Models Beyond User Model

You can do it by following everything in the documentation here , so basically having email_verified_at column in your model, implement the MustVerifyEmail interface in your model and also making your own middleware to check to the other model if the email has been verified. For that you need to create your own version of the EnsureEmailIsVerified middleware and register it in the Kernel.php file.

Nakov left a reply on Extension For Php To Align The Controllers File In Laravel?

Here you go, good plugin for PHP formatting using PSR-2 standard.

Nakov left a reply on Extra Check After Login

Yes a middleware is a way to go with this, so the steps are you create the middleware with the artisan command:

php artisan make:middleware CheckLicense

You will put your logic within the handle method of the middleware:


public function handle($request, Closure $next)
{
    if( Auth::check() && ! $request->user()->hasLicense()) { // you should have a method like this for example
        return redirect()->route('license');
    }

    return $next($request);
}

You will register the middleware in the Kernel.php file, and use it on your routes.

15 Apr
1 week ago

Nakov left a reply on Laravel Sum

@MOUZAK - Try to change this:

$data['som']= salaries::selectRaw('(salairebase + sursalaire) as total') ->where('salaries.id', $request->id)->get();

with

$data['som']= salaries::selectRaw('(salairebase + sursalaire) as total') ->where('salaries.id', $request->id)->first()->total;

Just so you know, first can return null, in which case calling total will fail. so even better is to use this:

$data['som']= optional(salaries::selectRaw('(salairebase + sursalaire) as total') ->where('salaries.id', $request->id)->first())->total;

Nakov left a reply on Laravel Sum

@MOUZAK - If you are getting a total you can go with this approach:

$totalSalary = Salary::selectRaw('(sum(salairebase) + sum(sursalaire)) as total')->first();

return $totalSalary->total; // this returns only the value.
14 Apr
1 week ago

Nakov left a reply on SQLSTATE

@AISHAHYAACOB - Yes, so that's why I said that you should select my answer that helped you as a best answer, and not your own thanks note.

13 Apr
1 week ago

Nakov left a reply on SQLSTATE

@AISHAHYAACOB - You should mark my answer as the one that helped, not yours my friend ?

Nakov left a reply on SQLSTATE

You are trying to create a suggestion with an empty suggestion field. Your array is wrong, so either try this:

$suggestion = [
            'suggestion' =>  $request->input('suggestion'),
            'category' => $request->input('category')
];

Suggestion::create($suggestion); 

// or 
Suggestion::create($request->only('suggestion', 'category'));
12 Apr
1 week ago

Nakov left a reply on Laravel Sum

Guessing that you have Salary model you can do it with eloquent like this:

Salary::selectRaw('(salairebase + sursalaire) as total')->get(); // this return each row separately

Salary::selectRaw('(sum(salairebase) + sum(sursalaire)) as total')->get(); // one total result
11 Apr
1 week ago

Nakov left a reply on No 'Access-Control-Allow-Origin'

There is a good answer here for your question. Hope it helps.

10 Apr
2 weeks ago

Nakov left a reply on How To Make A Sub Query With Eloquent

I am not sure of an eloquent way, but the you can do it with the query builder like this:

DB::table('payments')
                ->select('customerNumber, checkNumber, amount))
                ->havingRaw('max(amount) > ?', [50])
                ->get();

Nakov left a reply on Undefined Property

Most probably because you use older version of Laravel, odd and even where added in Laravel 5.8.5. More on this here

09 Apr
2 weeks ago

Nakov left a reply on What Are The Different Between Laravel Shedule And Queues?

@RANGANA - Yes, Queue is used for sending email, as it is a time consuming task, so the queue worker can pick it up and send it in the first available slot.

Nakov left a reply on What Are The Different Between Laravel Shedule And Queues?

And why not going in the wonderful docs that Taylor puts out?

Queues and [Scheduling tasks] (https://laravel.com/docs/master/scheduling#introduction)

In summary queue is same as in the hospital, before you enter into the doctor's office you are waiting in a queue, so it is for time consuming tasks to be performed one at a time. And the scheduler is more used if you want a specific task to be performed at a specific time, if you have a tasks that should be performed at a certain schedule as well.

Nakov left a reply on Pass Multiple Arguments To A Policy Method That Don't Require Models

@JULIEN44 - You will need to pass them as array, for example:

        return $this->user()->can('create',  [Signalement::class, Request::get('place_id')]);

Then the parameters of the function in your policy will be mapped to the correct values.

Nakov left a reply on Best Way To Count Page Views?

I think that Redis is the best option for this problem, but I am not sure why you would need a cron job to update the page_views column. I think that this video by Jeffrey can help you. Here he shows the trending videos, but you can use the same approach for page views. He also gives a tip on what to do when the same user is refreshing the page.

07 Apr
2 weeks ago

Nakov left a reply on Markdown Mail: Bold Text Inside Markdown Table

is used for header, not for making the text bold, you need two stars from each side of the text in order to make it bold. Ex: TEXT

06 Apr
2 weeks ago

Nakov left a reply on Profile Setting Page

As I noticed in your view, you have multiple @csrf fields, you need only one within the form.

The error that you get is because your route is defined with PATCH method, but you are not using the correct one. Your form is correct you should be using POST but you need to add @method('PATCH') within your form.

05 Apr
2 weeks ago

Nakov left a reply on Check Input First

@MADA72 - So you should consider accepting my answer as the one that helped you ;)

Nakov left a reply on Check Input First

You can take advantage of the helper methods that Laravel eloquent has, this for example.

So in your store method you can do:

$city = City::firstOrCreate(['name' => request('city_name')]);

// and use the $city->id or whatever you need here.
04 Apr
2 weeks ago

Nakov left a reply on Check If User Is Owner Of Child

You get the error because you are checking against a variable that has never be defined. So try changing this :

if (Auth::user()->id == $user_id){ with this if (Auth::user()->id == $id){.

Nakov left a reply on Policy Method Not Working As Expected

The problem is that you don't tell Laravel what you are trying to authorize, so you never get into the method of authorization. Try this in your controller:

$this->authorize('create', Post::class);

Nakov left a reply on Defining Correct Routes In Web.php If Controller And Views Are In Admin Folder

First make sure that when you moved the controller to a subfolder you changed it's namespace to the correct path, for example the default namespace is App\Http\Controllers now it should be App\Http\Controllers\Admin.

Second: You can add a namespace to your route group, instead of using it in each route separately, so to add it change your route group to this:

Route::group(['middleware' => ['admin'], 'prefix' => 'admin', 'as' => 'admin.', 'namespace' => 'Admin'], function () {

Third: You need a named route in order to use it as you do, that's why you get the error, so try this:

    Route::delete('delete-event/{id}','Admin\[email protected]_event')->name('delete-event');

And use it like this:

{{ route('admin.delete-event', ['id' => $id]) }}
01 Apr
3 weeks ago

Nakov left a reply on Laravel Validation

You should try 'stylesheet' => 'nullable|mimes:css'

Nakov left a reply on Issue With Summernote

In your blade you need to escape the HTML syntax like this:

<div id = "{{ $lesson->id }}_description" class="hide-this">{!! $lesson->description !!}</div>

Notice instead of {{ }} I use {!! !!}}

Nakov left a reply on Issue With Summernote

I believe this is what you are looking for, nice answer here.

29 Mar
3 weeks ago

Nakov left a reply on How To Get The PDOStatement Object From The Query Builder?

@ZSOLTGYURE - Can you share a code that you are trying to use so I can try to help better. If you open the Connection class, you can see this code:

/**
     * Configure the PDO prepared statement.
     *
     * @param  \PDOStatement  $statement
     * @return \PDOStatement
     */
    protected function prepared(PDOStatement $statement)
    {
        $statement->setFetchMode($this->fetchMode);

        $this->event(new Events\StatementPrepared(
            $this, $statement
        ));

        return $statement;
    }

Which you cannot access directly but you can set a listener for the Events\StatementPrepared event, and the PDOStatement will be given to you on which you can then use closeCursor().

Nakov left a reply on How To Get The PDOStatement Object From The Query Builder?

I don't think that there is such a thing as a PDOStatement. PDO is more like data access layer and it stands for PHP Data objects. So you can get a reference to the PDO through the connection:

DB::connection()->getPdo();

or if you want to write a statement you can use:

DB::connection()->statement()

here is the definition of the statement function:

/**
* Execute an SQL statement and return the boolean result.
*
* @param  string  $query
* @param  array   $bindings
* @return bool
*/
public function statement($query, $bindings = []);

Nakov left a reply on What Does A Successful Delete Query Via Query Builder Return?

You can always surround your query call with a try and catch.

try { 
  $result = DB::table('table_name')->where('GENDER', '=', $data['GENDER'])->delete();
} catch(\Illuminate\Database\QueryException $exception){ 
   // $exception->getMessage() - will give you the error if any.
  // Note any method of class PDOException can be called on $exception.
}
27 Mar
4 weeks ago

Nakov left a reply on How To Get Array Value Of Text Box In Javascript Alert

You can pass the reference to the element as a function argument. So each field can have:

// notice the `this` as an argument to the function.
 <input type="text" class="rate_per_kg" name="total_qty[]" onkeyup="calculation(this)"  />

and then the function is:

function calculation(el) {
    // el is the element that you are currently typing in.
    console.log(el.value); // this will print it to the console instead of an alert.
}

Nakov left a reply on Changing Auth Table

@BEHNAMPMDG3 - No, that's just a key, it should not have any effect, as the other parts use it. As you can see couple 'provider' => 'users' that means that it uses the providers->users key. But just changing the model to use the Member class instead of the default User what errors do you get?

26 Mar
4 weeks ago

Nakov left a reply on Changing Auth Table

@BEHNAMPMDG3 - if your table is called members, then I believe that your providers should be called respectively instead of users. But you should try, and if you have any errors, than share the error so we can help.

17 Mar
1 month ago

Nakov left a reply on Changing Auth Table

That should be it, but it sounds misleading having a User model which is a member. So you should better change the model itself to be Member, and then don't forget to apply the changes in your config/auth.php file.

Do you experience any errors using this approach btw?

16 Mar
1 month ago

Nakov left a reply on Laravel Error Logging

Laravel uses a config file called logging, which then uses LOG_CHANNEL which by default in newer versions is set to stack. So check what value do you use as a LOG_CHANNEL make sure it is not empty in your .env.