Punksolid

Punksolid

Member Since 2 Years Ago

Culiacán, México

Experience Points
78,510
Total
Experience

1,490 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
632
Lessons
Completed
Best Reply Awards
23
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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 16
78,510 XP
Nov
15
3 days ago
Activity icon

Replied to Returning From A Class In Chain Of Responsibility?

Maybe you could add some kind of Bag object and append each return but I don't think that would be very clear.

Nov
11
1 week ago
Activity icon

Replied to Pivot Table With 3 Forein Key Related To 1 Table

Hi @untymage in your usage example whats a $collabe it is suppose to be an artist?

collabArtist is like a band?

Why do you use join and select in the relationship?

Do you want to know the colleagues of an artist?

Oct
30
2 weeks ago
Activity icon

Replied to Laravel Notifications Or Custom One?

do you need to handle/attend notifications for each user separately even if their information is identical?

If not, you could add the notification trait to the object you will be observing, and then the subscribers should see the notifications for that object.

But if every user should mark the notification of the changed object then yes you could do a custom notification, or duplicate notifications but for each user.

Oct
29
2 weeks ago
Activity icon

Replied to Php Array Problem In Laravel Form

@islandman before the validation if you use request()->all() you can see the country index in the array returned?

Activity icon

Replied to Best Practice, 2 Laravel Apps Communication

Hi @davidsprauel both apps are using the same database? and same core framework or are separated? If everything is separated I think you will need an specific service to send a post from v1 to v2.

Activity icon

Replied to Php Array Problem In Laravel Form

Hi @islandman, could you share the controller method? and specify whats the error that you're having?

Also in laravel we don't access $_POST variable directly, just through the Request object

Oct
25
3 weeks ago
Activity icon

Replied to Laravel Notifications Or Custom One?

Hi @mihirpatel83 Actually the default notifications are pretty flexible, you can use the Notification trait for any object, for example if several users share a School object you can put the notifiable trait on it, and let access the notification panel for all the admins of the school. In that way you just pass the objects in the dispatcher that uses the notifiable trait.

In that way you will not duplicate notifications for each user.

Oct
16
1 month ago
Activity icon

Replied to To Pivot Or Not To Pivot

Hi @xibel why not both? Let me explain In your User you can have a pairs relationship and in Pair a user relationship, that is useful for showing some information, however as you say sometimes you will need to use something like $trade->user or $trade->pair to do some inspection.

I had a similar issue once when my pivot table over time had more pivot columns and it became its own concept, however I left the initial relationships and it is consistent.

When you use pivot columns sometime you will end asking if a $user->pair->pivot exists or throw an error instead of null also if you keep only the pivot approach in order to get some specifics like Trade 3 for user 1 you will need to use more complex methods like

public function  getUserWhereHasBlabla($whatever)
    $user->whereHas('pairs', function($query)) use($whatever) {
    $query->where('x', $whatever)
    }->first();
});

Is it possible to use some methods like that to give you the access however in the case like you mention that you need some kind of inspection it is useful and quickly to take advantage of the id key of your "pivot" table.

Activity icon

Replied to Why It Is Not Working?

Hi @marcellopato what you get is an array of objects as json. What I find weird is that you are returning a json endpoint maybe but you are doing a foreach with blade, is that assumption right? In that case your code should be client side.

If the error says that you are trying to use an array as if it were an string, so try some debugging first. Inside the foreach $socios in the declaration use a {{ dd($socio) }} and check if the result is right, also because it cut the process it should not give you an error yet.

Try also changing {{ $socio['nome'] }}

Oct
12
1 month ago
Activity icon

Commented on Authentication With No Passwords?

Actually you can use this login method in Laravel 6.X too.

Oct
09
1 month ago
Activity icon

Replied to HasOne Create Duplicates On Eager Loading

Hi @theo1 Group has many meetings (one to many)?

Why don't you use a query scope?

