RossUK

RossUK

Member Since 4 Months Ago

Experience Points 3,940
Experience
Level
Lessons Completed 28
Lessons
Completed
Best Reply Awards 0
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

21 Oct
1 month ago

RossUK left a reply on Correct Use Statement For Composer Library

I get that thanks but in this case the class I'm using didn't have a namespace to start with?

RossUK left a reply on Correct Use Statement For Composer Library

Hi,

I got it working, thanks for your help

I think it was conflicting with the built-in laravel Slack notification class names. What I did was left it autoloading in composer.json as normal and added a namespace to the top of the third party library's source file in the vendor directory. I then added using statement using the newly created namespace.

use \SimonBackX\Slack;
use \SimonBackX\SlackMessage;
//require (base_path('vendor/simonbackx/slack-php-webhook/slack.php'));

I'm pretty sure this is bad practice so I would be interested to know the correct way of dealing with this particular scenario :) If anyone can shed any light?

RossUK left a reply on Correct Use Statement For Composer Library

Unfortunately the built in slack functionality won't allow me to add buttons

RossUK left a reply on Correct Use Statement For Composer Library

Thanks I thought maybe something like that however if I do the above I get

Symfony\Component\Debug\Exception\FatalErrorException: Cannot declare class Slack, because the name is already in use in file /Users/Ross/LabProjects/PBXBridge/vendor/simonbackx/slack-php-webhook/slack.php on line 30

But if I comment out the line it cannot find it

Could it be conflicting with some of the built in slack notification code?

I have even tried renaming the class inside

vendor/simonbackx/slack-php-webhook/slack.php

to MySlack but I then I get

Symfony\Component\Debug\Exception\FatalErrorException: Cannot declare class MySlack, because the name is already in use in file /Users/Ross/LabProjects/PBXBridge/vendor/simonbackx/slack-php-webhook/slack.php on line 30

RossUK left a reply on Correct Use Statement For Composer Library

Hi , Yes I went through this but getting the following error so guess I need to include it somewhere in my controller ?

Class App\Http\Controllers\Slack; not found in file 

RossUK started a new conversation Correct Use Statement For Composer Library

I am trying to use a third party composer library.

https://packagist.org/packages/simonbackx/slack-php-webhook

I have done the usual composer require. In the docs it doesn't show how to include the library in my Laravel project (Which use statements to use or app.php etc) . I know there is probably a way to work this out but I'm pretty new to Laravel and not sure what to do. Can anyone help please?

RossUK left a reply on Display Laravel Echo Pusher Event Values In Vue Component

great all good now thanks very much :)

16 Oct
1 month ago

RossUK left a reply on Realtime Progress Bar

Thanks again for this I managed to muddle through and get this working using Vue and Pusher. It was also my first experience of using Vue and adding realtime feedback so really pleased with the results.

14 Oct
1 month ago

RossUK started a new conversation Display Laravel Echo Pusher Event Values In Vue Component

I have been following the series

https://laracasts.com/series/get-real-with-laravel-echo

in the example Jeffery passes an array to the view component I have tried reading the docs but can't quite figure out how to update single values for example a label or text box.

here is my vue component

<template>
<div>
        <div class="callout callout">
                <p>{{ msg }}</p>
        </div>
</div>
</template>

<script>
     export default {},
     created() {
     window.Echo.channel('progressBar').listen('UpdateProgressData', {{ message }} => {
     msg = message;
     })
     }
</script>

And here is my event. I have see the event values in the chrome js console

public $progress;
    public $message;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($progress, $message)
    {
         $this->progress = $progress;
         $this->message = $message;
    }

    
    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new Channel('progressBar');
    }
13 Oct
1 month ago

RossUK left a reply on Import CSV Files And Excel Using File Streamed From S3

Got it sorted using local storage thanks is it normal to have to prefix the path (in this case storage/app/) ?

here is what I ended up with

Controller Method:

public function store(Request $request)
    {

        if($request->hasFile('file')) 
        {
        $path = $request->file('file')->store('temp-files');
        ProcessUploadedCDRFile::dispatch($path);
        return back();
        } 
    }

