finchy70

Head of Systems at EPS

Experience

8,200

0 Best Reply Awards

  • Member Since 1 Year Ago
  • 73 Lessons Completed
  • 2 Favorites

25th February, 2018

finchy70 started a new conversation Additional Login Checks • 3 months ago

I have updated Laravel to send an email to a new user when they register. I want to be able to block login until the email has been validated. At the moment I have added a validated column to my users table with a default value of 0. This gets changed from 0 to 1 when the email is successfully validated. How do I configure a check on this value before allowing a user to login?

18th February, 2018

finchy70 left a reply on Works But Loads Of Errors • 4 months ago

I have solved the problem with multiple errors. Originally I was using the version of vuejs created when you run npm install. I then decided to try using the CDN provided on the vuejs site. Importing this in my header for the page solved the multiple errors.

17th February, 2018

finchy70 left a reply on Works But Loads Of Errors • 4 months ago

Removing this from axios results in no data being retrieved from the db and this error

ReferenceError: axios is not defined at VueComponent.fetchTags (app.js:1166) at VueComponent.boundFn [as fetchTags] (app.js:1494) at VueComponent.created (app.js:1158) at callHook (app.js:4196) at VueComponent.Vue._init (app.js:5861) at new VueComponent (app.js:6029) at createComponentInstanceForVnode (app.js:5543) at init (app.js:5360) at createComponent (app.js:6813) at createElm (app.js:6761)

and not declaring tag results in no rendering of the page and this

[Vue warn]: Property or method "tag" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property.

16th February, 2018

finchy70 started a new conversation Works But Loads Of Errors • 4 months ago

<template>
    <div>
        <h4 class="mt-3 mb-2">Tags</h4>
        <form v-on:submit.prevent="addTag">
            <div class="row">
                <div class="col-md-6">
                    <div class="form-group">
                        <input type="text" class="form-control" v-model="tag.name">
                    </div>
                </div>
                <div class="form-group">
                    <button class="btn btn-primary" v-on:submit.prevent="addTag">Add Item</button>
                </div>
            </div>
        </form>
        <div class="row">
          <div class="col-md-10"></div>

        </div><br />

        <table class="table table-hover">
            <thead>
            <tr>
                <td>ID</td>
                <td>Tag Name</td>
                <td>Actions</td>
            </tr>
            </thead>

            <tbody>
                <tr v-for="tag in tags">
                    <td>{{ tag.id }}</td>
                    <td>{{ tag.name }}</td>
                    <td>
                        <router-link :to="{name: 'EditTag', params: { id: tag.id }}" class="btn btn-primary">Edit</router-link>
                        <button class="btn btn-danger" v-on:click="deleteTag(tag.id)">Delete</button>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script>

    export default {
        data(){
            return{
                tags:[],
                tag:{}
            }
        },

        created: function()
        {
            this.fetchTags();
        },

        methods: {
            fetchTags()
            {
              let uri = 'http://localhost:8000/api/tags';
              this.axios.get(uri).then((response) => {
                  this.tags = response.data;
              });
            },
            deleteTag(id)
            {
              let uri = `http://localhost:8000/api/tags/${id}`;
              // this.tag.splice(id, 1);
              this.axios.delete(uri);
              this.fetchTags();
            },
            addTag(){
                let uri = 'http://localhost:8000/api/tags';
                this.axios.post(uri, this.tag).then((response) => {
                    this.fetchTags()
            })
            }
        }
    }
</script>

This is my first attempt at using Vue in my laravel projects. I'm pleased to sat all works but I get a load of error is the console. Such as:-

[Vue warn]: $attrs is readonly.

found in

---> at resources\assets\js\components\DisplayTag.vue

vue.js:584 [Vue warn]: $listeners is readonly.

found in

---> at resources\assets\js\components\DisplayTag.vue

