NickCourage

NickCourage

Member Since 4 Months Ago

Experience Points
590
Total
Experience

4,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
0
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 1
590 XP
Sep
21
2 days ago
Activity icon

Replied to How Do I Dockerise This Cloned Laravel App?

@martinbean Interesting because where I work we have our docker folders outside of our app directories. For example, the laravel app would be in a directory named quickstart-intermediate and the docker setup would be in an adjacent directory called quickstart-intermediate-docker, and for the purpose of learning tried to recreate this.

Sep
20
3 days ago
Activity icon

Replied to How Do I Dockerise This Cloned Laravel App?

@martinbean could I include a move/copy command to transfer it to quickstart-intermediate-docker first?

Activity icon

Replied to How Do I Dockerise This Cloned Laravel App?

@martinbean Thanks for your reply - I've tried this and can't get it working. I have two directories, one called quickstart-intermediate the other called quickstart-intermediate-docker.

quickstart-intermediate-docker contains my docker-compose.yml file and Dockerfile and is where I called docker-compose up -d from where I also reference the volumes for the file and dirs of quickstart-intermediate. So I'm struggling to get it to reference the composer.json and composer.lock files in quickstart-intermediate from there and keep getting copy failed: forbidden path outside the build context

Activity icon

Started a new Conversation How Do I Dockerise This Cloned Laravel App?

I know this is more to with Docker than Laravel but this question is specific to Laravel as I need to run composer update to install the vendor dependencies of the quickstart-intermediate demo app provided by Laravel.

my docker-compose.yml file:

version: '3'

networks:
    laravel:

services:
    nginx:
        image: nginx:stable-alpine
        container_name: nginx
        ports:
            - "8088:80"
        volumes:
            - ../quickstart-intermediate:/var/www/html
            - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
        depends_on:
            - php
            - mysql
        
        networks:
            - laravel
    mysql:
        image: mysql:5.7.22
        container_name: mysql
        restart: unless-stopped
        tty: true
        ports:
            - "4306:3306"
        volumes:
            - ./mysql:/var/lib/mysql
        environment: 
            MYSQL_DATABASE: homestead
            MYSQL_USER: homestead
            MYSQL_PASSWORD: secret
            MYSQL_ROOT_PASSWORD: root

            SERVICE_TAGS: dev
            SERVICE_NAME: mysql
        networks: 
            - laravel
    
    php:
        build:
            context: .
            dockerfile: Dockerfile
        container_name: php
        volumes:
            - ../quickstart-intermediate:/var/www/html
        ports:
            - "9000:9000"
        networks:
            - laravel

my Dockerfile:

FROM php:7.2-fpm-alpine

RUN docker-php-ext-install pdo pdo_mysql

I can get it working by manually executing composer update in the project directory as I also have composer installed globally but don't know how I could do this with Docker alone. I've done plenty of searching and will continue to but can't find anything that answers this issue.

Jul
23
2 months ago
Activity icon

Replied to How Can I Use AJAX To Get A List Of Records In The View For A JQuery Array?

@jlrdw thank you - it didn't solve it for me but I don't think I would have cracked it without that point in the right direction. I got there with:

        url = "{{route('test')}}";

        $.ajax({
            url: url,
            type:'get',
            dataType:'json',
            success:function (data) {
                
                $.each(data, function (index, item) {
                
                    return dataTitle = item.map(function(item){ return item; });

                }) 

            }
        });

and was then able to access them based on the selection of a dropdown by accessing dataTitle.

Thanks!

Jul
21
2 months ago
Activity icon

Started a new Conversation How Can I Use AJAX To Get A List Of Records In The View For A JQuery Array?

I'm trying to populate a jQuery array with the values from a column of a table. I tried:

var dataTitle = {!! json_encode(array_column($dataTitles->toArray(), 'my_data_title')) !!}

I now want to use ajax to do this. I've created a route that references a function in the controller and returns the data in JSON:

    public function getDataTitles(){

        $dataTitles = DataTitle::all();

        return response()->json(['data' => $dataTitles]);


    }

I've create the route for it to use as the URL parameter and have tried:

url = "{{route('get-data-titles')}}";

$.ajax({
    url: url,
    type:'get',
    dataType:'json',
    success:function (response) {

        console.log(data)
    }
})     

but am getting nothing. I've spent some time trying to Google and search for similar examples I can use but so far haven't found anything

Jul
14
2 months ago
Activity icon

Replied to How Can I Implement These Models?

