SunnyBoy

SunnyBoy

Business Analyst at Ideosis Technologies Inc.

Member Since 2 Years Ago

Calgary

Experience Points
20,460
Total
Experience

4,540 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
185
Lessons
Completed
Best Reply Awards
0
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.

Level 5
20,460 XP
Sep
23
4 days ago
Activity icon

Replied to Adldap2-Laravel With Windows Active Directory

It's all in there what one would need, I have to look into my archive and probably upload it to github or something if you still looking.

Aug
17
1 month ago
Activity icon

Replied to How To Covert Date And Time Using Carbon Date Format?

@snapey my bad found the issue! It was the model name! Grrrr!

Activity icon

Replied to How To Covert Date And Time Using Carbon Date Format?

@snapey But for some reason its not able to store the record getting following error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'start_date_time' in 'field list' (SQL: insert into `campaigns` (`user_id`, `title`, `description`, `start_date_time`, `finish_date_time`, `venue`, `organizer`, `email`, `phone`, `image`, `updated_at`, `created_at`) values (2, Sea Surfing, <p>Test</p>, 2020-09-05 16:05:00, 2020-11-07 16:05:00, Chicago, IL, SunnyBoy, [email protected], 5879669661, 1597702955.jpeg, 2020-08-17 22:22:35, 2020-08-17 22:22:35))

EventsController

    public function store(EventRequest $request)
    {
        $event                   = new Campaign;
        $event->user_id          = auth()->id();
        $event->title            = $request->title;
        $event->description      = $request->description;
        $event->start_date_time  = Carbon::parse($request->start_date_time)->format('Y-m-d H:i:s');
        $event->finish_date_time = Carbon::parse($request->finish_date_time)->format('Y-m-d H:i:s');
        $event->venue            = $request->venue;
        $event->organizer        = $request->organizer;
        $event->email            = $request->email;
        $event->phone            = $request->phone;

        if ($request->hasFile('image_file')) {
            $newImage = time() . '.' . $request->image_file->extension();
            $request->image_file->storeAs('images/events', $newImage);
            $event->image = $newImage;
        }
        $event->save();

        toast('Event created successfully!', 'success');

        return redirect()->route('events.index');
    }

Migration

Schema::create('events', function (Blueprint $table) {
    $table->id();
    $table->unsignedBigInteger('user_id');
    $table->string('image');
    $table->string('title');
    $table->text('description');
    $table->dateTime('start_date_time');
    $table->dateTime('finish_date_time');
    $table->string('venue');
    $table->string('organizer');
    $table->string('email');
    $table->string('phone');
    $table->timestamps();
});

Any idea??? Thanks!

Activity icon

Replied to How To Covert Date And Time Using Carbon Date Format?

Got it!

Carbon::parse($request->start_date_time)->format('Y-m-d H:i:s');

Any further suggestions???

Activity icon

Started a new Conversation How To Covert Date And Time Using Carbon Date Format?

How to convert something like "2020-09-04T16:58" to "2020-09-0416:58:00" using Carbon Date Format?

Aug
15
1 month ago
Activity icon

Replied to Select2 And Laravel Livewire