vue.js:584 [Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "to"

found in

---> at resources\assets\js\components\DisplayTag.vue

It's taken me hours to get this to work but I really want to know what these errors mean. Tried google but none the wiser.

13th February, 2018

finchy70 left a reply on Simple HTML Problem • 4 months ago

Turns out my $post->body was stored in the db with

tags. Used strip_tags($post->body) and everything worked as expected.

finchy70 left a reply on Bootstrap-selector Problem • 4 months ago

Turns out only the latest beta version of bootstrap-select is compatible with Bootstrap 4 (final stable).

finchy70 started a new conversation Simple HTML Problem • 4 months ago

Trying to output the following on one line but it always renders with the ...read more. on a separate line instead of appending the post. Any ideas?

<div>
     <span class="font-italic d-inline-block">{!! $post->body !!}<a class="read-more" href="/posts/show/{{$post->id}}">{{ (strlen($post->body)>99?"... read more.":"")}}</a></span>
</div>```

finchy70 started a new conversation Bootstrap-selector Problem • 4 months ago


        <select class="selectpicker mt-3" id="tags[]" name="tags[]" multiple="multiple">$tags[]
            @foreach($tags as$tag)
                <option value="{{$tag->id}}">$tag->name</option>
            @endforeach
        </select>```

Using this to select tags for a post but no tag values are getting passed to the select box.

No console errors are showing.

Anyone else managed to use this successfully?

11th February, 2018

finchy70 started a new conversation Outputing Data From Database From TinyMCE • 4 months ago

I have used TinyMCE for inputting a post body. I have then run this through Purifier::clean before storing in the database. Is it then safe to use {!! $post->body !!} to get the original input or should I use {{ $post->body }} which outputs escaped characters and is unreadable. Ive tried htmlspecialCharacters and strip_tags but these still leave in the escaped characters.

finchy70 left a reply on Horizontal Line Problems In A Blade @foreach Loop • 4 months ago

lol thanx

finchy70 started a new conversation <hr/> Problems In A Blade @foreach Loop • 4 months ago

Anyone understand why the only fires once in this loop that loops 3 times.

@foreach($posts as $post)
                   <hr/>
                    <h4 class="post-title">{{$post->title}}</h4>
                    <p class="mb-1">{{$post->body}}</p>
                    <h6 class="comment-text mb-3 font-italic">{{$post->user->name}} posted
                        this {{Carbon\Carbon::parse($post->created_at)->diffForHumans()}}.</h6
                    @if(count($post->comments)>0)
                        <p class="comment-text mb-0"><strong>Comments</strong></p>
                        @foreach($post->comments as $reply)
                            <div class="mt-2 card comment-card-background">
                                <p class="comment-added-by-text mt-0 mb-0">
                                    <span class="font-italic">{{$reply->user->name}}</span>
                                    <strong class="font-italic">added this comment</strong>
                                    <span class="font-italic">
                                        {{Carbon\Carbon::parse($reply->created_at)->diffForHumans()}}.
                                    </span>
                                </p>
                            </div>
                            <div class="mb-2 ml-2 card comment-background">
                                <p class="ml-2 comment-text">{{$reply->comment}}</p>
                            </div>
                        @endforeach
                    @endif
                @endforeach 

2nd October, 2017

finchy70 left a reply on Why Doesn't This Relationship Work? • 8 months ago

Oh my god. Thanks.

finchy70 left a reply on Why Doesn't This Relationship Work? • 8 months ago

Here is a larger section on the posts.index code

@foreach ($posts as $post)
                    <strong> {{$post->title}} </strong>
                    <p>{{ substr($post->body, 0, 300) }}{{ strlen($post->body) > 300 ? "..." : "" }}</p>
                    <a href="{{route('posts.show',$post->id)}}" class="btn-sm read-more-btn">Read More</a>
                    <hr>
                    <p>Posted by {{$post->user->name }}</p>
                @endforeach

finchy70 left a reply on Why Doesn't This Relationship Work? • 8 months ago

''' public function index() { $posts = Post::orderby('created_at', 'desc')->get(); dd($posts); return view('posts.welcome', compact('posts')); } '''

finchy70 left a reply on Why Doesn't This Relationship Work? • 8 months ago

ErrorException (E_ERROR)
Trying to get property of non-object (View: C:\Users\Paul.FINCHY\Sites\finchysblog\resources\views\posts\welcome.blade.php)

finchy70 started a new conversation Why Doesn't This Work • 8 months ago

<p>Posted by {{$post->user()->name }}</p>

Why wont the above code work? I've done similar stuff before with no issues. I'm sorry to bother you all.

Post.php

class Post extends Model
{
    public function user(){
        $this->belongsTo('App\User');
    }
}

User.php

class User extends Authenticatable
{
    public function posts(){
        $this->hasMany('App\Post');
    }
    
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
}

table

public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title');
            $table->text('body');
            $table->integer('user_id')->unsigned();
            $table->timestamps();
        });
    }

