1,410 experience to go until the next level!
In case you were wondering, you earn Laracasts experience when you:
Earned once you have completed your first Laracasts lesson.
Earned once you have earned your first 1000 experience points.
Earned when you have been with Laracasts for 1 year.
Earned when you have been with Laracasts for 2 years.
Earned when you have been with Laracasts for 3 years.
Earned when you have been with Laracasts for 4 years.
Earned when you have been with Laracasts for 5 years.
Earned when at least one Laracasts series has been fully completed.
Earned after your first post on the Laracasts forum.
Earned once 100 Laracasts lessons have been completed.
Earned once you receive your first "Best Reply" award on the Laracasts forum.
Earned if you are a paying Laracasts subscriber.
Earned if you have a lifetime subscription to Laracasts.
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.
Earned once you have achieved 500 forum replies.
Earned once your experience points passes 100,000.
Earned once your experience points hits 10,000.
Earned once 1000 Laracasts lessons have been completed.
Earned once your "Best Reply" award count is 100 or more.
Earned once your experience points passes 1 million.
Earned once your experience points ranks in the top 50 of all Laracasts users.
Earned once your experience points ranks in the top 10 of all Laracasts users.
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!
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:
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.
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.
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
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.
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>
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.
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>
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.
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.
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
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
Awarded Best Reply on How To Build Up Offensive Words In A Chat(Group & Personal) In Laravel?
Awarded Best Reply on How Set Namespace When Create File With Stub File?
You could replace a DummyNamespace
string just like you do for DummyService
and 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
{
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,
]);
});
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 ?
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.
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
Replied to How Set Namespace When Create File With Stub File?
You could replace a DummyNamespace
string just like you do for DummyService
and 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
{
Replied to Update Multi Value Array
Your request rules don't contemplate the attribute projectTaskEmployee
but $projectTask
does. Maybe is a misspelled variable ?
From:
if ($request->projectTaskEmployee != []) {
$ids =[$request->ProjectTaskEmployee];
To:
if ($projectTask->projectTaskEmployee != []) {
$ids =[$projectTask->ProjectTaskEmployee];
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
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
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.
Replied to Nova Throws Fillable Error When Model Is Fillable
Could you check if the visibility of the attribute is defined as the parent object ?
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 ;)
Replied to Vapor, Firebase, Microservice, ...? What To User For Big App.
Which blog article did you read ?
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.
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.
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.
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.
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.
}
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.
}
Replied to Options For Package Resources Discovery
Hi,
You seem to be describing Service Providers. Did you take a look on them ?
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
Replied to Add Api Resource Collection To Response Data
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
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.
Replied to Laravel Auto Populate Ajax/jquery
Why don't your filter null values before sending to the frontend ?
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.
Replied to Lumen Still Sending Mails To Mailtrap After Changed Completely The Configurations
I guess that is the way.
Replied to Lumen Still Sending Mails To Mailtrap After Changed Completely The Configurations
Locally or live server?
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.
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()) {
// ...
}