Did you find the solution??? i got something similar happening with Nice Select (https://hernansartorio.com/jquery-nice-select/).

Aug
14
1 month ago
Activity icon

Replied to Livewire With SweetAlert2

@apexleo i saw that too... thanks for sharing though!

Activity icon

Replied to Livewire With SweetAlert2

@snapey SWEET!!! It works like a charm! Thanks a bunch! 😍😍😍

Activity icon

Replied to Livewire With SweetAlert2

Yes, not sure where to even start... first day i started and tried to help someone share a link from Livewire docs itself and i got the msg "Account on Hold"... LOL 😂😂😂

After browsing for sometime all i could get to Messages -> New Message where it says Add User (And how would I know who to write, anyways msged Caleb but no response).

So pls let me know if there is some secret door??? Hahaha Also let the community know that there might be ppl like trying the same!!!!

THANKS!!!

Aug
13
1 month ago
Activity icon

Started a new Conversation Livewire With SweetAlert2

Hi, Has anyone got this working? I want to use Livewire but hate the fact that the forum seems not open for ALL. Or may be i could't find a way to post my issue at least... anyways coming back to the topic. I am using https://github.com/realrashid/sweet-alert package in my project now after implementing Livewire its a shame that i can't use it as easily as i though. or is there something that i am missing??? Please advice!

Aug
11
1 month ago
Activity icon

Replied to Eloquent ORM To Display The Most Liked Campaign

@geordiejackson this is new to me I didn't quite get how it would work without relationship... but again Laravel was doing its magic using withCount('likes'). I am getting the results! Thanks

Aug
10
1 month ago
Activity icon

Replied to Eloquent ORM To Display The Most Liked Campaign

Well i am looking for a list of campaigns in desc order based on the popularity (most liked first and least at the end).

Activity icon

Started a new Conversation Eloquent ORM To Display The Most Liked Campaign

What would be the optimized way of writing an eloquent orm query to display a list of all active Campaigns in desc order based on the popularity (most liked first and least at the end).

Campaigns Table Schema

Schema::create('campaigns', function (Blueprint $table) {
    $table->id();
    $table->string('image')->nullable();
    $table->string('title');
    $table->unsignedBigInteger('category_id');
    $table->enum('status', ['active', 'pending', 'inactive'])->default('pending');
    $table->unsignedBigInteger('user_id');
    $table->timestamps();
});

Likes Table Schema

Schema::create('likes', function (Blueprint $table) {
    $table->id();
    $table->unsignedBigInteger('user_id');
    $table->unsignedBigInteger('campaign_id');
    $table->boolean('status');
    $table->timestamps();
});

Looking for an optimized solution below is my imperfect sql query!!! 😆😆😆 Thanks!

SELECT campaigns.*, COUNT(*) 
FROM campaigns 
INNER JOIN likes 
ON campaigns.id = likes.campaign_id 
GROUP BY campaigns.id
ORDER BY 2 ASC;
Aug
01
1 month ago
Activity icon

Awarded Best Reply on Upload An Image Using Drag & Drop Over A Placeholder Image.

@kkhicher1 thanks again for the prompt response, but what you are suggesting regarding the base64 is equivalent to what i already did using event.target.result

$('#file_preview').attr('src', e.target.result); 

Anyways... what i "was" seeking was how to set our input's 'files' property on drop event which i have figured out.

Here is the missing piece of the puzzle:

$('.upload-area').on('drop', function (e) {
    e.stopPropagation();
    e.preventDefault();
    $(this).removeClass("dragover");

    var files = e.originalEvent.dataTransfer.files;

    if (files && files.length) {

        // we set our input's 'files' property
        $('#file')[0].files = files;

    }

    readFile(files[0]);

});

THANKS ALL

Activity icon

Replied to Upload An Image Using Drag & Drop Over A Placeholder Image.

@kkhicher1 thanks again for the prompt response, but what you are suggesting regarding the base64 is equivalent to what i already did using event.target.result

$('#file_preview').attr('src', e.target.result); 

Anyways... what i "was" seeking was how to set our input's 'files' property on drop event which i have figured out.

Here is the missing piece of the puzzle:

$('.upload-area').on('drop', function (e) {
    e.stopPropagation();
    e.preventDefault();
    $(this).removeClass("dragover");

    var files = e.originalEvent.dataTransfer.files;

    if (files && files.length) {

        // we set our input's 'files' property
        $('#file')[0].files = files;

    }

    readFile(files[0]);

});

THANKS ALL

Jul
31
1 month ago
Activity icon

Replied to Upload An Image Using Drag & Drop Over A Placeholder Image.

Thanks @kkhicher1, this is all good only if i get the file in my request then into the controller. Bigger issue is I am not able to get the file itself.

Inside Controller i'm getting false when the upload is done using drag and drop. While this returns tru when i use select. So the issue is on drag and drop the input field "image_file" is is not getting set. <input type="file" name="image_file" id="file" accept="image/*"> OR is it something that i 'm missing???

dd(request()->hasFile('image_file'));
Activity icon

Started a new Conversation Upload An Image Using Drag & Drop Over A Placeholder Image.

I have been tying to work it out since last couple of days... and finally hope i would get some answers from the lavarel community.

While working my Laravel project where I am trying to upload an image (single image) using either drag & drop or select.

NOTE: I have a placeholder image which i want to use it as a dropzone, and also the size may vary depending on where i want to use. Now I should be able to drop an image on this placeholder image. On drop or select the new image replaces the placeholder image (this part i am able to achieve) but when i am trying to submit the form if I have drop a file it won't get to the controller. But when i select the file i am good.

Here is what i have done so far... Can any one let me know what is wrong with the drag & drop method for submitting... the only issue i can think of is the <input type="file"> is not able to set the value when when file is dropped.

Here is my blade form

<form class="form" action="{{ route('categories.store') }}" method="post" enctype="multipart/form-data">
                    @csrf
                    <div class="form-group row">
                        <label for="category" class="col-sm-4 col-form-label">Category</label>
                        <div class="col-sm-8">
                            <input id="category" type="text" class="form-control @error('category') is-invalid @enderror" name="category" value="{{ old('category') }}">
                            @error('category')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="slug" class="col-sm-4 col-form-label">Slug</label>
                        <div class="col-sm-8">
                            <input id="slug" type="text" class="form-control @error('slug') is-invalid @enderror" name="slug" value="{{ old('slug') }}">
                            @error('slug')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="order" class="col-sm-4 col-form-label">Display Order</label>
                        <div class="col-sm-8">
                            <input id="order" type="number" class="form-control" name="order" value="{{ old('order') }}">
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="status" class="col-sm-4 col-form-label">Status</label>
                        <div class="col-sm-8">
                            <select id="status" class="form-control form__select" name="status">
                                <option value="1">Active</option>
                                <option value="0">Inactive</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="file" class="col-sm-4 col-form-label">Upload Image</label>
                        <div class="col-sm-8">
                            <div class="upload-area" id="uploadfile">
                                {{-- <h1>Drag and Drop file here<br/>Or<br/>Click to select file</h1> --}}
                                <img class="img-fluid" src="{{ asset('img/640x480.png') }}" height="200px" id="file_preview" alt="img" />
                            </div>
                            <input type="file" name="file" id="file">
                            @error('file')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-sm-12">
                            <button type="submit" class="form__submit">Save</button>
                        </div>
                    </div>
                </form>

style.css

.upload-area{
    width: 42%;
    border: 2px solid lightgray;
    border-radius: 3px;
    text-align: left;
    overflow: auto;
}

.upload-area:hover{
    cursor: pointer;
}

.upload-area h1{
    text-align: center;
    font-weight: normal;
    font-family: sans-serif;
    line-height: 50px;
    color: darkslategray;
}

#file{
    opacity: 0;
}

