fredemagi

fredemagi

Member Since 1 Year Ago

Experience Points 1,500
Experience Level 1

3,500 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 0
Lessons
Completed
Best Reply Awards 0
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.

16 Jul
1 month ago

fredemagi left a reply on Compiled Css Not Reflecting Changes After Deploy

For some reason, its working now 😂🙄.

fredemagi left a reply on Compiled Css Not Reflecting Changes After Deploy

Im uploading all the partials which are compiled and combined in the deployment process with npm run production. I can see that the partial CSS is uploaded (using filezilla), but the compiled dont reflect the change :/.

fredemagi started a new conversation Compiled Css Not Reflecting Changes After Deploy

I have made some changes locally to a css file which works locally. However, when I deploy to Laravel forge, the css file gets uploaded, but the compiled css file (combined of all) does not contain the change. What could be wrong?

11 Jul
1 month ago

fredemagi left a reply on Deploy Error: In PredisConnector.php Line. Class 'Predis\Client' Not Found

I did without success.

Solution: I started all over with deployment and a fresh upload to github.

10 Jul
1 month ago

fredemagi left a reply on Deploy Error: In PredisConnector.php Line. Class 'Predis\Client' Not Found

Yes to all. I just tried composer require predis/predis on the server, but same error. The full log is:

Wed Jul 10 14:00:54 UTC 2019
Application is now in maintenance mode.
From github.com:USER/REPO
 * branch            master     -> FETCH_HEAD
Already up to date.
Loading composer repositories with package information
Installing dependencies from lock file
Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.
Nothing to install or update
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: fideloper/proxy
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Package manifest generated successfully.

In PredisConnector.php line 25:
                                   
  Class 'Predis\Client' not found  
                                   

fredemagi started a new conversation Deploy Error: In PredisConnector.php Line. Class 'Predis\Client' Not Found

As the title indicates, I get an error through deploy on Laravel Forge to Digital Ocean. I have checked the file locally, and Predit/Client is included. What do I do wrong?

14 May
3 months ago

fredemagi left a reply on Dynamically Add Src To Image In Blade Using @yield

I found a solution. I made the parallax as a component and used slots for the variables ^_^.

13 May
3 months ago

fredemagi left a reply on Dynamically Add Src To Image In Blade Using @yield

@DEVFREY - The section is placed inside a view. The yield is placed inside another view which is included in the layout before the section.

I don't think the section should occur before the yield, because I have insertet a yield in the title tag in the head-tag which occurs before the corresponding section.

fredemagi started a new conversation Dynamically Add Src To Image In Blade Using @yield

In a blade view I add an image tag which should have it's src value dynamically replaced. The html looks like

<img class="jarallax-img" src="@yield('parallax_image')" alt="">

However, when I try to replace the value using

@section('parallax_image', $variable->image)

it yields src(unknown).

What do I do wrong?

03 May
3 months ago
29 Apr
3 months ago

fredemagi started a new conversation Validation Rule For MySQL Decimal

I know this has been debated before her: https://laracasts.com/discuss/channels/laravel/controller-validation-rule-for-mysql-decimal202

In the solution, it seems that it doesn't take into account the length of the digits (the number on the left side of the comma, like decimal(7,2)). I need two rules, one for decimal(7,2) and another for decimal(6,3) in Laravel, but I'm not sure how the regexs should look like. Any help is highly appreciated.

22 Apr
4 months ago

fredemagi started a new conversation Transpile CKEditor To ES5 Using Webpack/Laravel Mix

In order to get CKEditor to work on previous versions of Safari in iOS 10, I was recommended to transpile CKEditor to ES5 using their guide: https://ckeditor.com/docs/ckeditor5/latest/builds/guides/integration/advanced-setup.html#option-building-to-es5-target

However, when I need to add

module: {
    rules: [
        {
            test: /ckeditor5-[^\/\]+[\/\].*\.js$/,
            use: [
                {
                    loader: 'babel-loader',
                    options: {
                        presets: [ require( '@babel/preset-env' ) ]
                    }
                }
            ]
        },
        ...
    ]
}

to webpack.mix.js, I'm not sure about the syntax. The same goes for

entry: [
    require.resolve( 'regenerator-runtime/runtime.js' )
]

Any help is appreciated.

15 Apr
4 months ago

fredemagi left a reply on CKEditor/ClassicEditor Not Working On IPad