I don't know exactly but when you are defining a hasOne its not supposed to have a latest because it should return a collection but a model. So you could try with the scope approach using the main relationship

public function lastMeetingScope($query) {
    $query->where('DESC', 'created_at');  // or whatever the field you need
}

with that you could use it as

    Group::filter($request->all())->with(['meetings' => function($meeting_query) {
        return $meeting_query->lastMeeting()->first();
    }])->get();
Activity icon

Replied to Converting Website To Laravel (Old Database)

I think the approach you're doing works, but instead of doing the import from a CSV I recommend you to do it changing db connections.

I suppose you have already the rows in your database with proper primary key and the old varchar field as a field for momentary reference.

In a database migration or an artisan command you could

Model::chunk(100, function($model) {
    $model->reference_key = Customer::where('old_varchar', $model->reference_key)->first()->id; 
});

That process is expensive also but better than importing from CSV, I think it should be a database only approach which will be even better than this.

Activity icon

Replied to Mass Asignment

@danisemet could you share how are you making that loop?

As I remember there is a catch with array casting.

If you access the attribute directly $khs->score and $khs->mahasiswa_id you should have the proper arrays. But if you do $khs->toArray() you will have it as a string stored in database.

Is that the problem you're having?

Oct
07
1 month ago
Activity icon

Replied to Mass Asignment

Hi @danisemet 2did you tried the way I said?

As @snapey says, it looks more like a relationship. However the instructions I provided should be enough.

Whats the error response? Does it saves part of the registry?

Activity icon

Replied to Testing

Hi @davy_yg what @sti3bas said was needed.

Try executing phpunit from your root project directory

Activity icon

Replied to Testing

@davy_yg phpspec it not the default suite for testing in laravel. But if you want sure you can use it following the official page instructions.

The integrated testing suite is run by /vendor/bin/phpunit

Activity icon

Replied to Testing