Can anyone see what I'm doing wrong?

26th September, 2017

finchy70 started a new conversation Date Format In Select Box • 8 months ago

Im sending a collection of dates to a laravel form. These collections are in $statements.

I want the format of the date to be dd/mm/yyyy.

The select box gives me yyyy-mm-dd.

{{ Form::label('statement', 'Statement: ')}}
            {{ Form::select('statement', $statements, array('class' => 'form-control input-lg')) }}

How can I format the date the way I want it?

finchy70 left a reply on Cant Save After Conditional Updates • 8 months ago

Silly me. Fixed. Should not have been using ->get().

finchy70 started a new conversation Cant Save After Conditional Updates • 8 months ago

The following code changes the current status of one record to false then the current status of another to true but gives me a BadMethodCallException Method save does not exist. Error.

Can't understand why.

Can someone help?

public function makeCurrent($id)
    {
        $statements = Statement::all();
        $old_current_id = 0;
        foreach ($statements as $statement) {
            if($statement->current == 1)
            {
                $old_current_id = $statement->id;
            };
        }
        if($old_current_id != 0)
        {
            $statement_old_current = Statement::find($old_current_id)->get();
            $statement_old_current->current = 0;
            $statement_old_current->save();
        }
        $statement_current = Statement::find($id)->get();
        $statement_current->current = 1;
        $statement_current->save();
        return redirect()->route('statements');
    }

25th September, 2017

finchy70 left a reply on Number To 2 Decimal Placed Blade • 8 months ago

How would I get this to happen in a model bind form? Trying to populate the field with a float to two decimals.

22nd September, 2017

finchy70 left a reply on Need To Get A Value From A Posted Form • 8 months ago

Fixed it with the following. Thanks for the point in the right direction.

JavaScript

function hideCalibration() {
    var e=document.getElementById("calibration");

    var item = document.getElementById("category_name");

    var selected = item.options[item.selectedIndex];
    var flag = selected.getAttribute('calibration-check');
    console.log(flag);
    if (parseInt(flag)){
        e.style.display = "block";
    } else {
        e.style.display = "none";
    }
}

Selectbox Html

<label for="category_name">Tool Category:</label><br>
            <select class="textWidth form-control" onchange="hideCalibration()" id="category_name" type="text">
                <option disabled selected> -- select an option -- </option>
                @foreach($categories as $category)
                    <option value="{{$category->id}}" calibration-check="{{$category->needs_calibration}}">
                        {{$category->category_name}}
                    </option>
                @endforeach
            </select>

finchy70 left a reply on Need To Get A Value From A Posted Form • 8 months ago

function hideCalibration() {
    var e=document.getElementById("calibration");
    console.log(document.getElementsByName("category_name").class);
    if (parseInt(document.getElementById("category_name").class)){
        e.style.display = "block";
    } else {
        e.style.display = "none";
    }
};

The console shows console.log(document.getElementsByName("category_name").class); as undefined.

