imrodrigoalves

Member Since 4 Months Ago

Lisbon

Experience Points
13,590
Total
Experience

1,410 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
74
Lessons
Completed
Best Reply Awards
9
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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.

  • Community Pillar

    Earned once your experience points ranks in the top 10 of all Laracasts users.

Level 3
13,590 XP
Apr
12
1 day ago
Activity icon

Replied to Fetching Many Records From Database

One question.

Is your skip() and take() doing it at database level (basically pagination) or at app level ?

If it's the latter you'll end up being loading 2k records to a in-memory array that you wont be using while the former is using the database implementing limit and offset which only loads the data that you want.

Regards and good luck!

Apr
09
4 days ago
Activity icon

Replied to How To Use User Factory In Package Development Testing

Please paste the code of your test so we can provide better feedback.

Possible problems/solutions:

  1. Class not being imported in use -> add use App\Models\User;
  2. Class doesn't exist ? Wrong namespace ?
  3. composer dump-autoload
Activity icon

Replied to How To Prevent Duplicate Invoice No In Laravel

I believe you should look at database transactions if you're not using them already.

Activity icon

Replied to Fetching Many Records From Database

You're correct, it's bad to get so many records and then filter them because of the reasons you mentioned. (It won't scale well)

You should paginate the records.

Hit the endpoint and get 20 records paginated, when the user reaches the end of the scroll, you hit the endpoint again to get another 20.

Docs: https://laravel.com/docs/8.x/pagination

Activity icon

Replied to Config Filesystem To Upload To The Public Folder

You don't want to upload then to the public folder but rather have access to it.

Check more in the docs: https://laravel.com/docs/8.x/filesystem#the-public-disk

Apr
08
5 days ago
Activity icon

Replied to Laravel Sail / Docker Is Slow

In my project I added opcache and it is running just like having the LAMP stack installed locally on my machine.

My docker has 4 CPUs and 3Gb of memory.

This was the tutorial that I used.

https://laravel-news.com/php-opcache-docke

Mar
27
2 weeks ago
Activity icon

Awarded Best Reply on Laravel Sail In Production

I faced the same issue.

So, to implement it I basically re-wrote the entire dockerfile to be based on php:7.4-apache with the required extensions and modified the start-container file to initialize the apache server and the supervisor.

This retains all local development commands using sail.

My only problem is with slowness.

As a side note, I think it's possible only by installing the apache server in the initial dockerfile provided by sail, creating and copying the apache config and initialize the apache from the start-container.

Dockerfile

FROM php:7.4-apache

WORKDIR /var/www/html

ARG WWWGROUP

ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN apt-get update && apt-get install -y \
        libpng-dev \
        zlib1g-dev \
        libxml2-dev \
        libzip-dev \
        libonig-dev \
        zip \
        curl \
        unzip \
        libmagickwand-dev --no-install-recommends \
        supervisor \
        ghostscript \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libpng-dev \
        libc-client-dev libkrb5-dev \
    && docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install -j$(nproc) gd \
    && docker-php-ext-install pdo_mysql \
    && docker-php-ext-install mysqli \
    && docker-php-ext-install zip \
    && docker-php-ext-install mbstring \
    && docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
    && docker-php-ext-install -j$(nproc) imap \
    && mkdir -p /usr/src/php/ext/imagick \
    && curl -fsSL https://github.com/Imagick/imagick/archive/06116aa24b76edaf6b1693198f79e6c295eda8a9.tar.gz | tar xvz -C "/usr/src/php/ext/imagick" --strip 1 \
    && docker-php-ext-install imagick \
    && docker-php-source delete

RUN sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml
   
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
    
COPY vhost.conf /etc/apache2/sites-available/000-default.conf

RUN groupadd --force -g $WWWGROUP sail

RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail

RUN chown -R sail:$WWWGROUP /var/www/html \
    && a2enmod rewrite \
    && a2enmod headers

COPY start-container /usr/local/bin/start-container

COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

COPY php.ini /usr/local/etc/php/php.ini

RUN chmod +x /usr/local/bin/start-container
    
ENTRYPOINT ["start-container"]
start-container

#!/usr/bin/env bash

if [ $# -gt 0 ];then
    exec gosu $WWWUSER "[email protected]"
else
    # sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml
   
    exec docker-php-entrypoint apache2-foreground
    
    /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
fi
vhosts.config

ServerName localhost

<VirtualHost *:80>
    
    DocumentRoot /var/www/html/public/
    <Directory /var/www/html/public/>
        DirectoryIndex index.php
        Options Indexes FollowSymLinks Includes ExecCGI		
		AllowOverride All
		Order allow,deny
		Allow from all
		Require all granted
		RewriteEngine On
    </Directory>
    
    # Send apache logs to stdout and stderr
    CustomLog /proc/self/fd/1 common
    ErrorLog /proc/self/fd/2
</VirtualHost>
Activity icon

Replied to How Not To Show Automatic Date 01 January 1970, If The Date Value Is Null

If you need to perform that everywhere for the items,look for accessors.

Mar
25
2 weeks ago
Activity icon

Replied to Laravel Sail In Production

I faced the same issue.

So, to implement it I basically re-wrote the entire dockerfile to be based on php:7.4-apache with the required extensions and modified the start-container file to initialize the apache server and the supervisor.

This retains all local development commands using sail.

My only problem is with slowness.

As a side note, I think it's possible only by installing the apache server in the initial dockerfile provided by sail, creating and copying the apache config and initialize the apache from the start-container.

Dockerfile

FROM php:7.4-apache

WORKDIR /var/www/html

ARG WWWGROUP

ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN apt-get update && apt-get install -y \
        libpng-dev \
        zlib1g-dev \
        libxml2-dev \
        libzip-dev \
        libonig-dev \
        zip \
        curl \
        unzip \
        libmagickwand-dev --no-install-recommends \
        supervisor \
        ghostscript \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libpng-dev \
        libc-client-dev libkrb5-dev \
    && docker-php-ext-configure gd --with-freetype --with-jpeg \
    && docker-php-ext-install -j$(nproc) gd \
    && docker-php-ext-install pdo_mysql \
    && docker-php-ext-install mysqli \
    && docker-php-ext-install zip \
    && docker-php-ext-install mbstring \
    && docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
    && docker-php-ext-install -j$(nproc) imap \
    && mkdir -p /usr/src/php/ext/imagick \
    && curl -fsSL https://github.com/Imagick/imagick/archive/06116aa24b76edaf6b1693198f79e6c295eda8a9.tar.gz | tar xvz -C "/usr/src/php/ext/imagick" --strip 1 \
    && docker-php-ext-install imagick \
    && docker-php-source delete

RUN sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml
   
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
    
COPY vhost.conf /etc/apache2/sites-available/000-default.conf

RUN groupadd --force -g $WWWGROUP sail

RUN useradd -ms /bin/bash --no-user-group -g $WWWGROUP -u 1337 sail

RUN chown -R sail:$WWWGROUP /var/www/html \
    && a2enmod rewrite \
    && a2enmod headers

COPY start-container /usr/local/bin/start-container

COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

COPY php.ini /usr/local/etc/php/php.ini

RUN chmod +x /usr/local/bin/start-container
    
ENTRYPOINT ["start-container"]
start-container

#!/usr/bin/env bash

if [ $# -gt 0 ];then
    exec gosu $WWWUSER "[email protected]"
else
    # sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml
   
    exec docker-php-entrypoint apache2-foreground
    
    /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf
fi
vhosts.config

ServerName localhost

<VirtualHost *:80>
    
    DocumentRoot /var/www/html/public/
    <Directory /var/www/html/public/>
        DirectoryIndex index.php
        Options Indexes FollowSymLinks Includes ExecCGI		
		AllowOverride All
		Order allow,deny
		Allow from all
		Require all granted
		RewriteEngine On
    </Directory>
    
    # Send apache logs to stdout and stderr
    CustomLog /proc/self/fd/1 common
    ErrorLog /proc/self/fd/2
</VirtualHost>
Activity icon

Replied to Laravel 8 Exception Context

My understanding is that you'll need to implement a custom exception, define those variables in the class and initialize them from the constructor when calling the exception.

Mar
15
4 weeks ago
Activity icon

Replied to Info: Need Clearification On Mail Setting In .env File.

While working locally it may work, when working with external providers (smtp accounts, mailtrap, etc) you'll need to authenticate using those keys.

Mar
12
1 month ago
Activity icon

Commented on Laravel Sail

You changed the docker-composer laravel.test to something else.

To accommodate your change, you'll need to add

.env

APP_SERVICE=sameNameAsSomethingElse
Mar
11
1 month ago
Activity icon

Replied to Where Are You All From?

Hey,

Lisbon, Portugal

:)

Mar
09
1 month ago
Activity icon

Replied to Stripe CLI

When using stripe for windows I believe that you need to execute the file from the terminal using the params that you want.

in terminal run:

./stripe.exe command
Feb
11
2 months ago
Activity icon

Awarded Best Reply on How Set Namespace When Create File With Stub File?

You could replace a DummyNamespace string just like you do for DummyServiceand DummyModel

<?php

namespace DummyNamespace; // replace App with DummyNamespace and then replace this string in your command

use App\Services\Base\BaseService;
use Illuminate\Http\Request;

/**
 * Class DummyService
 * @package App\Services\Service
 */
class DummyService extends BaseService
{
Feb
09
2 months ago
Activity icon

Replied to How To Update A Column Using Another Table's Column ?

I believe something like this would point you in the right direction.

Countries::all()->each(function($country){
    CompanyAddress::where('country', 'like', $country->code)->update([
        'country_id' => $country->id,
    ]);
});
Feb
08
2 months ago
Activity icon

Replied to Different Token Expiry Times For Different Grant Types

According to the docs you can modify your expiration times in the service provider but I don't see anything preventing from doing it right before issuing the token. Have you tried it ?

Activity icon

Awarded Best Reply on Problem Using DatabaseTransactions Trait With Database Set Dynamically

While the database exists in MySql what the error is saying is that the connection to that database is not configured within Laravel.

Therefore, based on $connections = $this->app['config']['database.connections']; line I believe problem is that you're missing the connection to the database within config/database at the connections key of the array.

Feb
07
2 months ago
Activity icon

Awarded Best Reply on Does Search Engine Index Images In The Storage Directory?

Hi, Search engines don't have access to anything that is not public because the server is configured only to access the public folder and nothing else. The reason for this is security and to hide the code of your application.

If you wish to put something it in the public folder, you don't need to move them but rather create a storage link

Activity icon

Replied to How Set Namespace When Create File With Stub File?

You could replace a DummyNamespace string just like you do for DummyServiceand DummyModel

<?php

namespace DummyNamespace; // replace App with DummyNamespace and then replace this string in your command

use App\Services\Base\BaseService;
use Illuminate\Http\Request;

/**
 * Class DummyService
 * @package App\Services\Service
 */
class DummyService extends BaseService
{
Activity icon

Replied to Update Multi Value Array

Your request rules don't contemplate the attribute projectTaskEmployeebut $projectTaskdoes. Maybe is a misspelled variable ?

From:
if ($request->projectTaskEmployee  != []) {
        $ids =[$request->ProjectTaskEmployee];


To:
if ($projectTask->projectTaskEmployee  != []) {
        $ids =[$projectTask->ProjectTaskEmployee];

Activity icon

Replied to Rule::ExcludeIf() ?

You've the ability to create custom rules to fit your needs :)

https://laravel.com/docs/8.x/validation#custom-validation-rules

Activity icon

Replied to Does Search Engine Index Images In The Storage Directory?

Hi, Search engines don't have access to anything that is not public because the server is configured only to access the public folder and nothing else. The reason for this is security and to hide the code of your application.

If you wish to put something it in the public folder, you don't need to move them but rather create a storage link

Activity icon

Replied to Problem Using DatabaseTransactions Trait With Database Set Dynamically

While the database exists in MySql what the error is saying is that the connection to that database is not configured within Laravel.

Therefore, based on $connections = $this->app['config']['database.connections']; line I believe problem is that you're missing the connection to the database within config/database at the connections key of the array.

Jan
29
2 months ago
Activity icon

Replied to Infinity Categories Level Nested With Bootstrap ?

I'm sorry it took me so long to answer you.

Maybe Blade Components can help you with that ;)

Jan
21
2 months ago
Activity icon

Replied to Vapor, Firebase, Microservice, ...? What To User For Big App.

Which blog article did you read ?

Dec
28
3 months ago
Activity icon

Awarded Best Reply on Dynamic CSS

Assuming you want to do it inline since it is dynamic.

<?php

function generateCssFromArray(array $attributes)
{
    $css = '';
    
    foreach($attributes as $key => $value)
    {
        $css .= " {$key}: $value;";
    }
    
    return $css;
}

$atrr = [
    "margin-top" => "4px",
    "padding" => "3px 4x 4px 3px",
    "border-top" => "4px solid black"
];

$css = generateCssFromArray($atrr);

echo $css; //  margin-top: 4px; padding: 3px 4x 4px 3px; border-top: 4px solid black;

From a quick search (Google: array to css php) : https://ourcodeworld.com/articles/read/754/how-to-convert-a-nested-php-array-to-a-css-sass-less-rule-string

Best of luck.

Activity icon

Replied to [Homestead] Which Is Better, Mapping Individual Applications Or A Single Directory?

I use homestead as my default development environment and I map a single directory with all my projects with a mapping of the URL to the correct folder within that single folder. (with vagrant-hostsupdater too)

I never felt it slow because of the reason provided.

But I've noticed that if I use multiple php versions in multiple projects the boot time would increase exponentially.

So if I use multiple php versions I rather boot a VM for each project to keep boot times low.

Activity icon

Replied to Dynamic CSS

Assuming you want to do it inline since it is dynamic.

<?php

function generateCssFromArray(array $attributes)
{
    $css = '';
    
    foreach($attributes as $key => $value)
    {
        $css .= " {$key}: $value;";
    }
    
    return $css;
}

$atrr = [
    "margin-top" => "4px",
    "padding" => "3px 4x 4px 3px",
    "border-top" => "4px solid black"
];

$css = generateCssFromArray($atrr);

echo $css; //  margin-top: 4px; padding: 3px 4x 4px 3px; border-top: 4px solid black;

From a quick search (Google: array to css php) : https://ourcodeworld.com/articles/read/754/how-to-convert-a-nested-php-array-to-a-css-sass-less-rule-string

Best of luck.

Activity icon

Replied to Infinity Categories Level Nested With Bootstrap ?

With the structure described I believe you can already do it.

Using this structure you can always know what is next and before.

attempting to map database to image

categories
id - parent_id
1 - null -> Root navbar element
2 - 1 -> Drop Item 1
3 - 2 -> Drop Item 2
4 - 3 -> Submenu 1
5 - 3 -> -> Submenu 2
6 - null -> Root navbar element
7 - 6

My only suggestion would be for you to add a position column so that you can manipulate in which order the menus/submenus are displayed.

Activity icon

Awarded Best Reply on 403 In FormRequest

From the docs: https://laravel.com/docs/8.x/validation#authorizing-form-requests

If the authorize method returns false, an HTTP response with a 403 status code will automatically be returned and your controller method will not execute.

Therefore in your code:

class DownloadReportExcelRequest extends FormRequest
{
    public function authorize()
    {
        return false; <--- This line is what is causing the 403.
    }
Activity icon

Replied to 403 In FormRequest

From the docs: https://laravel.com/docs/8.x/validation#authorizing-form-requests

If the authorize method returns false, an HTTP response with a 403 status code will automatically be returned and your controller method will not execute.

Therefore in your code:

class DownloadReportExcelRequest extends FormRequest
{
    public function authorize()
    {
        return false; <--- This line is what is causing the 403.
    }
Dec
26
3 months ago
Activity icon

Replied to Options For Package Resources Discovery

Hi,

You seem to be describing Service Providers. Did you take a look on them ?

Activity icon

Replied to Field Level Permissions In A Model?

Hi,

The behavior describe is very dynamic and from my perspective if you want it to be configurable in the future you need to store it in a permanent storage (database).

My suggestion is to add two columns to your model, user_update_rules and admin_update_rules. I also suggest that you store these as json so you can cast them to array and load them according to the user requesting.

Regards

Dec
24
3 months ago
Activity icon

Commented on Interactive Rebasing

If you have git installed in windows you can create a .bash_profile file in your user folder (C:\Users\YOUR_USERNAME) and put your aliases there

Activity icon

Commented on Handling Merge Conflicts

Usually it's best that you do it manually but you can use the -X theirs|ours flag to set automatic behaviour.

Dec
23
3 months ago
Activity icon

Replied to Laravel Auto Populate Ajax/jquery

Why don't your filter null values before sending to the frontend ?

Activity icon

Replied to Cashier/stripe Subscription Not Adding Complete Data In DB

My best guess is just to look at the commits from yesterday and look if anything changed.

Activity icon

Replied to Lumen Still Sending Mails To Mailtrap After Changed Completely The Configurations

If you're using a queue to send emails you need to also restart the queue.

Dec
22
3 months ago
Activity icon

Replied to Authenticate Different Frontend With Sanctum

Assuming your API is a REST API, then you can check if the request is expecting a JSON answer

From the documentation:

Since many applications only serve HTML or JSON, you may use the expectsJson method to quickly determine if the incoming request expects a JSON response:

if ($request->expectsJson()) {
    // ...
}