hfalucas

hfalucas

Member Since 5 Years Ago

Porto - Portugal

Experience Points 77,740
Experience Level 16

2,260 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 935
Lessons
Completed
Best Reply Awards 10
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.

09 Jul
2 months ago

hfalucas commented on How To Dynamically Inline SVG Files In Vue Components

I had to implement that for a project of mine a while back and this is what I ended up with:

<template>
    <svg :viewBox="viewbox" :width="width" :height="height" v-html="use" v-on="$listeners"></svg>
</template>
<script>
export default {
    name: 'WSvg',

    props: {
        path: { ... },

        symbol: { ... },

        width: { ... },

        height: { ... },

        size: { ... }
    },

    computed: {
        use () {
            return `<use xlink:href="${this.path}#${this.symbol}"></use>`
        },

        viewbox () {
            if (this.size) return this.size

            return `0 0 ${this.width} ${this.height}`
        }
    }
}
</script>

Didn't needed the webpack rule if useing the xlink:href, but also don't know if that gives less flexibility or is a bad practice

PS: It's an SVG sprite

11 Feb
7 months ago

hfalucas left a reply on Pixel Measuring Tool

I t just looks like the same measurement tool used when using the cmd+shift+4 keyboard shortcut for creating custom sized screenshots.

Yes. I believe is the screenshot tool

14 Jan
8 months ago

hfalucas left a reply on Changes To App.blade.php Not Rendering

I believe your section should be

@section('bottom-scripts')

...

@endsection

hfalucas left a reply on How To Reduce App.js?

Some ways that I know:

  1. Asynchronously load components in Vue, this will create a bunch of smaller chunks
  2. Use webpack to compress the files (.gz)

...and that's all I know. Also interested in some other tips :)

hfalucas left a reply on Limit Attendance Records Just One Per Day

Sorry @viernes I didn't understand the English this time

11 Jan
8 months ago

hfalucas left a reply on Convert JSON String To Array

Yes, the function returns the keys, so you need to set a variable hold those values.

$keys = array_keys_multi($response);

print_r($keys);

hfalucas left a reply on Convert JSON String To Array

No! where is your $keys variable?

hfalucas left a reply on Notification And Broadcasts

The class seems fine.

You are firing the notification inside the event listener? And inside there you also have the collection of users(or user) to send the notification to?

hfalucas left a reply on Notification And Broadcasts

Can you show the DeliverynoteSaved class and where it is called?

hfalucas left a reply on Convert JSON String To Array

If you want to have functions like that available everyone in your app, the best way is to create a helpers file and autoload it.

// create a helpers.php file under /app for example
function array_keys_multi(array $array)
{
    $keys = array();
    foreach ($array as $key => $value) {
        $keys[] = $key;
        if (is_array($array[$key])) {
            $keys = array_merge($keys, array_keys_multi($array[$key]));
        }
    }
    return $keys;
}

// update your composer.php with:
 "autoload": {
        "psr-4": {...},
        "classmap": [...],
        "files": ["app/helpers.php"] //add this line
 },

// anywhere you need to call the function
array_keys_multi($myArray)

Another option is simply to create a method in the current class and call it

hfalucas left a reply on Notification And Broadcasts

@moenchfracht I didn't understood sorry

hfalucas left a reply on Laravel Project Deployment Problem In Shared Hosting (000webhost)

the public_path('images') aren't writeable by the server

Email the host asking to give you permissions or maybe try to upload the files to an AWS S3 bucket? lol

hfalucas left a reply on Taking TWO Variables From Inside A Foreach And Pass To A Modal

@rafaelmunoznl sorry, maybe I didn't explain myself right. What I mean is inside the jquery block add the line below, then click on the button to trigger the modal and show the log from the console tab :)

<script>
    $('#modal_1').on('show.bs.modal', function (event) {
      console.log(event) // add this and click on the modal
      ...
    });
</script>

hfalucas left a reply on Alternative Methods To The Boot() Method Of AppServiceProvider.php

Depending on your code it might make sense creating your own Service Providers

hfalucas left a reply on Convert JSON String To Array

Laravel doesn't have any helper for that so you'll have to write that logic on your own

hfalucas left a reply on Convert JSON String To Array

You can loop through the array or if you are using Laravel there's the array helper data_get (you can use wildcards)

$data = ['products' => ['desk' => ['price' => 100]]];

$price = data_get($data, 'products.desk.price');

// 100

hfalucas left a reply on Taking TWO Variables From Inside A Foreach And Pass To A Modal

Can you show the output of console.log event?

hfalucas left a reply on Convert JSON String To Array

Assign it to a variable and access it like a normal array.