@BOBBYBOUWMANN - It did. I will take a look at the guide provided later this week.

fredemagi left a reply on CKEditor/ClassicEditor Not Working On IPad

@BOBBYBOUWMANN - You are properbly right :). I will.

13 Apr
4 months ago

fredemagi started a new conversation CKEditor/ClassicEditor Not Working On IPad

I experience errors when I use ClassicEditor on iPad

$(function(){
    
   ClassicEditor.create(document.querySelector('.textarea-reply'), 
   {
     toolbar: [ 'bold', 'italic', 'bulletedList', 'numberedList']
   } );


});

I works fine on computer and iPhone, but it does not get activated on iPad. iPad version is iPad 4th with iOS 10.

02 Apr
4 months ago

fredemagi left a reply on Yajra Datatable With Relationship

Now I got it working when doing like this:

$orders = Order::with('customer')
                       ->with('employee'); 
                       
        return Datatables::of($orders)
                          ->editColumn('customer', function($order)
                          {
                             return $order->customer;
                          })
                          ->editColumn('employee', function($order)
                          {
                             return $order->employee;
                          })
                          ->make(true);

Now another issue arises; The {data: 'customer', name: 'customer.name'} now only returns the whole customer object and not the nested part. Pretty weird.

01 Apr
4 months ago

fredemagi left a reply on Yajra Datatable With Relationship

So basically I want to perform Order::with(‘employee’)->with(‘customer’)->get() with datatable.

fredemagi started a new conversation Yajra Datatable With Relationship

I'm trying to facilitate databables from Yajra, but I'm not sure how to use it, and the official documentation is a bit odd in my opinion: https://yajrabox.com/docs/laravel-datatables/master/relationships

I have to two models, one being Order and one being User.

An order belongs to a user who is the customer and another who is employee. They are connected like this:

public function customer()
    {
        return $this->belongsTo(User::class, 'user_customer_id', 'id');
    }


public function employee()
    {
        return $this->belongsTo(User::class, 'user_employee_id', 'id');
    }

Where do I go from here? :/

24 Mar
4 months ago

fredemagi left a reply on How To Set Folder Permissions For Public Users' Folder?

@DEVMASTER - I do have access. I have also made the php artisan symlink command to create the link between public and storage. It is normal procedure to run the symlink command through every auto deployment or just one time?

fredemagi left a reply on Issues With Github When Deploying With Laravel Forge

@EJDELMONICO - I’ll give it a go. Thank you :-).

fredemagi left a reply on Issues With Github When Deploying With Laravel Forge

@EJDELMONICO - Should it be both on my local and on the server?

fredemagi started a new conversation Issues With Github When Deploying With Laravel Forge

When I make some local changes to let say a js file, I would run npm run dev on my local machine to recompile all js files into a single app.js, which is located in public. When I then push to git, Laravel Forge shows the error from git in the deployment process that some files would be overwritten by a merge (I guess it’s the old app.js on the server which is to be replaced by a new). When Laravel Forge deploys, it runs this: https://gist.github.com/BenSampo/aa5f72584df79f679a7e603ace517c14. This includes npm run prod. Should the app.js file on both my local machine and the server be added to the gitignore, or should the script somehow delete the old app.js before pulling from github?

fredemagi started a new conversation How To Set Folder Permissions For Public Users' Folder?

I'm making an app where people can sign up, edit their user's profile etc. When people I sign up, I make a new folder for their images like this:

Storage::disk('public')->makeDirectory('user-images/'.$external_id);

user-images is located in storage/app/public. A symbolic link connects the path with public/storage. However, when new users signs up, either the new folder is created, nor can they upload images. I think it has something to do with wrong persmissions.

I'm fairly new to Laravel Forge which I use along with Digitalocean. What do I do to allow this? Can I change something in the code, or do I have to set permissions somewhere?

22 Mar
5 months ago

fredemagi started a new conversation Laravel: Outsending Emails With Link From Application Contains Wrong Url (localhost) In Link

It's my first time uploading a Laravel application to the web. I facilitate Laravel Forge and Digital Ocean. I've made an app where users can register them selves. Upon successful registration, an email with an activation link is sent to the user. The problem arises when the user checks the email. The link contains a link to https://127.0.0.1/...

Internal links in the app works correctly. The link in the mail is made with route('example'), where example is the name of a route made in routes/web.php.

The env.file looks something like:

