RossUK

Experience

3,670

0 Best Reply Awards

  • Member Since 2 Months Ago
  • 27 Lessons Completed
  • 0 Favorites

14th October, 2018

RossUK started a new conversation Display Laravel Echo Pusher Event Values In Vue Component • 16 hours ago

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');
    }

13th October, 2018

RossUK left a reply on Import CSV Files And Excel Using File Streamed From S3 • 1 day ago

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 • 1 day ago

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 • 1 day ago

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 • 1 day ago

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 • 1 day ago

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 • 1 day ago

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 left a reply on Import CSV Files And Excel Using File Streamed From S3 • 1 day ago

that makes sense thanks

RossUK started a new conversation Import CSV Files And Excel Using File Streamed From S3 • 1 day ago

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 • 1 day ago

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 • 2 days ago

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 :)

10th October, 2018

RossUK left a reply on Realtime Progress Bar • 4 days ago

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 • 4 days ago

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 :)

8th October, 2018

RossUK left a reply on Create Just One Related Model For Feature Test • 6 days ago

Great, works perfectly thanks

RossUK started a new conversation Create Just One Related Model For Feature Test • 1 week ago

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

5th October, 2018

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

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 :)

4th October, 2018

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

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 • 1 week ago

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 • 1 week ago

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 • 1 week ago

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 • 1 week ago

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 • 1 week ago

Thanks

RossUK left a reply on Struggling To Find Error In Test • 1 week ago

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 • 1 week ago

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 :)

2nd October, 2018

RossUK left a reply on Localised Faker In Test - Laravel 5.5 • 1 week ago

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 • 1 week ago

hey thanks looks interesting

RossUK started a new conversation Localised Faker In Test - Laravel 5.5 • 1 week ago

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(),
        ]);

    }

}

30th September, 2018

RossUK started a new conversation Realtime Frontend Blog Style Tag With Laravel • 2 weeks ago

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 • 2 weeks ago

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']);
       }

29th September, 2018

RossUK started a new conversation Array Combine Totals • 2 weeks ago

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 left a reply on Laravel Eloquent GroupBy() And Get Count Of Each Group • 2 weeks ago

Thanks very much

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

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 • 2 weeks ago

Ok Thanks again

RossUK left a reply on Problem With Eloquent Relationship • 2 weeks ago

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 • 2 weeks ago

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 • 2 weeks ago

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",
   }

25th September, 2018

RossUK left a reply on $request->getContent() Is Empty • 2 weeks ago

great , many thanks :)

RossUK started a new conversation $request->getContent() Is Empty • 2 weeks ago

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 • 2 weeks ago

Really great info thanks very much :)

RossUK left a reply on Unit Testing Advice • 2 weeks ago

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 • 2 weeks ago

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

Edit Your Profile
Update

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