$response = json_decode(file_get_contents($url), true);

$keys = array_keys($response)

$keys[0] // country
$keys[3] // area_name

// or

$response['country'] // England
$response['result_count'] // 1796

hfalucas left a reply on Convert JSON String To Array

Is everything being converted to an array? Show a small example of the output you are having now as well as what are trying to do and how.

hfalucas left a reply on Taking TWO Variables From Inside A Foreach And Pass To A Modal

If you copied and pasted directly from your codebase, seems like you a missing a " between data-imagename and data-slug

<button type="button" class="btn btn-block btn-primary" data-toggle="modal" data-target="#modal_1" data-imagename="{{$image->image_name}} data-slug="{{$image->slug}}">
            {{$image->image_name}}
</button>

// Should be

<button type="button" class="btn btn-block btn-primary" data-toggle="modal" data-target="#modal_1" data-imagename="{{$image->image_name}}" data-slug="{{$image->slug}}">
            {{$image->image_name}}
</button>

hfalucas left a reply on Convert JSON String To Array

This should return an array

json_decode(file_get_contents($url), true);

More info: http://php.net/manual/en/function.json-decode.php

hfalucas left a reply on Notification And Broadcasts

One more question: where should I fire the notification from?

I don't know if there's a right place for that, but from the controller doesn't seem to be bad.

And should I also fire the broadcasting-event? If so, which one first?

Yes broadcast the event and then the notification or vice-versa :)

hfalucas left a reply on Limit Attendance Records Just One Per Day

@viernes A policy would be a good place to put it, I would go with that :)

hfalucas left a reply on Convenient And DRY Way To Save Morphable To Relationship

Do you place controllers in this folders? Or you leave them in Http/Controllers?

@sergey_bruhin I keep the controllers in the default folder.

The @d9705996 suggestion is interesting too

10 Jan
8 months ago

hfalucas left a reply on How To Get ContentEditable Value

<h1 v-text="widget.title" @blur="update" contentEditable ref="editable"> Main Page Title</h1>


this.$refs.editable.innerHTML

hfalucas left a reply on How To Send A Header With Laravel Api Response?

According to https://laravel.com/docs/5.7/responses#attaching-headers-to-responses

$blog = Blog::all();

return response()->json($blog)->withHeaders(['X-Total-Count', $blog->count()]);

hfalucas left a reply on Convenient And DRY Way To Save Morphable To Relationship

@sergey_bruhin I like to create folders for each model and put everything related to them there for example:

/Comments
    /Events
    /Listeners
    /Notifications
    ...
    Comment.php
/Reviews
    /Events
    /Listeners
    /Notifications
    ...
    Review.php
/Services
    MediaFiles.php
    ...

This is total overkill for small or even medium projects.

If your project isn't that big putting files like MediaFiles in a /Services folder right under /app and Comments. Reviews, etc in a /Common named folder for example.

In the end honestly comes down to personal preference and how it feels better to you :)

hfalucas left a reply on Limit Attendance Records Just One Per Day

@xtremer360 yeah that is also possible, although he states that is the client who creates the attendance record for their employees. I just didn't want to make too many assumptions about the structure of his code.

hfalucas left a reply on Limit Attendance Records Just One Per Day

Check if the given user has an attendance record for that day before allowing to insert one.

// Pseudo Code...
$attended = Attendance::where('user_id', $user->id)
    ->whereDate('created_at', Carbon::today()) // created_at is just an example
    ->exists();

if ($attended) {
    // The user already has attended, so lets redirect back/abort etc
    return redirect()->back(); 
}

// Add an attendance record

hfalucas left a reply on Notification And Broadcasts

This is how I am doing:

1) Add the Notifiable trait in the User model

use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
    use  Notifiable;
    // ...
}

2) Fire the Notification

Notification::send($users, new PostWasCreated($post));

3) Choose the channels

class PostWasCreated extends Notification implements ShouldQueue
{
    use Queueable;


    protected $post;


    public function __construct( $post)
    {
        $this->post = $post;
    }


    public function via($notifiable)
    {
        return ['database', 'broadcast'];
    }


    public function toDatabase($notifiable)
    {
        return [
        'id' => $post->id,
        'title' => $post->title
        ];
    }


    public function toBroadcast($notifiable)
    {
        return new BroadcastMessage([
        'id' => $post->id,
        'title' => $post->title
    ]);
    }
}

4) Fetch the unread notifications for the user

$user->unreadNotifications()

hfalucas left a reply on Notification And Broadcasts