Also tried console.log(document.getElementsById("category_name").class);

finchy70 started a new conversation Need To Get A Value From A Posted Form • 8 months ago

This code sits inside a form and provides a select box of tool types. Some tools need testing / calibration and some don't. I have a js script that hides or shows a date input box depending on whether the tool needs a calibration date. The Boolean value for needs_calibration controls this. I assign this to the value and use this in my script to show or hide the date input box.

Tool Category: -- select an option -- @foreach($categories as $category) {{$category->category_name}} @endforeach

The problem is when I post the form I need the $category_name value ($request->category_name) but this returns the needs_calibration Boolean vale from the form. How can I get the $category->category_name or $category->category_id vale from my form without breaking the JavaScript.

14th June, 2017

finchy70 left a reply on Forms In Blade • 1 year ago

gator changing 'minimum' to 'min' worked thanks.

samfrjn11 Thanks too.

finchy70 left a reply on Forms In Blade • 1 year ago

I wanted to use Form Model Binding

finchy70 started a new conversation Forms In Blade • 1 year ago

What is the blade alternative to the following form code which only allows the user to select Sundays.

Week Ending (Will only allow you to select Sundays!)

I've tried {{ Form::label('Week Ending') }} {{ Form::date('week_ending'), ['minimum' => '2017-06-04', 'step' => '7'] }}

Any help appreciated.

18th May, 2017

finchy70 left a reply on Getting A List Of Users With A Specific Role While Using Entrust. • 1 year ago

@Cronix Thanks for the suggestion but still get the same error.

finchy70 left a reply on Query Scope Based On Method • 1 year ago

Same problem here.

finchy70 left a reply on Getting A List Of Users With A Specific Role While Using Entrust. • 1 year ago

@silverxjohn Yes. class User extends Authenticatable { use EntrustUserTrait; use Notifiable;

public function scopeHasRole($query, $role)
{
    $query->where('role', '=', $role);
}

finchy70 left a reply on Getting A List Of Users With A Specific Role While Using Entrust. • 1 year ago

@silverxjohn This still gives me the 'Non-static method App\User::hasRole() should not be called statically' error.

17th May, 2017

finchy70 started a new conversation Updating A Users Role In User_role Table With Eloquent When Using Entrust. • 1 year ago

When I attempt to do this using $user->attachRole(newrole); I add a second entry in the in the user_role table but I only want to update the users existing role. Any ideas anyone?

finchy70 left a reply on Getting A List Of Users With A Specific Role While Using Entrust. • 1 year ago

Thank you. I will try this tomorrow.

finchy70 started a new conversation Getting A List Of Users With A Specific Role While Using Entrust. • 1 year ago

I can get the list of Users with the 'user' role by using the following code:-

class AdministrationController extends Controller { public function index() { return view('templates.administrator'); }

public function create()
{
    $users =  User::all();
    $userList = array();
    foreach ($users as $user){
        if ($user->hasRole('user')){
            $userList[] = $user;
        }
}
    return view('templates.createadmin', compact('userList'));
}

}

Is there an easier Eloquent call to get the same result. I tried

User::hasRole('user')->get();

but this gave an error 'hasRole() should not be called statically' as I am not calling it on an instance of User.

Any help will be appreciated as I am only about 2 weeks into learning laravel.

14th May, 2017

finchy70 started a new conversation Ability To Create Forms And Use The Captured Data To Create Reports. • 1 year ago

I have a business that carries out maintenance and service contracts for multiple clients. I'm new to Laravel and I am trying to work out the best approach to build an app that lets me complete these surveys on-site and generates the clients own required report . The app will need to allow me to add additional forms and report templates as our client base expands and save the data in a database. One solution is I could manually add the forms and report templates with each new client and create a new model to store the data but this feels like a rewrite every time I add a new client. Any suggestions for the best way to go about this would be greatly appreciated.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.