@martinbean fair enough - sorry. In the end I added fields to the pivot table. I knew it was a many to many relationship but just wasn't sure if that was something that was bad practice, etc.

Activity icon

Replied to How Can I Implement These Models?

@martinbean no thanks. Already looked

Activity icon

Replied to How Can I Implement These Models?

@tallaljamshed yes I did "searched". Why else would someone resort to posting on a forum?

Activity icon

Started a new Conversation How Can I Implement These Models?

I want to associate a company to a category and let the description for the category be editable. A company can have many categories, a category can belong to one company.

I have a company table, a category table and think I need a link table but can't get my head around how to make this so that the category_description can hold any value that the company chooses but also corresponds to a category from the category table.

Jun
06
3 months ago
Activity icon

Replied to How Can I Change A Database Value With A Checkbox Toggle Using Ajax?

@tykus your answer didn't really help solve it but I'll give it to you as choosing my own is like giving myself a High 5 in public. I'm also using what you suggested for $profile = auth()->user()->profile; and this has meant I can just remove a hidden input and get rid of the form element altogether.

Activity icon

Replied to How Can I Change A Database Value With A Checkbox Toggle Using Ajax?

In the end I found exactly what I was looking for with this like for like tutorial Laravel Update User Status Using Toggle Button Example I made it bespoke for what I needed and was able to add a flash style Bootstrap alert:

<script>
    $(function (){
        $('div.user-active .toggle').on('click', function (event) {

            var status = $('div.user-active .toggle input').prop('checked') == true ? 0 : 1; 
            
            $.ajax({
                type: "GET",
                dataType: "json",
                url: '{{route('user.profile.user-active')}}',
                data: {'is_active': status/*, 'user_id': user_id*/},
                success: function(data){
                    console.log(data.success);

                    var messages = $('.user-active-toggle-message');

                    var successHtml = 
                    '<div class="alert mb-0 mt-3 alert-success border rounded border-success">' + 
                        '<p class="mb-0"><i class="fas fa-check mr-2"></i>' + data.success  + '</p>' +
                    '</div>';

                    $(messages).html(successHtml).fadeIn().fadeOut(2500);

                }
            });


        });

    });
</script>
Jun
05
3 months ago
Activity icon

Replied to How Can I Change A Database Value With A Checkbox Toggle Using Ajax?

@tykus I've taken care of that by passing the profile id in through $request->profile_id. Adding data: { is_active: this.checked } hasn't changed anything

Activity icon

Replied to How Can I Change A Database Value With A Checkbox Toggle Using Ajax?

@tykus - thanks for your reply. No the form doesn't need to be submitted - only when the checkbox is toggled. It's using submit at the moment though for the non ajax version, etc. I will give this a go

Activity icon

Started a new Conversation How Can I Change A Database Value With A Checkbox Toggle Using Ajax?

I am trying to update the value of a boolean database field (is_active) in a blade template by toggling a checkbox input, in a form using Bootstrap 4 Toggle. This adds some additional elements which I can successfully reference using on('click').

I've got this working without ajax but am struggling to workout a solution with what I've got so far:

form.blade.php

<form action="{{route('user.profile.user-active')}}" method="POST" class="user-active">
    @csrf
    <input type="checkbox" name="is_active" value="1" @if(!Auth::user()->profile->is_active) checked @endif data-toggle="toggle" data-on="Yes" data-off="No">
    <input type="hidden" name="profile_id" value="{{Auth::user()->profile->id}}">
    <button type="submit">submit</button>
</form>

What form.blade.php looks like with Bootstrap 4 Toggle:

<form action="http://localhost:8000/user/profile/user-active" method="POST" class="user-active">
    <input type="hidden" name="_token" value="IjHbGDJlE3AXZZOjTstPL2x976DlhHXoK5TVeBOi">                
    <div class="toggle btn btn-light off" data-toggle="toggle" role="button" style="width: 61.5938px; height: 38px;">
        <input type="checkbox" name="is_active" value="1" checked="" data-toggle="toggle" data-on="Yes" data-off="No">
        <div class="toggle-group">
            <label for="" class="btn btn-primary toggle-on">Yes</label>
            <label for="" class="btn btn-light toggle-off">No</label>
            <span class="toggle-handle btn btn-light"></span>
        </div>
    </div>
    <input type="hidden" name="profile_id" value="1">
    <button type="" submit="">submit</button>
</form>

non ajax, working controller method - ProfileController.php

    public function changeUserActiveStatus(Request $request){

        $profile = Profile::findOrFail($request->profile_id);

        $profile->is_active = $request->is_active == 1 ? 0 : 1;

        $profile->save();

        return redirect()->back();
    }

