finchy70

finchy70

Head of Systems at EPS

Member Since 2 Years Ago

Swansea

Experience Points
14,180
Total
Experience

820 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
101
Lessons
Completed
Best Reply Awards
1
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.

Level 3
14,180 XP
Oct
16
3 days ago
Activity icon

Replied to Laravel With Vue.js Components In Production On Forge/Digital Ocean

Thought I'd already tried this but I followed your advice and it's worked. Thanks.

Activity icon

Started a new Conversation Laravel With Vue.js Components In Production On Forge/Digital Ocean

I have put a web app into production on Forge but can't seem to disable vue dev tools.

I have tried the following in my app.js file

if (process.env['production']) {
    Vue.config.devtools = false;
    Vue.config.debug = false;
    Vue.config.silent = true;
} else {
    Vue.config.devtools = true;
}

and

if (process.env.MIX_APP_ENV === 'production') {
    Vue.config.devtools = false;
    Vue.config.debug = false;
    Vue.config.silent = true;
} else {
    Vue.config.devtools = true;
    Vue.config.debug = true;
    Vue.config.silent =false;
}

and also just

Vue.config.devtools = false;
Vue.config.debug = false;
Vue.config.silent = true;

I also added MIX_NODE_ENV = production to my .env file in forge.

Am I missing something? Do I need to change the forge deployment script?

Im using Laravel 6.2 and vue.js 2.6.10.

Please help!!

Regards Paul.

Oct
15
4 days ago
Activity icon

Replied to Close A Vue Modal After Form Submission

Fixed it. Adding $('#addFlashModal').modal('hide'); did the trick.

Activity icon

Started a new Conversation Close A Vue Modal After Form Submission

I have a small modal to add some data to a table. When the data is successfully submitted I want to close the modal.

<template>
    <div>
        <div class="modal fade" tabindex="-1" id="addFlashModal" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <form @submit.prevent="submitForm()">
                        <div class="modal-header">
                            <h5 class="text-uppercase">Add New Ticker Message</h5>
                            <br>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                        <div class="modal-body p-3">
                            <div class="form-group">
                                <input type="text" class="form-control" placeholder="New Ticker Message" v-model="newMessage">
                            </div>

                            <button class="button-top btn btn-bold btn-block btn-primary" type="submitForm()">
                                Save
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        name: "addFlash",
        data() {
            return {
                newMessage: "",
                errors: [],
            }
        },
        methods: {
            submitForm() {
                axios.post('/api/new-ticker-message', {
                    message: this.newMessage
                }).then(resp => {
                    /** Code here to close modal*/
                }).catch(error => {
                    this.errors = error.response.data.errors
                    console.log("Errors= " + this.errors)
                })
            }
        }

    }
</script>

<style scoped>
    .modal {
        color: black;
        max-width: 100% !important;
    }
</style>

I have used location.reload() but this refreshes the page.

I also tried this.$emit('hide', true); and added a v-if to the component. This does close the modal bu the background remains faded and un selectable.

Thanks Paul.

Oct
12
1 week ago
Activity icon

Started a new Conversation Bootstrap 4 Layout

How do I get from Imgur

to

Imgur

Here is my current vue template. The final template will use a v-for to output the multiple messages

<template>
    <div class="row">
        <div class="col-lg-6 mt-3 mt-lg-3 mt-md-3 mt-sm-3">
            <div class="card">
                <div class="card-header">
                    Message
                </div>
                <div class="card-body">
                    <h5>Hello</h5>
                </div>
            </div>
        </div>
        <div class="col-lg-6 mt-3 mt-lg-3 mt-md-3 mt-sm-3">
            <div class="card">
                <div class="card-header">
                    Message
                </div>
                <div class="card-body">
                    <h5>Hello</h5>

                </div>
            </div>
        </div>
        <div class="col-lg-6 mt-3 mt-lg-3 mt-md-3 mt-sm-3">
            <div class="card">
                <div class="card-header">
                    Message
                </div>
                <div class="card-body">
                    <h5>Hello</h5>
                </div>
            </div>
        </div>
        <div class="col-lg-6 mt-3 mt-lg-3 mt-md-3 mt-sm-3">
            <div class="card">
                <div class="card-header">
                    Message
                </div>
                <div class="card-body">
                    <h5>Hello</h5>
                </div>
            </div>
        </div>
    </div>

