nikos

nikos

Member Since 9 Months Ago

Nis

Php developer at Ingsoftware

Experience Points 14,680
Experience Level 3

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 86
Lessons
Completed
Best Reply Awards 9
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.

17 Apr
2 months ago

nikos left a reply on Hiding Duplicate Foreign Keys When Doing A Left Join

@markzimmer If I get it right you have one moderator per category, right? Why would you need a reference to moderator table in questions then? And also you should try to follow laravel naming conventions. Something like this: categories id|moderator_id|name moderators id|name questions id|category_id|question

16 Apr
2 months ago

nikos left a reply on Hiding Duplicate Foreign Keys When Doing A Left Join

Your db is set up wrong. Better way would be to have reference to moderator in category table. Then you could do something like this in the view:

@foreach ($categories as $category)
    {{ $category->name  . '  ' . $category->moderator->name }}
    @foreach ($category->questions as $question)
        {{ $question->text }}
    @endforeach
@endforeach
25 Mar
2 months ago

nikos left a reply on Passing Variables From Controller To A View

@sushant97 I'm not sure what's the problem. Anyway you can try flash the messages through sessions for redirects as described in the docs https://laravel.com/docs/5.8/redirects#redirecting-with-flashed-session-data

nikos left a reply on Passing Variables From Controller To A View

In your controller instead of redirect() use just return view('adminhome')->with('message', $msg);

21 Mar
3 months ago

nikos left a reply on How To Config Daily Log File Sperate By Level ?

You're defining a separate channel for each level, and pointing them to the same file, why would you do that?

you can define just a single channel something like chlog for example.

    'chinfo' => [
            'driver' => 'daily',
            'path' => storage_path('info/ch.log'),
            'level' => 'info',
        ],

Note that driver is daily, hence you want daily logs, and storage path is not laravel.log, hence that is default log file. And now in the trait, you could do this:

 Log::channel('chinfo')->info(....);
 Log::channel('chinfo')->error(....);
.
.
.

nikos left a reply on Count In Join Not Working Properly

@eusapxai if you want, take a look at Eloquent relationships, they can be quite useful :) https://laravel.com/docs/5.8/eloquent-relationships

nikos left a reply on Count In Join Not Working Properly

The problem is that you get the separate row for each image. Try adding count(DISTINCT rating.rating_id). Maybe it would help.

But is there any particular reason why are you doing this with query builder and not with Eloquent relations?

19 Mar
3 months ago

nikos left a reply on Eloquent Go Through HasMany And BelongsToMany

@trazsam my bad, my previous response couldn't help you. I googled a bit and it seems that joining tables would be the best solution. You can look at this stackoverflow link

nikos left a reply on Eloquent Go Through HasMany And BelongsToMany

@trazsam did you set relation between Type and Category, and between Category and * Formation* ?

If you did you can do it easily

$type->category->formations
18 Mar
3 months ago

nikos left a reply on Should I Define Mysql Relations When Using Alequent

@SCREENBEETLE - @screenbeetle isn't that adding foreign keys to SQL actually, just via migrations? @Of course, you should use migrations, for creating your database.

nikos left a reply on Should I Define Mysql Relations When Using Alequent

Relations in SQL and relations in Eloquent are different things. Mysql foreign keys are used for indexing, and they're making your queries more performant. Eloquent relations are part of ORM itself and are defining relations between objects. Anyway, you should define both, SQL because of the performance, and Eloquent so that you can it correctly.

17 Mar
3 months ago

nikos left a reply on Blade - Map Database Values And Show In View

@oliverbusk, of course, they should. For cases like that, the best thing would be not to have so-called magical strings in your code, but to define possible values for columns either in some constants or if you ask me even better in enums. Now, PHP does not support enums but there is a pretty cool package called Laravel Enum. That way you could keep everything clean, and if you need to change it anytime, you could do it in one place.

And one more plus to this approach is if you need to translate DB values to multiple languages, you'll do it quite easy like this.

16 Mar
3 months ago

nikos left a reply on How To Manage Multiple 3rd Party API's Using Service Providers

I think that would be a good idea hence you won't need to change your business logic if you want to add some third API integration. As for listener or subscriber, the answer is as usual - it depends :) Listener can only listen to a single event, but if you want to listen for multiple events in one class then use subscriber. Hope that this helped you a bit :)

14 Mar
3 months ago

nikos left a reply on How To Manage Multiple 3rd Party API's Using Service Providers

@pankajjha_145 did you think about event/listeners approach?

https://laravel.com/docs/5.7/events#registering-events-and-listeners

That way you could just add a listener for each 3rd API integration, and make mall listeners listen for the single event.

22 Feb
4 months ago