In your notification class add database to in the via method:

    public function via($notifiable)
    {
        return ['database', 'broadcast'];
    }

   public function toDatabase($notifiable)
    {
        return [
            // data to be saved in the db
        ];
    }

    public function toBroadcast($notifiable)
    {
        return new BroadcastMessage([
            // data to broadcast
        ]);
    }

hfalucas left a reply on Limit Attendance Records Just One Per Day

You can fetch the last attendance for the given user and compare with the current date, that should do it :)

hfalucas left a reply on Better Way To Add Optional Array Key?

I would probably do it like this:

$data = [
    'ticket_id' => $ticket->ticket->id,
    'meeting_id' => $ticket->meeting->id,
    'quantity' => $ticket->qty,
    'price' => $ticket->price,
];

$data = array_merge(
    $data, 
    array_filter(['info' => $ticket->options->info])
);

hfalucas left a reply on Why Isn't Data Updating?

You mean the students array is never populated or the {{ this.students }} in your template is never updated?

hfalucas left a reply on Creating A Dynamic Template

Put the v-ifin the div instead of the template

<template>
    <div class="template-1" v-if="create_page === 'create_page'">
        yay
    </div>

    <div class="template-2" v-else>
        no
    </div>
</template> 

hfalucas left a reply on Method Illuminate\Database\Eloquent\Collection::join

By calling all() will give you a collection of Application models, so the join method is not available.

ApplicationModel::all();

What you need to do as @douglasakula said is:

ApplicationModel::join('tb_detail', 'tb.detail.detail_id', '=', 'applications.detail_id')->get();

hfalucas left a reply on Push To Nested Array

The easiest way is using the Laravel array helper data_set()

$data = ['products' => ['desk' => ['price' => 100]]];

data_set($data, 'products.desk.price', 200);

// ['products' => ['desk' => ['price' => 200]]]

You can also use wildcards to set values:

$data = [
    'products' => [
        ['name' => 'Desk 1', 'price' => 100],
        ['name' => 'Desk 2', 'price' => 150],
    ],
];

// All products will have in_stock key set to true
data_set($data, 'products.*.in_stock', true);  

// Only the first product will have the in_stock key
data_set($data, 'products.0.in_stock', true);
09 Jan
8 months ago

hfalucas left a reply on Revoke Notification (from Queue?) If Model-item Has Been Shown

When sending the message do you know which users are seeing it/online at that moment?

hfalucas left a reply on Compare And Filter Json Params On Click

In that case, you should use a computed property instead of filtering in the products array directly. Currently, you are replacing the original products array with new filtered one, so it's impossible to retrieve the excluded items.

hfalucas left a reply on Compare And Filter Json Params On Click

In that case, you would have to check if the current project id inside the filter callback is inside the rules array:

removeChild: function (product) {
    this.products = this.products.filter(prd => { 
        return ! product.rules.includes(prd.id)
    });
}

hfalucas left a reply on Compare And Filter Json Params On Click

You want to compare rules not ids

methods:{
        removeChild: function (product) {
            this.products = this.products.filter(prd => prd.rules === product.rules);
        }
    }

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

The best is probably decimal(19,4), or save everything in cents using an int

hfalucas left a reply on Translation Problem To Eloquen

Is usuarios a pivot table? Do you have a Usuariosmodel class?

hfalucas left a reply on Using Email Verification But Also Sometimes Manually Verifying Users.

Use the forceCreate method like so: User::forceCreate([...]).

This way only in that specific location it allows to mass assign fields.

hfalucas left a reply on Getting A Select Drop Down To Be Selected In Vue

Get rid the :selected="" attribute

hfalucas left a reply on Convenient And DRY Way To Save Morphable To Relationship

How could I organize my classes (and files) with this approach from your perspective if I have multiple morphables (images, comments, avatars, etc)?

You mean like hitting for example/comments and that controller knows whether it should create a comment for an article, product or some other model?

hfalucas left a reply on Fire Eloquent Event Dynamically

You can listen for all eloquent events including eloquent.retrieved, eloquent.booting, etc with this block of code:

Event::listen('eloquent.*', function($event, $model) {
        //
 });

If you only want the CRUD related ones, in that case, you gonna have to be specific and pass an array with them:

Event::listen(['eloquent.saved:*', 'eloquent.created:*'], function($event, $model) {
        //
 });

A good location for this code to be placed is inside the boot method of EventServiceProvider class

hfalucas left a reply on Find Key With Data In Nested Collection Or Array

The array_get function retrieves a value from a deeply nested array using "dot" notation:

$array = ['products' => ['desk' => ['price' => 100]]];

$price = array_get($array, 'products.desk.price');

Make sure to check out the other helpers they are really useful :)