fredemagi

fredemagi

Member Since 1 Year Ago

Experience Points 1,360
Experience Level 1

3,640 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 Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

14 May
1 month 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
1 month 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
1 month ago
29 Apr
1 month 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
2 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
2 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
2 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
2 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
2 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
3 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
3 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
3 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
3 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
4 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
6 months ago

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

@REALRANDYALLEN - Thank you. It works :).

Merry christmas to all!

13 Dec
6 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
6 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, and compiled it through the mix.js instead of combine, 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
6 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, whick I don't understand. Shouldn't it be global?

10 Dec
6 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:

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
7 months ago
13 Nov
7 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 easylier with Eloquent?

In advance, thank you.

24 Sep
9 months ago

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

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.

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
9 months ago

fredemagi left a reply on Blade Syntax Inside JQuery

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

fredemagi started a new conversation Blade Syntax Inside JQuery

I'm facing difficulities trying to use blade syntax inside jQuery. I want to use {{ route('NAME') }}

inside a jQuery statement like:

$list.append("<a href='{{ route('NAME', param1, param2) }}'>link_name</a>");

but I'm not sure of the syntax.

Any help is appreciated.

In advance, thank you.

30 Aug
9 months ago

fredemagi left a reply on Combining Intervention Image With Storage::put, Yielding An Error On Windows 10.

@newbie360, thanks. That did the job.

In addition to this, if I want to facilitate Storage::putFile() instead, because it creates the unique filename for me, what should I place as 2 parameter? I have tried with both

Storage::putFile('photos', $file);

and

Storage::putFile('photos', new File($file));

but I'm not sure how to solve it. Maybe give tmp-path from $file as parameter?

fredemagi left a reply on Combining Intervention Image With Storage::put, Yielding An Error On Windows 10.

Unfortunately, it did not work with Storage::put($path, (string) $file->encode());

Still yields error with permission.

fredemagi left a reply on Combining Intervention Image With Storage::put, Yielding An Error On Windows 10.

I shall try the suggested Storage-method when I get home later.

I have already tried the save-method, but the problem is that it fails with “(...) cannot write to the path...) when I have multiple files, so I thought I could avoid this error by facilitating the Storage-method.

fredemagi started a new conversation Combining Intervention Image With Storage::put, Yielding An Error On Windows 10.

I'm coding a file upload for images in which I want to manipulate the image before uploading. However, when I combine Intervention Image's stream() with Laravel's built in Storage::put(), I keep facing the same error with: "file_put_contents(PATH): failed to open stream: Permission denied".

My code is like:

 $path = 'public/SOMENAME';

        $file = Image::make($image)
                        ->orientate()
                        ->resize(800, null, function ($constraint) 
                            {
                                $constraint->aspectRatio();
                                $constraint->upsize();
                            }); 


        Storage::put($path, $file);        

I have tried to change permission on both storage/, storage/SOMETHING and xampp's tmp-folder to 777 for all users and groups, but nothing seems to work. If I only use Storage::put() directly on the file, I face no issues. What could be wrong?

I use Windows 10 64bit and run the server with npm run watch.

Thank you in advance.

30 May
1 year ago

fredemagi started a new conversation Advanced Search, Based On Filters, Pagination, And Preservation Of Old Input

I'm working on a search function on a website where users can search for other users based on filters like genders, areas, etc. I face several difficulties when coding:

  • I cannot seem to figure out how to combine pagination with the collection, I get back. I make us of https://github.com/spatie/laravel-paginateroute for pagination. The problem is that when I go to page 2, I'm shown the result from page 1 and so on. I have tried out different solutions like: Query for all users in a post method based on the filters, ending with ->paginate(NUMBER). Then Session::put('users') in order to be able to retrieve it from a get method so I can return a view with the collection. I've also tried to pass the request object from the post to the get method, but with no result.

  • I cannot figure out how to preserve old data for the form when visiting page 2, page 3, etc.

Atm, the code looks like:

POST METHOD:

$users = User::select();

    //Add gender.
    if($request->has('genders'))
    {
        $users->whereIn('gender_id', $request->genders);
    }

    //Get matching users.   
    $users = $users->Paginate(self::paginate);    

 
    //Flash collection to session.
    Session::put('users', $users);

    return Redirect::route('match.show')->withInput();

GET METHOD:

$users = null;

    if(Session::has('users'))
    {
        $users = Session::get('users');
    }

    else
    {

        $users = User::Paginate(self::paginate);
    }

    return View("find-match.show", compact("users"));

Regards, Frederik