</template>

Can someone tel me how to get the desired output if possible and keep the current single stacked column that a small screen displays.

Taken from development site. Imgur

Regards Paul

Jul
16
3 months ago
Activity icon

Replied to Vue Select: How Do I Mark An Option As Selected Dependant On Id?

I was approaching this problem from the wrong direction. Instead of trying to to use a ternary to set the :selected property, I set the 'selected' and 'current_method' immediately after retrieving the prelims. This was done by looping over the prelimdata objects and finding the matching id's.

for( let i = 0; i < this.prelimdata.length; i++){
    if(this.prelimdata[i].id === this.check.prelim_id){
        this.selected = this.prelimdata[i];
        this.current_prelim = this.prelimdata[i].prelims;
    }
}

Not sure if this is how you should do it, but it's the only way I could get it to work.

Thanks

Activity icon

Replied to Vue Select: How Do I Mark An Option As Selected Dependant On Id?

I've updated the line to

<option v-for="prelim in prelimdata" :value="prelim" :selected="prelim.id === id_check ? 'selected' : ''">{{ prelim.name}}</option>

It compiles but does nothing.

Jul
15
3 months ago
Activity icon

Started a new Conversation Vue Select: How Do I Mark An Option As Selected Dependant On Id?

I pass the current id of an object via props (id_check) and loop through an array of objects to populate a select dropdown. I cant pre select the object with the same id as the check_id.

<template>
    <div>

        <p v-if="errors.length">
            <b>Please correct the following error(s):</b>
            <ul>
                <li v-for="error in errors">{{ error }}</li>
            </ul>
        </p>
        <div class="card">
            <div class="card-header">
                <div class="row">
                    <h3 class="ml-3 mr-3 mt-1">Select Existing Preliminaries or </h3>
                    <a href="/prelims" class="float-right btn btn-sm btn-outline-dark mt-2 mb-2">Create New</a>
                </div>
            </div>
            <div class="card-body">
                <label class="mb-2">Name</label>
                <select class="form-control mb-5" v-model="selected" @change=getSelected>
                    <option disabled value="">Please select one</option>
                    <option v-for="prelim in this.prelimdata" :value="prelim"
                            :selected="(prelim.id === id_check)">{{ prelim.name }}</option>
                </select>

                <label class="mb-2">Preliminaries Description</label>
                <textarea class="form-control" rows="10">{{ current_prelim }}</textarea>

                <div class="row">
                    <button class="mt-2 ml-auto mr-3 btn btn-success -btn-sm" @click=savePrelim>Save</button>
                </div>

            </div>
        </div>
    </div>
</template>

<script>
    export default {
        name: "PrelimSelector",
        props: ['task_id', 'id_check'],
        data(){
            return {
                prelimdata: [],
                selected: null,
                errors: [],
                current_prelim: '',
                current_prelim_id: null,
            }

        },
        methods: {
            getSelected(){
                this.current_prelim = this.selected.prelims;
                this.current_prelim_id = this.selected.id;
            },

            getPrelims() {
                axios.get('/prelims/prelim_list')
                    .then((response) => {
                        // handle success
                        this.prelimdata = response.data;
                        // console.log("Prelims="+this.preliminaries);
                    })
                    .catch(e => {
                        if(e){
                            this.errors.push("Error!!");
                        }

                    });
            },

            savePrelim(){
                if(this.selected == null){
                    return;
                } else {
                    this.errors = [];
                    axios.patch('/tasks/'+this.task_id+'/add_prelims', {
                        add_prelim_id: this.current_prelim_id
                    })
                        .then((response)  => {
                            console.log("SUCCESS!!!!");
                            flash('Preliminaries added to current task!!');
                        })
                        .catch(e => {
                            if(e){
                                this.errors.push("A model with this name already exists!!");
                            }

                        });
                }
            }

        },

        created() {
            console.log("ID="+this.id_check);
            this.getPrelims();

        },
    }