nikos left a reply on Number Of Foreign Key Occurrences In Faker Seeder

Hi @jjmontalban ,

There are two ways, both well described in this article

28 Jan
4 months ago

nikos left a reply on Laravel Query

I guess you could add order by users_membership.endad_at desc, but the Laravel way to do it would be to do it with relations.

24 Jan
5 months ago

nikos left a reply on Query Problem -> Wrong Data

Then just add meetings.users

$seminars = Seminar::whereHas('users',function ($query) use ($user) {
                $query->where('id', $user->id);
})
->with(['users' => function ($query) use ($user) {
                $query->where('id', $user->id);
}, 'meetings.users']);

nikos left a reply on Query Problem -> Wrong Data

I'm sorry think that you'll need to do it with ->whereHasToo() hence they're separate queries. So in the end i would try something like this

$seminars = Seminar::whereHas('users',function ($query) use ($user) {
                $query->where('id', $user->id);
})
->with(['users' => function ($query) use ($user) {
                $query->where('id', $user->id);
});

nikos left a reply on Query Problem -> Wrong Data

So meetings table is pivot table between users and seminars. If so

$seminars = Seminar::with(['users' => function ($query) use ($user) {
                $query->where('id', $user->id);
            }])->get();

nikos left a reply on Pivot Data On Query

The relationship name should be companies hence your user has multiple companies, not one. So you will have o specify the id of the company you're trying to get users from.

nikos left a reply on Pivot Data On Query

You didn't specify which users do you want. The correct way would be to set the appropriate relations, and then if you want company users, do something like this: $company->users and you'll get the users you need.

23 Jan
5 months ago

nikos left a reply on Laravel - Changing Object's Field Value That Is Inside Of The #appends Array

@leff7 Did you try to add accessor method for that field, like mutator.

class Item extends Model
{
    /**
     * Set the item's slug.
     *
     * @param  string  $value
     * @return void
     */
    public function setSlugAttribute($value)
    {
        $this->attributes['first_name'] = strtolower($value);
    }
}
10 Jan
5 months ago

nikos left a reply on Get Files In Base64 Code

@MECJOS - What do you get when you print $cadFiles? try it with dd($cadfiles);

nikos left a reply on Get Files In Base64 Code

Or hence its base64, you could try $request->input('cadNames'). One of those must work

nikos left a reply on Get Files In Base64 Code

@MECJOS - You shouldn't use $request->get('cadNames') but $request->file('cadNames'). Take a look at laravel docs

nikos left a reply on Get Files In Base64 Code

Maybe this link on stackoverflow will help?

09 Jan
5 months ago

nikos left a reply on Best Data Type Is For Storing Money Values

I stored it as an integer, and multiplied by currencies lowest unit (cents for dollars) but had a problem when storing cryptocurrencies, for example, ethereum smallest unit is wei, and 1 eth = 10^18 wei. So even if you're using big unsigned integer you're gonna have a problem.

06 Nov
7 months ago

nikos left a reply on Validate To Input With Same Name That Belongs To Two Table

in your case I'd call the, user and match. Laravel does that by default for resource url parameter names. But it's definitely up to you how will you name them.

15 Oct
8 months ago

nikos left a reply on View Primary Key In Blade.php

In your current query you are selecting multiple id columns, so the last one selected overwrites others.

Adding ->select('column_1', 'column_2') or ->selectRaw('table_1.*, table_2.column', ....) in the end of the query would solve your problem. That way you could specify which id column you want to select.

But are you sure that you need joins at all? Maybe take a look a eloquent relations. This would be more 'laravel' apporach https://laravel.com/docs/5.7/eloquent-relationships

12 Oct
8 months ago

nikos left a reply on How To Get Friends Message

So you're trying to get all messages that current user sent to himself...?

nikos left a reply on How To Get Friends Message

What do user_id and receiver_id columns mean? If user_id is actually id of person who sent the message, this way you're trying to query all messages that the current user sent himself.

05 Oct
8 months ago

nikos left a reply on Since Our Laravel Project Uses Repository, Where Is The Best Place To Do Validation?

I'm doing it in request. The only thing that you should be aware of is when calling your repositories from some other places then controllers. Like importing some stuff etc...

nikos left a reply on How To Use Pre-defined Destroy Method

Route Model Binding is just one way you can get your stuff done. In my opinion doing database logic in controller is not a good thing, this way you're making controller depended on Model. You should extract that to repository level.

nikos left a reply on How To Use Pre-defined Destroy Method

in html you need a form hence delete method is http request type DELETE. So something like this

<form method='POST' action="{{ route('posts.delete', ['post' => $post->id]) }}">
    @csrf
    @method('DELETE')
    <input type="submit" value="Delete Post" />
</form>

⋅⋅*??*`@ directive inserts csrf field (if you want to read more about it here is a link) ⋅⋅* Note that method is POST, and then there is @method('DELETE') hende html forms do not support any other type then POST/GET. You can read about it here

In routes you can either make one route for delete or hence you've already made resource controller you can make resource routes too. Something like this

Route::resource('posts', 'PostController');

just watch out for namespaces of controller.

and now about the controller, if you like it more, you can change destroy() function parameter to $postId (I like it that way hence I'm not doing any stuff with models in controllers), but if you're developing something simple laravel lets you bind a model to your routes, you can check that here But still I'd do something like this (If you do the db/model logic in controllers)

* Remove the specified resource from storage.
     *
     * @param  int  $postId
     * @return \Illuminate\Http\Response
     */
    public function destroy($postId)
    {
        $post = Post::find($postId);

    if (empty($post)) {
        abort(404);
    }
    
    $post->delete();
    
    return redirect()->route('posts.index');
    }

Basically, I just tried to find post with given id, if not threw 404, and if I did I deleted it and redirected to index page.

02 Oct
8 months ago
25 Sep
8 months ago

nikos left a reply on Update Json Column On Pivot Table

I think that you can't update only one json attribute, because you're updating column, regardless of its type. So I think that if you're using json, and want to edit only a part of it, you must first read it, edit it the way you want, and save it.

24 Sep
9 months ago

nikos left a reply on Get User Name From The Id From Other Table In Controller

Okay lets start from beginning. You have User and Log model, right? In User model put this function

public function logs()
    {
        return $this->hasMany('App\Log'); // assuming this is the path for Log model
    }

Then in your Log model

public function user()
    {
        return $this->belongsTo('App\User'); // assuming this is the path for User model
    }

Then in your controller

// Find log
$log = Log::where('id', 1)->first(); // or whatever, just get one log
$username = $log->user->name;

nikos left a reply on Get User Name From The Id From Other Table In Controller

The Log model should have user relation and then you can do

$log = Log::first();
$user = $log->user;

You can check that in docs https://laravel.com/docs/5.7/eloquent-relationships Note: this woul be on-to-many relation

nikos left a reply on Bugs On Has()

So you wanted to restrict users only to the courses he has access to. The 'Laravel' way of doing this is with Policies https://laravel.com/docs/5.6/authorization#creating-policies But also you can do that in your controller/repository, just by generating the right query

nikos left a reply on Bugs On Has()

Take a look at querying relationship existence at docs https://laravel.com/docs/5.7/eloquent-relationships#querying-relations And I'm not quite sure what are you up to? Do you want to get all the lessons from one courseor a collection of courses with its lessions ?

23 Sep
9 months ago

nikos left a reply on Constants In Repository Pattern

Thanks both, for my case @wilk_randall approach will do great, but enum approach is definitely interesting, especially because of the table and column names. I'll definitely think about it

nikos started a new conversation Constants In Repository Pattern

When using repository pattern, should I put constants in Models or maybe in Repositories, hence I could need them in controllers... and I'm thinking if I put them in the Models, controllers are going to again depend on models, which is kinda what shouldn't be the case when using repository pattern...

21 Sep
9 months ago

nikos left a reply on Checking Object Value

for the empty data model this is how would it work in create function:

$data = new ModelName();

And how does it work on one and not on the other machine, I'm not sure

nikos left a reply on Checking Object Value

Take a look at the docs I sent. I says The callback should return an associative array containing a single key / value pair:. It returns an array, so you can't access it as a object. What is an error if you use second approach I suggested?

nikos left a reply on Join Table Using Eloquent

Try this

$promo = PromoDetailModel::join('tb_m_biller_solusi', function($join){
$join->on('tb_m_promo_detail.product_id', '=', 'tb_m_biller_solusi.Productid');
$join->on('tb_m_promo_detail.biller_id', '=', 'tb_m_biller_solusi.Billerid');
})
->where('promo_code', $promo_code)
->get();

nikos left a reply on Checking Object Value

Check the docs: https://laravel.com/docs/5.6/collections#method-mapwithkeys

So it looks that if you want to use mapWithKeys() you should apply all(), and then access it as a row not an object. Like this:

// Controller
$billers = collect($billers)->mapWithKeys(function($data) {
            return [$data->biller_id => $data->biller_name];
        })->all();

// Then in view
 @foreach($billers as $key => $row)
        <option value="{{$key}}">{{$row}}</option>
@endforeach 

// Same for products

But if you only need it for this why don't just take two columns that you need and still access it as object? Something like this

/// Controller
$billers = BillerModel::select('biller_id', 'biller_name')->get();

Then you should be able to access it in view like you tried to.

20 Sep
9 months ago