and finally my JavaScript

 // On File Drop
        $('.upload-area').on('drop', function (e) {
            e.stopPropagation();
            e.preventDefault();
            $(this).removeClass("dragover");
   
            var file = e.originalEvent.dataTransfer.files[0];
            readFile(file);

            var fd = new FormData();
            fd.append('file', file[0]);
            // uploadData(fd);
        });

        // Open file selector on div click
        $("#uploadfile").click(function () {
            $("#file").click();
        });

        // file selected
        $("#file").change(function () {
            var file = $('#file')[0].files[0];
            readFile(file);
        });


    function readFile(file) {

        var reader = new FileReader();
        reader.onload = function (e) {
            $('#file_preview').attr('src', e.target.result);
        };
        reader.readAsDataURL(file);
    }
Jul
20
2 months ago
Activity icon

Replied to How To Validate Slug On Update

I got the same issue, here is my categories table

Schema::create('categories', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('slug')->unique();
            $table->unsignedInteger('order')->nullable();
            $table->boolean('status')->default(1);
            $table->string('image')->nullable();
            $table->timestamps();
        });

Below are the 2 ways i tried to sort this issue:

public function rules()
    {
        return [
            'category' => [
                'required','min:3','max:255'
            ],
            'slug' => [
                'required', 'min:3', 'max:255', 'unique:categories,slug'
            ],
            'fileName' => [
                'sometimes', 'required', 'image', 'mimes:jpeg,png,bmp,gif,svg,webp', 'max:1024',
            ]
        ];
    }
public function rules()
    {
        return [
            'category' => [
                'required','min:3','max:255'
            ],
            'slug' => [
                'required', 'min:3', 'max:255', Rule::unique(categories,slug,except,id),
            ],
            'fileName' => [
                'sometimes', 'required', 'image', 'mimes:jpeg,png,bmp,gif,svg,webp', 'max:1024',
            ]
        ];
    }

But i keep getting the same error, please advise!!! 😖😩🥺

The slug has already been taken