</script>

<style scoped>

</style>

I have tried a few combinations of :selected="(prelim.id === id_check)" with no success. Can anyone show me how I do it?

Activity icon

Replied to Pass Query Result To Vue Component Via Axios To Populate A Dropdown.

That fixed it. Thank you very much.

Activity icon

Replied to Pass Query Result To Vue Component Via Axios To Populate A Dropdown.

***.test/prelims/prelim_list gives me the json containing my test data.

Activity icon

Replied to Pass Query Result To Vue Component Via Axios To Populate A Dropdown.

web.php

/**Axios Routes**/
Route::get('/prelims/prelim_list', '[email protected]_list')->name("prelims.prelim_list");
Activity icon

Replied to Pass Query Result To Vue Component Via Axios To Populate A Dropdown.

Same success response= [object Object]

Activity icon

Replied to Pass Query Result To Vue Component Via Axios To Populate A Dropdown.

Still error.

console.log("success response= "+ response.data);

gives success response= [object Object]

Activity icon

Started a new Conversation Pass Query Result To Vue Component Via Axios To Populate A Dropdown.

I have started building a Vue component that will populate a dropdown then depending on whats selected populate a text area.

Select box in template.

<div class="card-body">

                <select class="form-control" v-model="selected" @change=getSelected>
                    <option disabled value="">Please select one</option>
                    <option v-for="prelim in this.preliminaries" v-bind:value="prelim.id">{{ prelim.name }}</option>
                </select>

            </div>

function to populate dropdown

<script>
    export default {
        name: "PrelimSelector",
        data(){
            return {
                preliminaries: [],
                selected: null,
                errors: []
            }
        },

        methods: {
            getSelected(){

            }

        },
        created() {
            function getPrelims() {
                axios.get('/prelims/prelim_list')
                    .then((response) => {
                        // handle success
                        console.log("success response= ");
                        this.preliminaries = response.data;
                        console.log("Prelims="+this.preliminaries);
                    });
            }

            getPrelims();
        },

    }
</script>

controller

public function prelim_list()
    {
        return response()->json(Prelim::orderBy('name', 'asc')->get());
    }

I keep getting the following error.

Uncaught (in promise) TypeError: Cannot set property 'preliminaries' of undefined at app.js:1920

I have done something similar to this before with no problems. Any idea what I'm doing wrong?

Jun
04
4 months ago
Activity icon

Replied to NotFoundHttpException In PhpUnit Caused By Redirect()->route()

I think I have managed to find the problem. It was in fact the $this->get('/diary/'.$job->id) because $job->id is null as the Job object is not persisted.

Activity icon

Started a new Conversation NotFoundHttpException In PhpUnit Caused By Redirect()->route()

This simple test is failing.

/**
     * @test
     */
    public function it_can_create_a_job()
    {
        $client = create('App\Client');
        $job = make('App\Job', ['client_id' => $client->id]);
        $this->post('/jobs', $job->toArray())
            ->assertRedirect("/diary/1");

        $this->get('/diary/'.$job->id)
            ->assertSee($job->job_number)
            ->assertSee($client->name)
            ->assertSee($job->site);
    }

The error is Symfony\Component\HttpKernel\Exception\NotFoundHttpException:.

This seems to be caused by the redirect at the end of my controller code.

return redirect()->route('diary.show', $job->id);

Here is the route

Route::get('/diary/{id}', '[email protected]')->name('diary.show');