Hi @davy_yg

  1. Each test method should have an assertion
  2. If you are using phpunit you could test only a test with `vendor/bin/phpunit --filter=test_here _goes_the_name_of_your_method 3)There are two types of test generator for laravel, but basically is just a directory structure, both works the same, by default it will create it in the /Feature directory, if you want it in unit just add --unit to your command.

Note: All test should be named TestWhatever.php it looks like you tried to name it TagParserSpec.php which should not work that way.

Oct
06
1 month ago
Activity icon

Replied to How Do You Standardize Your JSON Responses?

Hi @aligajani I do it as @burlresearch does, yes is that good even if they are not eloquent models. Or you could even do a simple return response()->json([ 'data' => $myobject/array ])

Additionally when I'm gonna display an error I just throw the right status code of the http with a 'message' attribute.

Activity icon

Replied to Mass Asignment

Hi @danisemet Is not an issue of mass assigment but a casting.

In your model put this.

    protected $fillable = [
        'semester_id',
        'tahun_id',
        'mata_kuliah_id',
        'score',
        'mahasiswa_id'
    ];
    

    protected $casts = [
        'score' => 'array',
        'mahasiswa_id' => 'array'
    ];

But take in mind that you need to have json type fields in your database for those fields

    Schema::table('yourtable', function(Blueprint $table){
        $table->json('score')->nullable();
        $table->json('mahasiswa_id')->nullable();
    });

Oct
05
1 month ago
Activity icon

Replied to Polymorphic Help

Hi @movepixels As you say, looks like the upgrades doesn't have anything to do there. But, maybe you have a model observer or listener when you update or save your OrderItem model ?

  1. You have an object variable called $upgrade there, what it is?
Activity icon

Replied to When To Use Contracts In Packages

Hi @secretsseeker you need to understand whats the purpose of each one first. Normally the people that make packages know the importance of re-utilization, that's why they do it a package.

So when using both (contracts and traits) you could reuse code and make it scalable. With contracts they specify the specific methods that are needed in a class in order to that class be compatible with another class. With traits they add functionality to that class.

But if someday you want to add another implementation you could left the contract and add your own specific logic in the specified methods.

(https://stackoverflow.com/a/9205132/716211)

Oct
02
1 month ago
Activity icon

Replied to How To Update Data From Multiple Table From One View.

In you company.php you have in your fillable array a program_type but you don't have it in your database. Remove it from your fillable or add it to your database.

Oct
01
1 month ago
Activity icon

Replied to Vue Component Not Displaying In Another Component

@calin.ionut It could be because HTML has already a <head> tag, vuejs coding style recommends that component names should be composed. Try something like <personalized-head>

Activity icon

Replied to How To Update Data From Multiple Table From One View.

Hi @kanchan186 is your store method working? If so, your update method should have the other resources as well.

public function update(Request $request, Company $company) {
    $company->update($request->all());
    $company->companyOtherInfo->update($request->all());
}

Also you could/should simplify your creations on the store method it will be more readable, just put explicitly the attributes that aren't in your fillable.

    $company = new Company($request->all());
    $company->industry_id = $request->industry_id;
    $company->login_first = 0;
    $company->save();

If it doesnt work, could you share how many models are you using here and how are they related?

Activity icon

Replied to Vue Js / Laravel Basic Example Doesn´t Work

@cscesano do your console shows you any error?

Activity icon

Replied to Vue Component Not Displaying In Another Component

Hi @calin.ionut In your dashboard component you are not declaring your header component, it should be something like this


    import Header from "../layout/Header"; 

    export default {
        name: "Dashboard",  
    components: {
        Header
    },    
        mounted() {
            console.log('Dashboard mounted.')
        }
    }
Activity icon

Replied to Trigger An Email From A Function In A Controller

Hi @alidnet

One of the best ways is to do a mailable and trigger it in your controller, the laravel documentation is pretty straightforward

(https://laravel.com/docs/6.x/mail#generating-markdown-mailables)

Activity icon

Replied to Test Purpose

Yes you could reuse the test code you use more often like creating an object with pre-requisites, but the tests are the simplest code your application will have because it will not contain or should not contain difficult logic just inputs and assertions. So, yes at the beginning it is tedious but later you will do it as any thing you do automatically in your life.

Activity icon

Replied to Using Laravel Resources To Consume 3rd Party API OUTSIDE Of A Controller

In theory you wouldn't have any problem using it in another context like inside a method in a model.

Activity icon

Replied to Test Coverage

Ok I understand, you could do this but I don't think is a good idea because you will be deactivating code programatically, but only you know where does that happen.

When you are on a test it will skip that. Hope it helps


if (app()->environment('testing')) {
    throw new Exception('some error');
}
Activity icon

Replied to Test Purpose

You could do several types and levels of tests, you could test the UI, endpoints or objects, or combine them however you want. I recommend you to start with something easy like a happy path of an endpoint or a view.

You will learn how to tests more details once you do the easy ones

Activity icon

Replied to Test Purpose

Hi @davy_yg there are a lot lot of reasons.

  1. It is fastest to test, while you can test with a refresh button, once you have two test done, with a single shortcut you can test both tests, now imagine your entire application with 15 types of resources, and several different states of each one within 5 minutes, and do it on every deploy or as you wish. Thats why people say tests are awesome but you just notice it after the second run.

  2. When you test your app, as a developer we tend to test only the happy path, if its a form and you test that it will save you will skip that each field is required. With test driven development, each feature will be a test and will stay there. So you try in advance to check different routes of your code.

  3. You could integrate those test in an automatic tool before deploying, so it will not be deployed if something failed by your team or even yourself.

  4. Tests helps you to think easily about a feature caring only about the input and output, once done you care in the code that will meet the criteria that you thought before, it will help you to code and think more consistently.

  5. Refactors, it is a common phrase to say "if its working, don't touch it" but that's when you think that a feature was hard and it will be harder to adapt to some edge cases or new actions, if you do a test, you could do the feature however you want, and later if your response is slow, or needs more logic, or extract a part of the code to a method to use it in another place, you do that and then run the test and you will have re-utilizable code and tested to use it in another place.

There are a lot of other reasons but those are the ones of what I think are the best ones.

Activity icon

Replied to Test Coverage

Hi @gocanto I don't think that 100% code coverage is that good. Its not that has a hidden return it is that throw Exception will stop everything unless you have a try catch, what you could do are several tests that will trigger all the other flows that isn't the exception, but like in this case you already done it.

Sep
23
1 month ago
Activity icon

Replied to Semi SPA With Web And API Issue

Hi @faa technically if you are using SPA it is suppose to catch an API, or is it the recommended way. Looks like all of the routes are responding a view or doing a redirect.

I recommend you to start responding json api responses to prevent those redirections.

Activity icon

Replied to Multiple Sides To An App, Best Practices

Hi @ackerchez Maybe this talk could help you. As always it depends on your app, I recommend that if you feel or think that the logic in each role is a lot different keep it separate. But check the video. https://www.youtube.com/watch?v=MF0jFKvS4SI

Activity icon

Replied to How To OrderBy Updated_at?

Hi @duckz_1209 do you want to order just after your paginated response or from the backend?

Sep
14
2 months ago
Activity icon

Replied to Which Pagination Approach Is More Performant?

Hi @mikelovely The second one.

All the pagination should be do it by the database, if you bring all the records to your app someday it will hang out.

The fastest pagination available is not paginate but simplePaginate but you will not know in which page you are because it is based on the last id that you have and continue on the next id to take the next X rows

Look for the simplePaginate section (https://laravel.com/docs/5.8/pagination#paginating-query-builder-results)

Sep
13
2 months ago
Activity icon

Replied to Duplicate Key In Table

LOL, shit happens haha

Activity icon

Replied to What Am I Doing Wrong

Hi @jsanwo64 you are doing an if for a whole block and what you want to change is only a class name, everything else will stay the same. Try this inline conditional only for the classname

       <li {{ {{ \Request::path() == "support-living" ? "current" : "" }} >
            <a href="#">Care Services</a>
            <ul>
                <li><a href="respite-care.html">Home Care</a></li>
                <li><a href="personal-care.html">Specialist Care</a></li>
                <li><a href="elderly-service.html">Supported Living</a></li>
            </ul>
        </li>

But check first it the return of the Request::path() returned is the one you want.

Sep
11
2 months ago
Activity icon

Replied to What Am I Doing Wrong

Hi @jsanwo64 first thing first always be explicit about the problem in the title of the post. If you pay attention every single post could put the same title as yours. So you need to specify the most important aspect your problem and context in the title.

So whats the problem?

Activity icon

Replied to Duplicate Key In Table

Man @pn

You have the exact sentence twice $table->foreign('user_id')->references('id')->on('users');

You error says explicitly

duplicate key in table '#sql-555_19' (SQL: alter table `orders` add constraint `orders_user_id_foreign