APP_URL=http://SOME_IP_ADDRESS. 

What do I do from here?

In addition, I sent mails to mailtrap. What should I change the mail_host variable to instead in order to send real emails? It looks like:

MAIL_HOST=smtp.mailtrap.io

In advance, thank you.

01 Mar
5 months ago

fredemagi left a reply on Encrypt Ids Before Returning Models As Json

@JSENGER - Yes, of course. I keep forgetting the simple stuff. Thank you!

fredemagi started a new conversation Encrypt Ids Before Returning Models As Json

Is it possible in Laravel to encrypt id's in a collection of models before returning it as json?

Below I'm returning products, but I want the ids' of all the products to be encrypted before returning as json. Is it possible?

$products = Product::all();

return $products->toJson();

fredemagi left a reply on Offline Basket

@JOHNBRAUN - Thanks, I'll give it a go :).

27 Feb
5 months ago

fredemagi started a new conversation Offline Basket

Is it possible to store session data if the user disconnects?

I’m making a website with a basket, but if user disconnects, I want the user’s saved items to be stored somehow so he doesnt have to add them again. How do I achive this?

13 Feb
6 months ago

fredemagi left a reply on Select Count And Group By.

@STAUDENMEIR - I couldn't figure it out using Eloquent, but I ended up with this:

$arr = Email::where('from', '!=', '[email protected]')
                       ->get()
                       ->groupBy('from');


        $emails = [];

        foreach ($arr as $key => $value) 
        {
            $number_of_unread = 0;
            $number_of_emails = 0;

            foreach ($value as $v) 
            {
                if($v->is_read == 0)
                {
                    $number_of_unread++;
                }

                $number_of_emails++;
            }

            $emails[$key] = [
                            'number_of_unread' => $number_of_unread, 
                            'number_of_emails' => $number_of_emails
                         ];
            
        }

        //Turn into collection.
        $emails = collect($emails);

fredemagi left a reply on Select Count And Group By.

Found a solution.

fredemagi started a new conversation Select Count And Group By.

My application has a table containing emails. Is has columns like from, receiver, is_read, etc.

I want to display in a table the email, number of new, unread messages (where is_read == 0), and total number of emails in a correspondence; that is where from == somemail or receiver == somemail.

How do I using Eloquent achive this? Right now I have:

$emails = Email::select('from')
                       ->get()
                       ->groupBy('from');

fredemagi left a reply on Return Back To A Specific Html Element.

@SAURABHD - Thank you. I figured out that there is a way to fetch the previous url with app('url')->previous().

I ended you with redirect()->to(app('url')->previous()."#somenumber");

Thank you for your help.

fredemagi started a new conversation Return Back To A Specific Html Element.

In a controller, I want to return back to a page using back(). This will take me to the top of the page. How do I jump to a specific html element with an id? The url should be something like www.mydomain.com/forum/category/thread#element.

In advance, thank you.

14 Dec
8 months ago

fredemagi left a reply on Head Tag Title, Blade, And Language

@REALRANDYALLEN - Thank you. It works :).

Merry christmas to all!

13 Dec
8 months ago

fredemagi started a new conversation Head Tag Title, Blade, And Language

I'm trying to change the tab title based on language like:

@section('title', '{{ trans('inventory.tab') }}')

However, it fails with: "syntax error, unexpected 'inventory' (T_STRING), expecting ',' or ')'".

Anyone else who experience this?

12 Dec
8 months ago

fredemagi left a reply on Access Env Variable Inside Js File

I think I have found the issue. I now tried to do a fresh installation of Laravel and put my js code inside the resources/js folder, and compiled it through the mix.js instead of combining, and it seems to be working.

My question is now what the best workflow is? As it is now I have to include every single js file in the html file like:

 <script type="text/javascript" src="{{ asset('js/file1.js') }}"></script>
 <script type="text/javascript" src="{{ asset('js/file2.js') }}"></script>

I want all my custom made js files to be compiled AND combined into 1, so that I only have to include 1. How should the webpack file look like?

11 Dec
8 months ago

fredemagi left a reply on Access Env Variable Inside Js File

@ERICKPATRICK - Still same issue. I have substituted console.log with alert, but it still complains about Uncaught ReferenceError. Have I done something wrong in the Webpack file? Or doesn't process.env work in a pure js file?

fredemagi left a reply on Access Env Variable Inside Js File