and the job method

public function handle()
    {

       $results = Excel::load('storage/app/' . $this->path); 
       Storage::delete('storage/app/' . $this->path);

       // do something useful with results
    }

Thanks again

RossUK left a reply on Import CSV Files And Excel Using File Streamed From S3

Think I'm going to go with local storage as it's going to be deleted after use :)

Ill post back my solution once I have read how to store and delete off the local file system to a temp folder

RossUK left a reply on Import CSV Files And Excel Using File Streamed From S3

I think its because the PHPExcel_Reader is expecting a filename but I'm not sure how to sort it.

below extracted from error message

  public function canRead($pFilename)
    {
        // Check if file exists
        if (!file_exists($pFilename)) {
            throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
        }

RossUK left a reply on Import CSV Files And Excel Using File Streamed From S3

Thanks almost there something isn't quite right when I try this I get the following

Could not open /Users/Ross/Projects/TestCDRProcess/Id , Customer, Telephone Number,

Those are the file headers ?

RossUK left a reply on Import CSV Files And Excel Using File Streamed From S3

That's what I was thinking. I just need to work out the best way of managing the files so they are deleted after they are processed :)

Thanks for your help

RossUK left a reply on Import CSV Files And Excel Using File Streamed From S3

Actually I tried this and didn't have any luck I received the error

Serialization of 'Illuminate\Http\UploadedFile' is not allowed

I also tried to comment out the Serialization parts and received the same error

amespace App\Jobs;

use Illuminate\Bus\Queueable;
//use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class ProcessUploadedCDRFile implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable;//, SerializesModels;

    protected $file;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($file)
    {
        $this->file = $file;
    }

RossUK started a new conversation Import CSV Files And Excel Using File Streamed From S3

I have a job to process large uploaded csv files. I process these as a queued job. Because the queued jobs can not accept a file as a passed in parameter I had the idea of uploading the file to S3 first then use the file from s3 in my csv processing job.

I have tried this using Maatwebsite/Laravel-Excel but it wont accept the streamed file from S3.

$contents = Storage::disk('s3')->get($filename);
        $results = Excel::load($contents);

So I can process the csv in the background can anyone recommend a better way of doing this or maybe a better csv, excel import library.

RossUK left a reply on Laravel Echo Not Listening/working On Pusher Channel Event

Found my error here a type in my bootstrap.js method

    .listen('UpdateProgressData', e => {

changed to

  .listen('UpdateProgressData', (e) => {

RossUK started a new conversation Laravel Echo Not Listening/working On Pusher Channel Event

Hi I have been trying to use Laravel Echo with pusher after going through the tutorial on Laracasts. I am trying to listen on a public channel just as a test but cannot get a message to log to the console. The project I am trying to add this to is Laravel 5.5.

So far I have the following:

my .env file setup

an event called UpdateProgressData

<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class UpdateProgressData implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $foo;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct()
    {
         $this->foo = 'bar';
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new Channel('progessBar');
    }
}

and the following at the bottom of /resources/assets/js/bootstrap.js

import Echo from 'laravel-echo'

window.Pusher = require('pusher-js');

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: '8e30361e3c24c96c3397',
    cluster: 'eu',
    encrypted: true
});

window.Echo.channel('progressBar')
    .listen('UpdateProgressData', e => {
        console.log('UpdateProgressData has been updated!');
        console.log(e);
    });

I can see the connections in the pusher debug console and also the event data but nothing is being logged to the console.

I have probably missed something obvious if any can help me debug it will be much appreciated :)

10 Oct
2 months ago

RossUK left a reply on Realtime Progress Bar

Hey, this is really useful info thanks for taking the time to give me a head start very much appreciated! Going to go through the series first and then take it from there. :)

RossUK started a new conversation Realtime Progress Bar

Hi,

I have a large background task / queue task that I want to be able to give realtime progress on. I want to end up with something like this

https://blog.pusher.com/improve-user-experience-app-real-time-progress-bar-tutorial/