jQuery:

<script>
        $(function (){
            $('form.user-active .toggle').on('click', function (event) {

                $.ajax({
                type: 'POST',
                url: "{{route('user.profile.user-active')}}",
               
            });

            });
        });	
</script>

I realise that the jQuery is not complete and I'm kind of at the limit of my skills in this area although I'm researching, googling my way through, looking at comparable examples that solve this problem etc but not getting very far at the moment.

May
26
3 months ago
Activity icon

Replied to Can Someone Recommend Some Tutorials Or Resources For This?

@bugsysha @martinbean Thank you both for your replies - That's given me a better insight than before I asked! @martinbean that would explain why I've not been able to find much and it's obvious that I need spend some more time studying it. Thank you although I'm still unsure about how you would make these private but then accessible to particular users...

Activity icon

Replied to How Should I Structure The Relationships For Companies And Users?

@michaloravec I guess was thinking too much in a purist kind of way...It's what stopped me from doing what you've suggested i.e. having the company_id in the user's table as there would be lots of users that wouldn't have a company but I can't see any other way to do it. Thank you for your help

Activity icon

Started a new Conversation Can Someone Recommend Some Tutorials Or Resources For This?

Hi - I'm fairly new to Laravel and AWS but am trying to get started on user file uploads on to AWS S3. Of course I've looked about already but can't seem to find anything specific to individual users uploading documents/files to my AWS S3 bucket. For example, if I wanted a user to upload a word document, how could you do that from a Laravel app to a bucket in S3, make it private and associate to that user?

NB I know this is a broad question and would probably get down-voted on StackOverflow but all I'm asking for is a point in the right direction to some examples, tutorials, etc.

Activity icon

Replied to How Should I Structure The Relationships For Companies And Users?

Hi @michaloravec - thanks for your reply...Ok but for the user that will not have a company, I can have company_id null?

Activity icon

Replied to Elequent GroupBy Date And Order By Asc Inside The Date Group

You said "If I order them by created_at then the documents are displayed backwards" - what happens if you don't order them by created_at?

Activity icon

Started a new Conversation How Should I Structure The Relationships For Companies And Users?

Hi - I'm struggling to work out a solution for implementing these rules, although this may be more of an SQL, RDBMS question, its implementation will be in Laravel and I've come across polymorphic relationships for Eloquent in Laravel's documentation but am unsure of what to do next:

  • A user may only have a company or a profile
  • A user belongs to one company
  • A company can have many users
  • A user belongs to one profile
  • A profile has one user

Initially I thought, of putting the company_id in the user's table. However this would also result in a lot of NULL entries as not all users will belong to a company. Would this still be OK to do?

Similarly, not all users will have a profile (as they will instead, have a company) and this would look like a user having an entry for company_id but not for profile_id i.e. profile_id would be null where this is an entry for company_id and vice versa.

May
16
4 months ago
Activity icon

Replied to Why Are My Vendor/mail Views Being Ignored?

@michaloravec I guess you could say that...Still there was nothing to suggest that the custom provider wouldn't read from config/mail.php so I didn't know to include it. To me it seemed like a Laravel problem

Activity icon

Awarded Best Reply on Why Are My Vendor/mail Views Being Ignored?

@michaloravec @haz_ Thank you both for replying. It's taken nearly 6 hours, countless google searches and trawling Stack Overflow and LaraCasts and I've finally fixed the problem. I'm going to go into detail for anyone else that has this issue.

@michaloravec you were right about resource_path('view/vendor/mail') but I had already made sure of this in config/mail.php which then prompted to me search for "vendor publish laravel-mail not working" and I came across this (https://stackoverflow.com/questions/54844711/laravel-5-4-vendor-publish-component-not-working) that was identical to my problem. The solution was around 'paths' => [resource_path('views/vendor/mail)] but as I had already checked this, then started to think about where it's getting my configurations form, perhaps not config/mail.php?

As it turns out, I've used a custom ServiceProvider to set my SMTP configurations from an email_settings table that holds the values for these configurations (driver, host, port, etc) and it's reading all mail configurations from this ServiceProvider that doesn't declare resource_path('view/vendor/mail')

So I used:


class CustomConfigServiceProvider extends ServiceProvider
{

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        if ($email_settings = EmailSetting::first()) {

            $this->app['config']['mail'] = [
                'driver' => $email_settings->mail_driver,
                'host' => $email_settings->mail_host,
                'port' => $email_settings->mail_port,
                'from' => [
                    'address' => $email_settings->mail_from_email,
                    'name' => $email_settings->mail_from_name
                ],
                'recieve_to' => [
                    'address' => $email_settings->mail_from_email,
                    'name' => $email_settings->mail_from_name
                ],
                'encryption' => $email_settings->mail_encryption,
                'username' => $email_settings->mail_username,
                'password' => $email_settings->mail_password,
                'markdown' => [
                    'default' => 'markdown',
                    'paths' => [resource_path('views/vendor/mail')]
                ],
            ];

        }
    }

}