By duplicate it means that its trying to create another with the same name, and in the last part says orders_user_id_foreign that its the name of your foreign key by convention of laravel

Activity icon

Replied to Curl Error 6 On Production Server

Hi @matttonks11 you need to share a lot more info.

Whats the code of your request?

Sep
10
2 months ago
Activity icon

Replied to Making Multiple Axios Calls To Different Methods To Return Data

No problem @brltdxd With my suggestion you could do 1 or several vue components, it all depends on what are you trying to achieve. If you want to do some kind of dashboard then I think you want to have maybe all cards of counts in that view, you will need to do just one call and that call will serve to populate all cards. But if you want to do several cards separated by components and show them in different views you could also use it but as you say you will get all the counters even if you don't need the other values.

Doing it in different request but calling all at the same time on the same view is not good because the requests will be longer than if you do 1 request because between the request and the response is where most of the time the applications spends time.

So, you could do as your proposed modification, for example you could accept parameters to differentiate when you need only one counter

public function index(Request $request)
{
    $counters = [];
    if ($request->filled('customers')) {
        $counters['customers'] => Customer::count();
    }
    if ($request->filled('users')) {
        $counters['users'] => User::count();
    }
    if ($request->filled('open_orders')) {
        $counters['open_orders'] => Order::open()->count();
    }

    return response()->json($counters);
}