Does anyone have a good tutorial for something like this or can advise me on the front end part of it. Just a high level overview would be great :)

08 Oct
2 months ago

RossUK left a reply on Create Just One Related Model For Feature Test

Great, works perfectly thanks

RossUK started a new conversation Create Just One Related Model For Feature Test

If I am writing a test that contains both a user model and a post model each has an associated Model Factory. I know I can do the following to create a collection of related records but how do I create just one of each for use during a feature test.

$users = factory(App\User::class, 3)
           ->create()
           ->each(function ($u) {
                $u->posts()->save(factory(App\Post::class)->make());
            });

for example

$customer = factory('App\User')->create()

// then add a single post to this user

Many Thanks

05 Oct
2 months ago

RossUK left a reply on Setting The Existing Value On A Drop Down Box When Using Partial For Edit And Create Form Fields

Yes thank you very much. This is what I have now and works perfectly

//CustomerController.php

    public function create()
    {
        // pass blank customer (for select menu)
        $customer = new Customer;
        return view('customer.create',['customer' => $customer]);
    }

public function edit(Customer $customer)
    {
        $customer = Customer::find($customer->id);
        return view('customer.edit', ['customer' => $customer]);
    }

And in my customer/partials/formfields.blade.php

<select class="form-control" name="title">
      <option value="" @if(old('title', $customer->title) == "") selected @endif>Select</option>
      <option value="Mr." @if(old('title', $customer->title) == "Mr.") selected @endif>Mr.</option>
      <option value="Mrs." @if(old('title', $customer->title) == "Mrs.") selected @endif>Mrs.</option>
      <option value="Miss" @if(old('title', $customer->title) == "Miss") selected @endif>Miss</option>
      <option value="Ms." @if(old('title', $customer->title) == "Ms.") selected @endif}>Ms.</option>
      <option value="Dr." @if(old('title', $customer->title) == "Dr.") selected @endif>Dr.</option>
      <option value="Prof." @if(old('title', $customer->title) == "Prof.") selected @endif>Prof.</option>
    </select>

Thanks again :)

04 Oct
2 months ago

RossUK left a reply on Setting The Existing Value On A Drop Down Box When Using Partial For Edit And Create Form Fields

ok, now I have this. This gets the correct initial value on the edit form and retains the value on validation error. It does however still throw an Undefined variable: customer error when trying to create a customer :/ :)

<select class="form-control" name="title">
      <option value="" {{ (optional($customer->title) === "" or old('title') === "") ? "selected" : "" }}>Select</option>
      <option value="Mr." {{ (optional($customer->title) === "Mr." or old('title') === "Mr.") ? "selected" : "" }}>Mr.</option>
      <option value="Mrs." {{ (optional($customer->title) === "Mrs." or old('title') === "Mrs.") ? "selected" : "" }}>Mrs.</option>
      <option value="Miss" {{ (optional($customer->title) === "Miss" or old('title') === "Miss") ? "selected" : "" }}>Miss</option>
      <option value="Ms." {{ (optional($customer->title) === "Ms." or old('title') === "Ms.") ? "selected" : "" }}>Ms.</option>
      <option value="Dr." {{ (optional($customer->title) === "Dr." or old('title') === "Dr.") ? "selected" : "" }}>Dr.</option>
      <option value="Prof." {{ (optional($customer->title) === "Prof." or old('title') === "Prof.") ? "selected" : "" }}>Prof.</option>
    </select>

Thanks

RossUK left a reply on Setting The Existing Value On A Drop Down Box When Using Partial For Edit And Create Form Fields

No, afraid not. It retains the old value on validation errors etc but doesn't set the value on the page load. I'm curious if there are better ways to do the same thing as it seems a bit messy (my original method I mean)

RossUK left a reply on Setting The Existing Value On A Drop Down Box When Using Partial For Edit And Create Form Fields