and all is now working :)

Activity icon

Replied to Why Are My Vendor/mail Views Being Ignored?

@michaloravec @haz_ Thank you both for replying. It's taken nearly 6 hours, countless google searches and trawling Stack Overflow and LaraCasts and I've finally fixed the problem. I'm going to go into detail for anyone else that has this issue.

@michaloravec you were right about resource_path('view/vendor/mail') but I had already made sure of this in config/mail.php which then prompted to me search for "vendor publish laravel-mail not working" and I came across this (https://stackoverflow.com/questions/54844711/laravel-5-4-vendor-publish-component-not-working) that was identical to my problem. The solution was around 'paths' => [resource_path('views/vendor/mail)] but as I had already checked this, then started to think about where it's getting my configurations form, perhaps not config/mail.php?

As it turns out, I've used a custom ServiceProvider to set my SMTP configurations from an email_settings table that holds the values for these configurations (driver, host, port, etc) and it's reading all mail configurations from this ServiceProvider that doesn't declare resource_path('view/vendor/mail')

So I used:


class CustomConfigServiceProvider extends ServiceProvider
{

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        if ($email_settings = EmailSetting::first()) {

            $this->app['config']['mail'] = [
                'driver' => $email_settings->mail_driver,
                'host' => $email_settings->mail_host,
                'port' => $email_settings->mail_port,
                'from' => [
                    'address' => $email_settings->mail_from_email,
                    'name' => $email_settings->mail_from_name
                ],
                'recieve_to' => [
                    'address' => $email_settings->mail_from_email,
                    'name' => $email_settings->mail_from_name
                ],
                'encryption' => $email_settings->mail_encryption,
                'username' => $email_settings->mail_username,
                'password' => $email_settings->mail_password,
                'markdown' => [
                    'default' => 'markdown',
                    'paths' => [resource_path('views/vendor/mail')]
                ],
            ];

        }
    }

}

and all is now working :)

Activity icon

Replied to Why Are My Vendor/mail Views Being Ignored?

@michaloravec As I have already stated - I have and that's why I'm asking this question.

Activity icon

Replied to Why Are My Vendor/mail Views Being Ignored?

@michaloravec What should be in resources/views/vendor/mail? I am sending using SMTP to my gmail account.

Activity icon

Replied to Why Are My Vendor/mail Views Being Ignored?

So if I edit email.blade.php in my localized resources/views/vendor/notifications directory that works. However this uses mail::message and other mail::components and it's these that I'm trying to edit. Seemingly, these are what are using the defaults even though I've run php artisan vendor:publish --tag=laravel-mail and edited them in the copied views.

Activity icon

Replied to Why Are My Vendor/mail Views Being Ignored?

@haz_ I've tried what you suggested before I came on here - that's how I knew it wasn't working. There's also no header.blade.php in mail/html/themes just the default css file but I get what you're pointing at which is what I've already done.

Activity icon

Replied to Why Are My Vendor/mail Views Being Ignored?

@michaloravec I've checked and it's already there. I even renamed the vendor folder (I changed it back, just to test, etc) and placed that in the resource_path() but it made no difference.

May
15
4 months ago
Activity icon

Replied to Why Are My Vendor/mail Views Being Ignored?

Believe me I've looked. Seemingly it's saying to do what I've already mentioned i.e. php artisan vendor:publish --tag=laravel-mail, etc.

I'm sending the emails via SMTP to my gmail account.

Activity icon

Started a new Conversation Why Are My Vendor/mail Views Being Ignored?

I've tried to customize the default email templates that Laravel ships with, have used "vendor:publish" to copy the default mail resource/views to my app but these are being ignored.

Annoyingly (and purely for testing purposes) I have edited the default views just to see what's what and it's clear to me that the mail views I've created using vendor:publish are being ignored as the default views reflect the changes whereas the views created from vendor publish don't.

Any ideas on why Laravel would choose these over the ones I've made from vendor:publish instead?