So when you do the axios request you can call it with GET params as for example api/dashboard?customers=whatever&users=true

and that will retrieve only the counters for customers and users and not open orders

Activity icon

Replied to Making Multiple Axios Calls To Different Methods To Return Data

Hi @brltdxd looks like you are making a dashboard, in that case I would recomend a [email protected] and then return all in the response

public function index()
{
    return response()->json([
        'customers' => Customers::count(),
        'users' => ...,
        'open_orders' => ...
    ]);
}

that will be more restful but also more database performant and easier to implement because you will need only one axios call

Activity icon

Replied to More Cleaner Way

Ok, so the rank method is in a User model?

Maybe you need another aproach, for example doing it inside the Rank model. Is the rank model polymorphic? Could you share it?

Activity icon

Replied to More Cleaner Way

Hi @sadri I think that te biggest problem is in this line

$rank = Rank::where('number','<',$totalcount )->orderBy('number', 'DESC')->get()->first();

I think you could solve it with just discarding the ->get()

$rank = Rank::where('number','<',$totalcount )->orderBy('number', 'DESC')->first();

Thats because in the one you have now you are retrieving all and in the resulting collection just picking one. In the second approach that's done in the database itself.

Sep
09
2 months ago
Activity icon

Replied to Retrieving Data From A Polymorphic Table

No, to do $invoice->user->f_name you just need this and nothing else

class Invoice extends Model
{
    public function user()
    {
        return $this->belongsTo(User::class); //Its exactly what you defined as owner
    }
}
Sep
06
2 months ago
Activity icon

Replied to Eloquent : How To Store Object In Table

Hi @mostafalaravel I think as almost always the response is it depends

You can consider a single json field if the object you are going to save has multiple different structures, or if they will be only read attributes, or if you are not going to use complex searches between the attributes of your object in that case you dont need to worry about defining all fields in your models.

Otherwise I will recommend you to use standard fields, in that case you have the advantage to use eloquent or standard sql to do personalized queries.

You maybe can replicate the logic you need within the json field but take in mind that each database engine treats it differently and you can end with a more coupled system-database.

However it depends

Sep
05
2 months ago
Activity icon

Replied to Retrieving Data From A Polymorphic Table

Hi @successdav Can you save correctly?

In order to do $invoice->user->f_name; you need to specify the relationship with the user in your invoice model class

class Invoice extends Model
{
    public function user()
    {
        return $this->belongsTo(User::class); //Its exactly what you defined as owner
    }
}

But I dont think its what you want. By convention you need to put a method in your model that have the polimorphic table.

    public function invoiceable()
    {
        return $this->morphTo();
    }
Sep
04
2 months ago
Activity icon

Replied to How To Merge 2 Collections Together?

Hi @martinzeltin is it a multidimensional array I think? And you want to merge all the properties based on the user_id right?

You could try this

$collection_with_posts;
$collection_with_comments;

$integrated = [];
foreach($collection_with_posts as $post_arr) { 
    $collection_comment_arr = $collection_with_comments->where('user_id', $post_arr['user_id']);
    $integrated[] = array_merge($post_arr, $collection_comment_arr);
}

return $integrated;

You need something like that, this code is not tested. And secondly take in mind that this could be resolved more performantly on the query itself if you have that in your database. However it should work something like that.