this is what I have at the moment

 <select class="form-control" name="title">
                      <option value="" {{ old('title') === "" ? "selected" : "" }}>Select</option>
                      <option value="Mr." {{ old('title') === "Mr." ? "selected" : "" }}>Mr.</option>
                      <option value="Mrs." {{ old('title') === "Mrs." ? "selected" : "" }}>Mrs.</option>
                      <option value="Miss" {{ old('title') === "Miss." ? "selected" : "" }}>Miss</option>
                      <option value="Ms." {{ old('title') === "Ms." ? "selected" : "" }}>Ms.</option>
                      <option value="Dr." {{ old('title') === "Dr." ? "selected" : "" }}>Dr.</option>
                      <option value="Prof." {{ (old('title') or $customer->title) === "Prof." ? "selected" : "" }}>Prof.</option>
                  </select>

RossUK left a reply on Setting The Existing Value On A Drop Down Box When Using Partial For Edit And Create Form Fields

Thanks I tried that but not sure how to apply to a select menu please can you help?

RossUK started a new conversation Setting The Existing Value On A Drop Down Box When Using Partial For Edit And Create Form Fields

I am trying to reduce code duplication by having a partial for my create and edit customer form fields.

    <form action="/customer/{{$customer->id}}" method="POST" enctype="multipart/form-data">

                     {{ csrf_field() }}

             {!! method_field('patch') !!}


             @include('customer.partials.formfields')

            </form>
          </div>

I have a select menu for title eg. Mr. , Mrs. Miss etc Im not sure how to make the value selected for both old('title) and also $customer->title

I have done the below on the create form

<option value="Mr." {{ old('title') === "Mr." ? "selected" : "" }}>Mr.</option>

But not sure how to do this for edit and create?

RossUK left a reply on Struggling To Find Error In Test

Hi, thanks for this I have been looking at it too long. I'm still/always learning. Is there any way to spit out the error during the test? I get the assertion errors but not why the error 500 is thrown. I'm just curious the correct way of debugging

Thanks

RossUK started a new conversation Struggling To Find Error In Test

Hi I am getting an error 500 on a test I am running and am struggling to find what I have dome wrong below are my tests and controller methods :)

 /** @test */
    public function authenticated_users_can_update_existing_customer()
    {
        $this->withExceptionHandling();

        $customer = factory('App\Customer')->create();

        $data = [
        'company' => 'Acme Ltd',
        'first_name' => 'Ross',
        ];

        $this->actingAs($this->user)
        ->patchJson(route('customer.update', $customer->id),$data)
            ->assertStatus(202);

        $customer = $customer->fresh();

         $this->assertEquals('Acme Ltd', $customer->company);
    }

And my Controller Method and route

public function update(Customer $customer,Request $request)
    {
         //$this->validator(request()->all())->validate();

        $customer->update($data);

        return request()->wantsJson()
            ? response()->json($customer, 202)
            : null;
    }
// Resource Routes
    Route::resource('customer', 'CustomerController')->middleware('auth');

Thanks for any help in advance :)

02 Oct
2 months ago

RossUK left a reply on Localised Faker In Test - Laravel 5.5

I sorted this using the following, not sure if this the best way

$this->faker('en_GB')->phoneNumber;

RossUK left a reply on Realtime Frontend Blog Style Tag With Laravel

hey thanks looks interesting

RossUK started a new conversation Localised Faker In Test - Laravel 5.5

Please can someone help me to use an en_GB instance of faker within tests. I have tried reading the docs but can only find example of using Faker in Factories and not using WithFaker. Here is an example of where I would like to implement it :)

<?php

namespace Tests\Unit;

use App\User;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

class LoginTest extends TestCase
{

    use WithFaker;

    /**
     * A basic test example.
     *
     * @return void
     */

    /** @test */
    public function test_example()
    {

        $user = User::create([
            'mob_no' => $faker-> mobileNumber(),
        ]);

    }

}
30 Sep
2 months ago

RossUK started a new conversation Realtime Frontend Blog Style Tag With Laravel

Hi,

Id like learn how to do some realtime stuff with Laravel. I think I probably need api routes and a JS framework but not sure where to start. In an Laravel App I have I need to add some billing tags to a report similar to blog tags in the style of this https://jsfiddle.net/dede89/f0b6gegt/ but with autocomplete for existing tags.