It all seems to work but this failing test is annoying me. Any one got any ideas what I am missing?

May
21
4 months ago
Activity icon

Started a new Conversation Group By And Count On Pivot Table.

I have an intermediate table match_player that holds a match_id and player_id. It's the belongsToMany relationship between Player and Match models. I want to get the player appearances which is a query that returns the player_id and the amount of times it occurs. I've tried this

$appearances = DB::select('match_player.player_id', DB::raw('count(match_player.match_id) match_id'))->groupBy('player_id')->get();

but i have an idea it's a bit easier than this.

This results in an error Argument 1 passed to Illuminate\Database\Connection::prepareBindings() must be of the type array, object given

Can anyone help?

May
09
5 months ago
Activity icon

Replied to Open Local Folder In Finder/explorer From Laravel Web App

I know but the directors don't want to upload and download the documents. They want to just be able to open them and then save them to the drive. I'll probably build a local app with python and wx widgets.

Activity icon

Started a new Conversation Open Local Folder In Finder/explorer From Laravel Web App

I need my Laravel app to open a specific folder on the local file system of my mac in finder. Is this possible? We have a locally stored directory which contains individual directories which contain job specific documentation. We want to keep these local and not upload them to the webserver. As everyone using this web app will be either on the office network or connected to it from home via vpn we like to be able to open the correct job directly in finder or windows explorer locally on the users machine. Every user has the directory mapped to their machine as the Z drive on windows. I use Go->Connect to server for my connection(macos). Windows set up is more important as only i use macos.

Feb
26
7 months ago
Activity icon

Replied to Phpunit Not Using Phpunit.xml Settings

@KEL_ - I’ve pointed phpstorm at the phpunit.xml file and that seems to have fixed the issue. Can’t explain exactly what I’ve done as I’m away from my Mac but it was in the edit configuration settings accessible from the testing drop down at the top of PHPStorm. I configured a directory for Feature and another for Unit. I do like running the test from inside PHPStorm as it is so convenient. Tried to click the best answer button for you but it keeps asking me to sign up and I already have a monthly membership.

Activity icon

Started a new Conversation Phpunit Not Using Phpunit.xml Settings

My phpunit.xml

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="vendor/autoload.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false">
    <testsuites>
        <testsuite name="Unit">
            <directory suffix="Test.php">./tests/Unit</directory>
        </testsuite>

        <testsuite name="Feature">
            <directory suffix="Test.php">./tests/Feature</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
        </whitelist>
    </filter>
    <php>
        <env name="APP_ENV" value="testing"/>
        <env name="BCRYPT_ROUNDS" value="4"/>
        <env name="CACHE_DRIVER" value="array"/>
        <env name="SESSION_DRIVER" value="array"/>
        <env name="QUEUE_CONNECTION" value="sync"/>
        <env name="MAIL_DRIVER" value="array"/>
        <env name="DB_CONNECTION" value="sqlite"/>
        <env name="DB_DATABASE" value=":memory:"/>
    </php>
</phpunit>

When I run my tests with PHPStorm I get this error.

Testing started at 16:13 ...
/usr/local/Cellar/php/7.2.9_2/bin/php /Users/paulfinch/code/site/vendor/phpunit/phpunit/phpunit --no-configuration /Users/paulfinch/code/site/tests/Feature --teamcity
PHPUnit 7.5.4 by Sebastian Bergmann and contributors.