@ERICKPATRICK - Now I tried to move the file inside resources/js/test.js with the sample code:

$(function()
{
    console.log(process.env.MIX_MY_VAR);
});

I have tried to restart the watch command and manually run the dev command, but it still cannot seem to find the process object.

The project structure is a standard Laravel project folder structure. I normally place my js code inside the public folder, but in this case I tried to inside the resources. The js code is compiled(combined to a single fine, which happens to reside in public/js and linked to in the html body before end tag.

fredemagi left a reply on Access Env Variable Inside Js File

The js-file is pure jQuery code, starting the document with:

$(function()
{
});

It gets combined with other js-files to a single one. However, it cannot seem to find the process object, whihk I don't understand. Shouldn't it be global in js?

10 Dec
8 months ago

fredemagi left a reply on Access Env Variable Inside Js File

@ERICKPATRICK - Yes, I use the precoded webpack.mix.js that comes with Laravel and have restarted watch:

const mix = require('laravel-mix');

mix.sass('resources/sass/app.scss', 'public/css');

mix.combine(
    [
        'public/js/custom/test.js'
    ], 'public/js/app.js')

mix.browserSync('localhost:8000');

The test variable looks like:

MIX_MY_VAR=1234

And the sample js code:

var max_val = process.env.MIX_MY_VAR;
    console.log(max_val);

It fails with: "Uncaught ReferenceError: process is not defined".

fredemagi left a reply on Access Env Variable Inside Js File

@KVITHALANI - Hmm... it yields {{ env('MIX_MY_VAR') }} in the browser.

fredemagi left a reply on Access Env Variable Inside Js File

@KVITHALANI - I just tried what you suggested, but it yields "Uncaught SyntaxError: Unexpected identifier".

fredemagi started a new conversation Access Env Variable Inside Js File

I need to retrieve an env variable inside a js.file. I have prefixed it with MIX_, so that it looks like MIX_MY_VAR=1234. The js file is located public/js, and all js files are combined into a single one using mix.combine. I have tried using process.env, but the browser fails with "Uncaught ReferenceError: process is not defined". What do I do wrong?

15 Nov
9 months ago
13 Nov
9 months ago

fredemagi started a new conversation MySQL/Laravel - Get Number Of Records Created In A Month For The Past 5 Months

In MySQL, I have a table with data like (the table's name is Persons):

Id (int), Name (varchar), Created_at (timestamp), Updated_at (timestamp).

1         Percy            2018-08-09 00-00-00    2018-08-09 00-00-00
2         Josh             2018-09-02 00-00-00    2018-09-02 00-00-00
3         Anna             2018-09-15 00-00-00    2018-09-15 00-00-00
4         Chris            2018-11-02 00-00-00    2018-11-02 00-00-00

I need an SQL to get the number of records created for a month for the past 5 months (including this month). If the month has no record, a 0 should be returned. Expected returned data with the data in the columns above would be:

month        count
november      1
october       0
september     2
august        1
july          0

The months name are dynamic, meaning november is this months, october the last, etc. I need the data like this, as I'm going to use is in a bar chart, with the month as the x-axis, and the count as the y-axis.

I have tried:

SELECT COALESCE(MAX(EXTRACT(MONTH FROM created_at)), 0) AS Months, COUNT(*) AS Count
FROM persons
WHERE created_at BETWEEN CURDATE() AND CURDATE() - INTERVAL 5
GROUP BY EXTRACT(MONTH FROM created_at).

Could it be done easier with Eloquent?

In advance, thank you.

24 Sep
10 months ago

fredemagi started a new conversation SOLVED: Queued Event Listeners Using Redis Not Working

SOLVED: I forgot to start the worker with queue:work.

As the title says, I cannot get any queued event listeners using redis working. I use Windows 10, have installed redis server as part of my local environment, and the server runs.

The queue is a standard setup: 'redis' => [ 'driver' => 'redis', 'connection' => 'default', 'queue' => 'default', 'retry_after' => 90, ],

I dispatch the event like: if($recipient->email_notify == 1) { event(new NewPrivateMessage($recipient)); }

I try to write to the log just to test out, but I don't get anything: public function handle(NewPrivateMessage $event) { Log::info("Testing..."); }

What could I have done wrong?

In advance, thank you.

02 Sep
11 months ago

fredemagi left a reply on Blade Syntax Inside JQuery

Thanks, @Cronix. I ended up using your suggested solution.