Can anyone point me at a good tutorial as a starting point.?

RossUK left a reply on Array Combine Totals

Hi,

Thanks think I was approaching this the wrong way I looped through the array instead to change the value

foreach($totals as $total)
       {
        $labels[] = $total['status'];
        $values[] = $total['count'];
        $colours = $this->chartColour($total['status']);
       }
29 Sep
2 months ago

RossUK started a new conversation Array Combine Totals

if I have an array like this [‘failed’ => 1, ‘completed’ =>5] that is pulled from a DB query but there are other options that may show up in the query that I need to include even if no results exist for example [‘failed’ => 1,‘completed’ => 5,‘busy’ => 0] how can I achieve this in php> i wondered if there is a way to merge an empty array with one that has values or similar

RossUK started a new conversation Laravel Eloquent GroupBy() And Get Count Of Each Group

if I have a table containing a job and a job can have a status of one of three values. What is the Laravel/Eloquent way of getting a count of each status?

RossUK left a reply on Problem With Eloquent Relationship

Ok Thanks again

RossUK left a reply on Problem With Eloquent Relationship

Thanks very much for your help I'll have a read through the docs. So without using eager loading would the job be lazy loaded by default? and do you know why I could access all the other job fields except for the name field without eager loading ?

Thanks again

RossUK left a reply on Problem With Eloquent Relationship

Hi, thanks

the second example works but the first one doesn't. Please can you explain your solution I don't understand why i would need "with" only on that particular column? :)

RossUK started a new conversation Problem With Eloquent Relationship

Hi, I have model called CallLog and a class called Job and the following and CallLog belongs to Job.

class CallLog extends Model
{
     protected $table = 'call_log';

    public function job()
    {
        return $this->belongsTo(Job::class, 'job_id');
    }

Job includes the fields type,status,name

I am strugling to get the job name value

as a test if I run tinker and enter the following

$calllog = App\CallLog::find(5);
$job = $calllog->job;
$status = $job->status;
// I get the value I expect
=> "Completed"

however if I do the same with name eg. I get null

$calllog = App\CallLog::find(5);
$job = $calllog->job;
$name = $job->name;
// I get null
=> "null"

When I find the job I can see the name value set?

>>> $job = $calllog->job;
=> App\Job {#2937
     id: 4,
     created_at: "2018-09-12 21:12:25",
     updated_at: "2018-09-12 21:48:15",
     name: "test9",
     status: "Sent",
   }

25 Sep
2 months ago

RossUK left a reply on $request->getContent() Is Empty

great , many thanks :)

RossUK started a new conversation $request->getContent() Is Empty

I am trying to inspect the structure of an incoming webhook by capturing the incoming post request to a text file.

here is my api route

Route::post('/callstatus/webhook', '[email protected]');

and here is my controller method

    public function updateStatus(Request $request)
    {

        file_put_contents('temp-log.txt', $request->getContent()->all());
    }

if I make a post request using postman i can access individual post variables by name eg. $request->myField but not the whole request. Am I missing something? :)

RossUK left a reply on Unit Testing Advice

Really great info thanks very much :)

RossUK left a reply on Unit Testing Advice

Hi,

Thanks. I have been going through the forum tutorial and trying to apply the testing logic to my own example. Thanks for helping me clear up the differences between a feature and a unit.

Is testing at route level a typical work flow or would it be better to test at browser level therefore testing the routing at the same time. I suppose that's what Jeffery does in the forum tutorial :)

RossUK started a new conversation Unit Testing Advice

Hi, I am trying to do some unit/feature testing and take a TDD approach to a new Laravel project. I am trying to get my head around which tests I should be writing and also which tests are a feature or a unit. As an example to start off with I have a Customer model and a Contact model. When the app is finished an authenticated end user will be able to create edit and delete customers and contacts and also add contacts to a customer. Before any webforms exists what tests should/would be good to write for this.

Many Thanks