Illuminate\Database\QueryException : SQLSTATE[HY000] [1049] Unknown database 'site' (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')
 /Users/paulfinch/code/site/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
 /Users/paulfinch/code/site/vendor/laravel/framework/src/Illuminate/Database/Connection.php:624
 /Users/paulfinch/code/site/vendor/laravel/framework/src/Illuminate/Database/Connection.php:333
 /Users/paulfinch/code/site/vendor/laravel/framework/src/Illuminate/Database/Schema/MySqlBuilder.php:99
............

Was working fine so not sure whats happened.

Anyone having a simular problem?

Feb
18
8 months ago
Activity icon

Replied to [Vue Warn]: Cannot Find Element: #app

Moving the @include(partials.scripts) out of the div with id="app" did the job.

<body>
        <div id="app">
            <main class="container">
                @include('partials.nav')
                @include('partials.messages')
                @include('partials.banner')
                @yield('content')
                @include ('partials.footer')
            </main>
        </div>
        @include('partials.scripts')
    </body>
Activity icon

Started a new Conversation [Vue Warn]: Cannot Find Element: #app

Every page I visit gives this error.

My layouts.app looks like this

<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>{{ config('app.name', 'Laravel') }}</title>

    <!-- Scripts -->
    <script src="{{ asset('js/app.js') }}"></script>

    <!-- Fonts -->
    <link rel="dns-prefetch" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css?family=Raleway:300,400,600" rel="stylesheet" type="text/css">

    <!-- Styles -->
    <link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>
<body>
    <main class="container">
        @include('partials.nav')
        @include('partials.messages')
        @include('partials.banner')
        @yield('content')
        @include ('partials.footer')
        @include('partials.scripts')
    </main>
</body>
</html>

The only view with a Vue.js componenet is this one.

@extends('layouts.app')
@section('content')
    <div class="row justify-content-center">
        <strong><h4>Create a New Vehicle</h4></strong>
    </div>
    <div id="app">
        <model :makes="{{ $makes }}"></model>
    </div>

@stop

This does not show the vue content. I have tried moving the div with the id="app" tag back to the layouts.app file but same problem.

Feb
14
8 months ago
Activity icon

Replied to Passing Variables To A HTML Mail Template And Displaying Them

I fixed the issue by creating an array containing only the questions.

$q_a = $vehicle_check->questions_answers;
            $questions = [];
            foreach($q_a as $q)
            {
                $questions[] = $q->question;
            }
Activity icon

Started a new Conversation Passing Variables To A HTML Mail Template And Displaying Them

I use the following code to build an email in html. The variables have been passed to the view.

<div>
    <div class="row">
        <h2>
            Vehicle {{ $vehicle->reg }} has failed a vehicle check on {{today()->format('d-m-Y')}}.
        </h2>

    </div>
    <div class="row">
        <h2>
            <span style="color: red">{{Auth::user()->name}}</span> did not tick pass for the following questions.
        </h2>

    </div>

    <hr>
    @foreach($fault_check as $fault)
        <div class="row">
            <h3>{{ $questions[$fault-1]->question }}</h3>
        </div>
    @endforeach

    <hr>
    <h2>Notes Captured</h2>
    <p>{{$notes}}</p>
    <hr>

    Regards,<br>

    <h4>Web Master</h4>
    <h4>EPSConstruction Ltd</h4>
</div>

When the email arrives it looks like this.

Click to see Email

When I use this route to view the email all looks fine.

Route::get('mailable', function () {
    $questions = VehicleQuestion::all();
    $vehicle = App\Vehicle::find(1);
    $faults = [1,5,7,8,9];
    $notes = "It's broken!!!";

    return new App\Mail\FaultsReported($vehicle, $faults, $questions, $notes);
});

Any advice please?

Feb
11
8 months ago
Activity icon

Replied to Capturing Checkboxes With An Array.

@click when using radio buttons they all share the answer[] name so only one button can be checked on the whole form.

Activity icon

Started a new Conversation Capturing Checkboxes With An Array.

I have a form that contains a loop that displays a question and checkbox.

<form action="/vehicle_checks/{{$vehicle->id}}" method="POST" class="form-control">
            @csrf
            <label name="mileage" for="mileage">Please record the vehicle mileage.</label>
            <input type="number" name="mileage" class="form-control mb-2" required>

            @foreach($questions as $question)
                <div class="row">
                    <div class="col-8"><label for="answer[]" class="ml-2">{{$question->question}}</label></div>
                    <div class="col-4">
                        <div class="form_check form-check-inline">
                            <input class="mr-2" type="checkbox" name="answer[]" checked>Yes
                        </div>
                    </div>
                </div>
                <hr>
            @endforeach
            <label name="notes" for="notes"><strong>Record any notes if applicable.</strong></label>
            <textarea rows="5" class="form-control" name="notes"></textarea>
            <div class="row">
                <a href="/vehicle_checks/{{$vehicle->id}}" class="ml-auto btn btn-danger mt-3 mr-2">Cancel</a>
                <button type="submit" class="btn btn-success mt-3 mr-3">Save</button>
            </div>
        </form>
            

I an using answer[] to capture the status of the checkboxes but they only add to the array when set to "on" status. I need every value in the array with its on / off status so I can save the answer against the specific question. For example if someone saved the form without checking any checkbox, the answer array would contain 14 values of "off" (as that is currently the amount of questions), or if they just check question 3 then answer[2] would be set to "on";

Is there a way to do this?

Feb
06
8 months ago
Activity icon

Replied to Htmlspecialchars Error

@cronix. Yeah sorry. Didn't mean to delete the post.

Activity icon

Started a new Conversation Htmlspecialchars Error

I deleted my original post in error after I quickly solved my problem.

My issue was a htmlspecialchars error when passing data to this vue component

<template>
    <div>
        <div class="row">
            <div class="col-1">#</div>
            <div class="col-5">Question</div>
            <div class="col-2">Section</div>
            <div class="col-2">Type</div>
            <div class="col-2">Option</div>
        </div>
        <hr>
        <div v-for="question in questions">
            <div class="row">
                <div class="col-1">{{ question.id }}</div>
                <div class="col-5">{{ question.question }}</div>
                <div class="col-2">{{ question.section_id}}</div>
                <div class="col-2">{{ question.question_type.description}}</div>
                <div v-if="checkSelected(question.id)" class="col-2"><button @click="removeQuestion(question.id)" class="btn btn-warning btn-sm">Remove</button></div>
                <div v-else class="col-2"><button @click="addQuestion(question.id)" class="btn btn-success btn-sm">Add</button></div>
            </div>
            <hr>
        </div>
        <div class="row">
            <button class="btn btn-sm btn-info ml-auto mr-3" @click="saveQuestions()">Save Questions</button>
        </div>
    </div>

</template>

<script>
    export default {
        props: ["questions", "plant", "list"],

        data: function () {
            return {
                selected: [...this.list]
            }
        },

        mounted() {
            console.log(this.selected);
        },

        methods: {
            checkSelected: function (check) {
                var length = this.selected.length;
                for (var i = 0; i < length; i++) {
                    if (this.selected[i] === check) return true;
                }
                return false;
            },


            addQuestion: function (add) {
                this.selected.push(add)
                console.log("selected="+this.selected, "old="+this.list);
            },

            removeQuestion: function (remove) {
                var length = this.selected.length;
                for (var i = 0; i < length; i++) {
                    if (this.selected[i] === remove) this.selected.splice(i, 1);
                    console.log("selected="+this.selected, "old="+this.list);
                }
            },

            saveQuestions: function () {
                axios.post('/plant_types/questions', {

                    questions: this.selected,
                    plant: this.plant.id,
                    old: this.list
                })
                    .then(response => {
                        window.location.href = '/plant_types/' + this.plant.id;
                    })
                    .catch(e => {
                    })
            }
        }
    }
</script>

It turns out that I was passing a collection of objects as the questions prop. I then plucked the ids instead

$questions = Question::orderBy('section_id', 'asc')->pluck('id');

and passing this array fixed the issue

Sorry again but this should now give the post some value again.

Activity icon

Replied to Sending Session Message With Window.location.href

You are right. I over complicated the matter.

Session::flash('flash', 'Updated Successfully!!);

I'd used

Session::flash('success', 'Updated Successfully!!);

and got the Bootstrap messages.

Activity icon

Replied to Sending Session Message With Window.location.href

Not really explained this very well. I have built the Vue Flash message component in Episode 29 of Lets build a forum with Laravel.

I am redirecting from my component after the response from the back end. This ensures my data is updated before I display it. I want to redirect to '/plant_types/'+this.plant.id and then display a the success message. As I'm redirecting from the component I used

window.location.href = '/plant_types/'+this.plant.id;

If I try to redirect to the page from the laravel controler with no response the axios post fails with a 500 error.

Can I redirect from the vue component with the equivalent of the ->with('flash', 'Updated Questions!!') so my Vue flash component works.

Activity icon

Replied to Sending Session Message With Window.location.href

Yes but my component posts to laravel and on response redirects to window.location.href = '/plant_types/'+this.plant.id; to ensure the data has been updated.

Activity icon

Started a new Conversation Sending Session Message With Window.location.href

window.location.href = '/plant_types/'+this.plant.id; How would I set the session variable so the page '/plant_types/'+this.plant.id' displays a flash('message'). In laravel controller I would normally use

Session::flash('success', 'Questions successfully updated!!'); 
return view('plant_types.show');
Feb
04
8 months ago
Activity icon

Started a new Conversation Save Request $request To Different Records

I have a $request returned from a dynamically built form.

Request $request

As you can see it has 5 different prefixes. oil_sample, trip_and_close, operations, panel_damage, cb_timing. I need to save each set of records with the same prefix to a single record in my answers table. The prefixes will not always be the same and will not always be 5 in number.

answers table

As you can see record 5 corresponds to the $requests with cb_timing prefix.

These are then linked to the inspection and question via a questions_answers table.

questions_answers_table

Can this be done?

Activity icon

Replied to Custom @include Directive To Fetch Correct View

My IDE PHPStorm doesn't like it either.

IDE Syntax Error

Activity icon

Replied to Custom @include Directive To Fetch Correct View

Yes variable is type1, and view is question_types/type1.blade.php.

Activity icon

Replied to Custom @include Directive To Fetch Correct View

And this error

syntax error, unexpected '<' (View: C:\Users\Paul\code\TxTest\resources\views\reports\show.blade.php)
Activity icon

Replied to Custom @include Directive To Fetch Correct View

Tried this.

 @include('question_types.' . {{$part->question->question_type->name}})

Didn't work.

Activity icon

Started a new Conversation Custom @include Directive To Fetch Correct View

I want to fetch a specific view based on the following

@include('form_type.' {{$some->name}})

This wont work so tried a custom directive. Put this in my AppServiceProvider

 public function boot()
    {
       Blade::directive('formtype', function($expression) {
            return "<?php echo 'form_type.'{$expression}; ?>";
        });
    }

and this in my blade file

 @formtype({{$part->question->question_type->name}})

Still wont work. Is it possible to accomplish what I'm trying to do?

Jan
27
8 months ago
Activity icon

Replied to Laravel Is Still Displaying Old Welcome Screen

@D9705996 Never had to do that before. Thank you.

Jan
26
8 months ago
Activity icon

Started a new Conversation Laravel Is Still Displaying Old Welcome Screen

I have changed my welcome.blade.php file to extend layout.app and inserted some content. When I serve with php artisan serve Laravel keeps loading it's own standard welcome screen. I've done composer dump-autoload php artisan cache:clear, cleared my browser cache, and I've even restarted my PC. My route file is pointing '/' to view 'welcome'. I know I've done something simple wrong but I cant figure it out. HELP!!!!

Activity icon

Replied to Eloquent Polymorphic DB Relationships

I have decided this is not the correct approach and have tried implement a different design pattern which will remove the need for separate models for each type of report.

Jan
09
9 months ago
Activity icon

Replied to Eloquent Polymorphic DB Relationships

Played around a little and added a type field to the plant table.

$table->string('type');

The type would contain a reference to the plants report model.

$plant->type = "App\AuxTxReport";

This simple function on the plant model

public function reports()
{
    return $this->hasMany($this->type);
}

and on the reports models

public function plant()
{
    return $this->belongsTo('App\Plant');
}

Then accesses the correct table to retrieve reports.

Removes all the messy logic.

There may be a better way to do this!!

Activity icon

Replied to Eloquent Polymorphic DB Relationships

Was my plan to have one reports table but each plant type would require a different report with different fields. I have built this using multiple access relationships. One for transformer, one for Switchgear , and one for Generators.

public function generator_reports()
    {
        return $this->hasMany('App\GeneratorReport');
    }

public function aux_tx_reports()
    {
        return $this->hasMany('App\AuxTxReport');
    }

public function aux_tx_swg_reports()
    {
        return $this->hasMany('App\AuxTxSwitchgearReport');
    }

Logic such as

public function getCheckedByAttribute()
    {
        if($this->equipment_type_id === 1)
        {
            return $this->aux_tx_swg_reports()->orderBy('checked_at', 'desc')->first()->user->name;
        }
        elseif($this->equipment_type_id === 2)
        {
            return $this->aux_tx_reports()->orderBy('checked_at', 'desc')->first()->user->name;
        }   
        elseif($this->equipment_type_id === 4)
        {
            return $this->generator_reports()->orderBy('checked_at', 'desc')->first()->user->name;
        } 
        else
        {
            return null;
        }
    }

is used then to determine the relationship to use. All seems to messy and has a lot of repeated code.

Activity icon

Started a new Conversation Eloquent Polymorphic DB Relationships

I have a DB which has a Plant table. This contains items of plant. They can be Transformers, Switchgears, or Generators. I then have a table for Switchgear Reports, a table for Transformer Reports, and a table for Generator Reports. I want to set up a porlymorphic relationship that supports a single plant object having multiple reports. These reports would all be of the same type dependant on whether the item is a transformer, switchgear, or generator. I want to set up relationships that when I ask for reports on an item it goes and gets them without me having to write logic to check the plant type then query the specific reports table. This would also mean adding new plant types and reports for that type would be a lot easier. I have tried to set up the polymorphic relationship on a test db with the report tables containing

            $table->morphs('reportable');

the Switchgear report table then contains this line in it model class.

public function plant()
    {
        return $this->morphTo(Plant::class, 'reportable');
    }

and the other report tables have the same. The plant model has this

 public function reportable()
    {
        return $this->morphMany();
    }

So what I want to know is polymorphic relationship the way to achieve what Im looking for and is my code to set up the relationships correct as it isn't working?

Regards Paul.

Jan
07
9 months ago
Activity icon

Replied to Using An Array Of Objects In A Form Drop Down

You can pass the $products to your view and the just loop through it.

Here is a very simple example that displays the name in the selectbox dropdown and returns the id and not the name when you submit the form. As you can see I don't use the LaravelCollective Forms & HTML package. Just good old fashioned html5 forms.

<select>
    @foreach($products as $item)
        <option value={{$item->id}}>{{$item->name}}></option>
    @endforeach
</select>

Hope this helps.

Activity icon

Started a new Conversation Building An App To Use To Record Maintenance Reports

I'm building an app to record annual maintenance checks on electrical plant. The problem is each different type of plant (make/model) requires a different maintenance report. So what I need in to be able to create forms quickly, and associate them with a make/model. Each different item of plant also needs different information recorded dependant on make/model and the client. So first of all is there a package to allow the building of forms quickly maybe using a drag and drop ui in my applications admin panel and what would be the best database solution to store the non standard data as I don't want to build a new model for each report type. Any suggestions would be greatly appreciated.

Dec
18
10 months ago
Activity icon

Replied to Testing For Users With Unverified Emails.

@D9705996 - Exactly what I was after. Thanks.