skoobi

Member Since 5 Years Ago

Ceredigion

Experience Points
38,450
Total
Experience

1,550 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
260
Lessons
Completed
Best Reply Awards
8
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 8
38,450 XP
Sep
29
2 weeks ago
Activity icon

Replied to Cannot Log Into Forge SSH

So after quite some time, it turned out to be Sequel Pro. Uninstalled it and downloaded a new version and all worked ok.

Activity icon

Started a new conversation Cannot Log Into Forge SSH

I have a database server on a Digital Ocean server that holds all my databases but I had to reinstall osx and after Installing Sequel Pro I cannot access the DB server. I've checked and double-checked the details and all are exactly the same as my details on the MacBook. The only thing different will be the SSH keys. I created new keys on the iMac but if I add the key to Forge and try to log in I get

Unable to connect to host 00.00.00.00, or the request timed out.

Be sure that the address is correct and that you have the necessary privileges, or try increasing the connection timeout (currently 10 seconds).

MySQL said: SSL connection error: Server doesn't support SSL

If i play around then i get::

The SSH Tunnel could not authenticate with the remote host. Please check your password and ensure you still have access.

Now i know the password is correct as i can login to the server through SSH and also connect to the db using the same details.

I just can't understand why it works on my MacBook and not on the iMac with exactly the same settings...

Any help or ideas would be massively grateful.

Thank you

Sep
18
3 weeks ago
Activity icon

Started a new conversation Foreach Radio Items

Hi. I'm not particularly good with javascript but bumble through slowly.

What I'm trying to do is to have a selection of radio buttons under a foreach loop of images. So image 1,2,3, etc. Under the images is a form with a selection of radio buttons that lets the user choose what they want to do with that image (delete, destroy, scan etc.) and a submit under each of the images that pop up when they select an option.

The easy part for me was displaying the images and building the form but now after a fair bit of hair pulling I'm struggling on the JS part. I can get it all to work on 1 image and I've also got the code working to differentiate between the images, but how do I get it so the javascript knows which image to work on. I.e. if I select "delete" on image 2, I want it to display the message and the submit button for that and not the others. Hope that makes sense. Heres what I have so far.

<div class="grid_4 omega">

            <div class="cont">
                @if($scan->scan_paths == "images/viewer-demo.jpg")
                <img src="{{ url($scan->scan_paths) }}" alt="Avatar" class="image"
                style="width:100%">
                <a href="{{ route('customer.scan-viewer.show', ['scan' => $scan->id]) }}">
                    <div class="middle">
                        <div class="text">VIEW</div>
                    </div>
                </a>
                @else
                <img src="{{ config('settings.s3.url') . $scan->scan_paths }}"
                alt="{{  str_replace('.jpg', '', str_replace('customers/' . Auth::user()->username . '/scans/', '', $scan->scan_paths)) }}"
                class="image"
                style="width:100%">
                <a href="{{ route('customer.scan-viewer.show', ['scan' => $scan->id]) }}">
                    <div class="middle">
                        <div class="text">VIEW</div>
                    </div>
                </a>
                @endif
            </div>


            <p>
                Uploaded {{ $scan->created_at->format('dS F Y') }} <br>
                <span style="color:grey;">Image Ref: {{  str_replace('.jpg', '', str_replace('customers/' . Auth::user()->username . '/scans/', '', $scan->scan_paths)) }}</span>
            </p>
            <form action="{{ route('customer.scan-viewer.update', ['id' => $scan->id]) }}"
                role="form" method="POST">
                @csrf

                @if($scan->destroy_item == 0)
                <p>
                    <input type="radio" name="scan_selection" id="toggle-scan-{{ $scan->id }}" value="1"> SCAN
                    ALL PAGE
                    <br>
                    <input type="radio" name="scan_selection" id="toggle-forward-{{ $scan->id }}" value="2"> FORWARD
                    THIS MAIL ITEM <br>
                    <input type="radio" name="scan_selection" id="toggle-delete-{{ $scan->id }}" value="3"> DELETE
                    IMAGE FROM VIEWER
                    <br>
                    <input type="radio" name="scan_selection" id="toggle-destroy-{{ $scan->id }}" value="4"> DESTROY
                    THIS MAIL ITEM <br>
                </p>

                @else
                <p>
                    <input type="radio" name="scan_selection" id="toggle-delete-{{ $scan->id }}" value="3"> DELETE
                    IMAGE FROM VIEWER
                </p>
                @endif

                <div id="show-scan-{{ $scan->id }}" style="display:none; line-height: 1em;">
                    <p>
                        <small class="">
                            Selecting "SCAN ALL PAGES" will scan all the pages in this mail item.
                        </small>
                    </p>
                    <p>
                        <input type="submit" id="submit_scan-{{ $scan->id }}" value="SUBMIT &amp; REFRESH">
                    </p>
                </div>

                <div id="show-forward-{{ $scan->id }}" style="display:none; line-height: 1em;">
                    <p>
                        <small class="">
                            Selecting "FORWARD THIS MAIL ITEM" will send this mail item to you via your
                            selected forwarding method.
                        </small>
                    </p>
                    <p>
                        <input type="submit" id="submit_forwarding-{{ $scan->id }}" value="SUBMIT &amp; REFRESH">
                    </p>
                </div>

                <div id="show-delete-{{ $scan->id }}" style="display:none; line-height: 1em;">
                    <p>
                        <small class="error">
                            Selecting "DELETE IMAGE FROM VIEWER" will delete the selected scan and you
                            will no longer be able to DESTROY the original mail item.
                        </small>
                    </p>
                    <p>
                        <input type="checkbox" id="confirm_delete-{{ $scan->id }}" name="confirm_delete"> Are you sure?
                    </p>
                    <p>
                        <input type="submit" id="submit_delete-{{ $scan->id }}" value="SUBMIT &amp; REFRESH">
                    </p>
                </div>

                <div id="show-destroy-{{ $scan->id }}" style="display:none; line-height: 1em;">
                    <p>
                        <small class="error">
                            Selecting "DESTROY THIS MAIL ITEM" will notify the mailroom to DESTROY the
                            physical mail item.
                        </small>
                    </p>
                    <p>
                        <input type="checkbox" id="confirm_destroy-{{ $scan->id }}" name="confirm_destroy"> Are you sure?
                    </p>
                    <p>
                        <input type="submit" id="submit_destroy-{{ $scan->id }}" value="SUBMIT &amp; REFRESH">
                    </p>
                </div>

            </form>
</div>

JS

$(document).ready(function () {
        $('input[type="radio"]').click(function () {

                // Toggle scan all
                if ($(this).attr('id') === 'toggle-scan-{!! $scan->id !!}') {
                    $('#show-scan-{!! $scan->id !!}').show();
                } else {
                    $('#show-scan-{!! $scan->id !!}').hide();
                }

                // Toggle Forwarding
                if ($(this).attr('id') === 'toggle-forward') {
                    $('#show-forward').show();
                } else {
                    $('#show-forward').hide();
                }

                if ($(this).attr('id') === 'toggle-delete') {
                    $('#show-delete').show();
                    $('#submit_delete').prop('disabled', true);
                    document.getElementById("confirm_delete").checked = false;

                    $('#confirm_delete').change(function () {
                        if ($(this).is(':checked')) {
                            $('#submit_delete').prop('disabled', false);
                        } else {
                            $('#submit_delete').prop('disabled', true);
                        }
                    });

                } else {
                    $('#show-delete').hide();
                    $('#submit_destroy').prop('disabled', false);
                    document.getElementById("confirm_delete").checked = false;
                }

                // Toggle destroy and delete radio
                if ($(this).attr('id') === 'toggle-destroy') {
                    $('#show-destroy').show();
                    $('#submit_destroy').prop('disabled', true);
                    document.getElementById("confirm_destroy").checked = false;

                    $('#confirm_destroy').change(function () {
                        if ($(this).is(':checked')) {
                            $('#submit_destroy').prop('disabled', false);
                        } else {
                            $('#submit_destroy').prop('disabled', true);
                        }
                    });

                } else {
                    $('#show-destroy').hide();
                    $('#submit_destroy').prop('disabled', false);
                    document.getElementById("confirm_destroy").checked = false;
                }
            });


    });

Cheers

Activity icon

Replied to Sorting By Id

I had something like this before which worked for me

->orderByRaw('SOUNDEX(id), LENGTH(id), id asc')
Aug
06
2 months ago
Activity icon

Replied to AWS S3 Private Images

What I ended up doing was to build a route that shows the image via an id, and in the controller it then checks the user is authenticated and then changes the file to public from private and records it in the database. Ive then got a schedule running every minute that checks for opened images and sets any public files back to private. So basically it's setting the image as public for the user to view for 1 minute (or however long i want it to) and then setting it back to private.

$visibility = Storage::getVisibility('file.jpg');

Storage::setVisibility('file.jpg', 'public')

It's a bit of a long way of doing it, but it works for what i need at the moment. It's not getting used much, but buys me a little time till i find a better solution.

Aug
03
2 months ago
Activity icon

Replied to AWS S3 Private Images

Ah ok. Ill take a look into the IAM way.

Is there any other way of doing it with another service or public dir.

Activity icon

Started a new conversation AWS S3 Private Images

Hi. Im looking to create an app for a customer that shares files with their customers and was looking into using AWS S3.

Ive used S3 for a few different projects with images that weren't too sensitive (personal information etc), but for this one I need to make sure that only the logged in user that has permission to view the files can view them.

Ive uploaded a few test files as private but cant get them to show in the browser.

Theres obviously something im missing but what? Any help would be greatful.

Many thanks

Jul
26
2 months ago
Activity icon

Replied to Stripe Webhooks

Hi. Sorry forgot to mention I'm using "ultrahook" to post to the Webhooks controller. I know its hitting it as its saving to the log, just not running the Update user to database code.

Cheers

Jul
25
2 months ago
Activity icon

Started a new conversation Stripe Webhooks

Hi.

Im trying to get my webhooks sorted on the localhost. I can receive the Webhooks and log it into the logs but when i try to use the data, like update the user etc it doesn't do anything!

Heres one Webhook::

<?php

namespace App\Http\Controllers\Webhooks;

use App\Models\Common\Ledger;
use App\Models\User;
use Laravel\Cashier\Http\Controllers\WebhookController as CashierController;
use Log;
use Stripe\Stripe;
use Illuminate\Http\Response;

class StripeWebhooksController extends CashierController
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function __construct()
    {
        Stripe::setApiKey(config('services.stripe.secret'));
    }

public function handleCheckoutSessionCompleted($payload)
    {
        if ( ! $this->eventExistsOnStripe($payload['id'])) {
            return;
        }

        \Log::alert('checkout.session.completed');
        \Log::alert(json_encode($payload['data']['object']));

        // Save the customer_id to the user table
        $client_reference_id = json_encode($payload['data']['object']['client_reference_id']);

        User::where('id', $client_reference_id)->update([
            'stripe_id' => json_encode($payload['data']['object']['customer'])
        ]);

        return new Response('Payment Session Completed', 200);
    }

Any ideas?

Many thanks This should save the customer object to the user database. If i log the client_reference_id to the Log, it is correct and it finds the user.

Jun
12
4 months ago
Activity icon

Started a new conversation Firefox Content Security Policy

Hi. Im in the middle of updating the Stripe payments and found an issue when it redirects to the payments page.

Im getting Content Security Policy: The page’s settings blocked the loading of a resource at eval (“script-sr

It only happens in Firefox and works perfect in chrome and safari.

Ive added a meta header <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' http://* 'unsafe-inline'; script-src 'self' http://* 'unsafe-inline' 'unsafe-eval'" /> to see if that works but nothing...

Any ideas?

Cheers

Jun
11
4 months ago
Activity icon

Replied to New CSS Only Updates When Hard-refreshing(ctrl + F5)

Its to do with the browser. I went mad trying to figure out why my css wasnt updating when changed. Turned out Chrome and Safari caches the css and js files. Depending on which you use you can disable it to cache that url.

Jun
10
4 months ago
Activity icon

Replied to Auth Login Shows 419 Page Expired On POST Request

I think this is the same as what i had on an app previously. But what i done was catch the error in the Handler.php file and then redirect back with a message.

public function render($request, Exception $e)
    {

        if ($e instanceof \Illuminate\Session\TokenMismatchException)
        {
            return redirect()
                    ->back()
                    ->withInput($request->except('password'))
                    ->with([
                        'status' => 'Oops! Your Validation Token has expired. Please try again',
                        'alert' => 'danger']);
        }   

        return parent::render($request, $e);
    }
Jun
05
4 months ago
Activity icon

Replied to Redirecting Non-www To Www

Figured it out...

Cheers all for your help.

It turned out that it was trying to redirect non http instead of the https.

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
server_name .my-app.com;
    rewrite ^(.*) https://www.my-app.com permanent;

        # FORGE SSL
}

This has worked for me

Activity icon

Replied to Redirecting Non-www To Www

Hi @johnbraun. Thanks for the reply.

Im not too good with nginx and try to stay clear of it as best i can but I gave it a try and it didn't change anything on that.

Heres what I tried and its more than possible I have it wrong lol...

server {
    server_name my-app.com;
    return 301 http://www.my-app.com$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name .my-app.com;
    root /home/forge/my-app.com/public;

    # FORGE SSL (DO NOT REMOVE!)

Am i right in saying that the server is basically a block for that server_name? So if i use www.my-app.com and admin.my-app.com i can pass through seperate redirects and so on.

I.e.

// Deals with non-www
server {
    server_name my-app.com;
    return 301 http://www.my-app.com$request_uri;
}

// Deals with www
server {
    server_name www.my-app.com;
    rewrite ^/registration.php /registration permanent;
        rewrite ^/login.php /login permanent;
}


// Deals with admin
server {
    server_name admin.my-app.com;
}

Cheers

Jun
04
4 months ago
Activity icon

Replied to Redirecting Non-www To Www

Hi @cronix. Cheers for the reply.

Ive got it redirecting the http to https already through nginx, but the issue I have is the app was setup in such a way that the routes splits it into subdomains, i.e. the front-end is www.my-app.com and the admin route is admin.my-app.com. I was hoping to find a way to do it in the nginx config but, I'm not so confident in poking around in the files.

I was hoping if there was a way in nginx to check if the uri has a www or admin before the .my-app.com and then if there is no www or admin just redirect to www, if that makes any sense at all...

When I add a redirect into nginx for non-www to www, if I goto admin.my-app.com it redirects to www.my-app.com.

Route::domain('www.my-app.com')->group(function () {
    // Front-end Routes
});

Route::domain('admin.my-app.com')->group(function () {
    // Admin Routes
});
Activity icon

Started a new conversation Redirecting Non-www To Www

Hi. I've got an app which uses subdomain for the backend (admin.my-domain.com) and the frontend which is (www.my-domain.com) But if i goto my-domain.com without the www it will hit a 404.

I added a middleware to my 'web/routes.php' which handles the frontend pages to redirect to www but this doesn't work for some reason.

// Middleware file

if (App::environment('production')) {

    $host = $request->header('host');
    if (substr($host, 0, 4) != 'www.') {
        $request->headers->set('host', 'www.' . $host);
                return Redirect::to($request->path(), 301);
            }

 }
return $next($request);

// Route/Web.php

Route::domain(config('settings.routes.domain'))->middleware(['redirect_to_www', 'redirect_if_logged_in'])->group(function () {
//
});

What would be the best way to have it check and redirect the frontend pages.

Cheers

Apr
25
5 months ago
Activity icon

Replied to Syntax Error Or Access Violation: 1075 Incorrect Table Definition

Hi @devfrey. I checked it over this morning and found that it was due to me adding a length to the "tag_number" integer.

Changed $table->integer('tag_number', 11)->nullable(); to $table->integer('tag_number')->nullable(); and it worked. Im still not quite sure why, im sure i used to put a length into the integer before! May be my old age lol.

Many thanks

Apr
24
5 months ago
Activity icon

Started a new conversation Syntax Error Or Access Violation: 1075 Incorrect Table Definition

Hi.

Im trying to setup a migration which on delete cascades but i keep getting the error::

SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key (SQL: create table `stock_list` (`id` bigint unsigned not null auto_increment primary key, `user_id` int unsigned not null, `name` varchar(255) null, `tag_number` int null auto_increment primary key, `notes` text null, `created_at` timestamp null, `updated_at` timestamp null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

Heres my migration for the stock_list::

Schema::create('stock_list', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedInteger('user_id');
            $table->string('name', 255)->nullable();
            $table->integer('tag_number', 11)->nullable();
            $table->text('notes')->nullable();
            $table->timestamps();

            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        });

I don't quite understand why this error is popping up and on another project which this was copied and pasted from (BirdBoard Tutorial) it works perfect)

Any help would be grateful

Cheers

Apr
11
6 months ago
Activity icon

Replied to Valet Issues

Found a solution.

It looks like apache was running in the background which I think was stopping it from loading nginx etc.

Heres a link for some troubleshooting​ guides.

https://gist.github.com/adamwathan/6ea40e90a804ea2b3f9f24146d86ad7f#problem-im-getting-a-502-bad-gateway-error

After stopping apache and restarting valet it all worked.

Activity icon

Started a new conversation Valet Issues

Hi.

For some reason yesterday, I switched my machine on and none of my test sites worked. I got the message "Failed to open page", "Safari cannot connect to the server".

I checked 'brew services list' and found that some are yellow and some are green. dnsmasq, nginx, php and redis are the ones in yellow and the rest are green. Yellow normally means it cannot get the status. All has been working perfectly​ up until​ yesterday. Nothing has changed on the system.

dnsmasq   started root       /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
[email protected] started root       /Library/LaunchDaemons/[email protected]
nginx     started root       /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
php       started root        /Library/LaunchDaemons/homebrew.mxcl.php.plist
[email protected]   started            /Library/LaunchAgents/[email protected]
redis     started root        /Library/LaunchDaemons/homebrew.mxcl.redis.plist

Things I've​ tried:

  • Update composer global
  • update brew
  • valet install
  • valet restart
  • Unlink from brew and install again

Nothing seems to have worked. Yesterday I switched the machine back of and then back on again and all was working, till this morning when I tried to access a different project and im getting the same as yesterday.

Any ideas?

Cheers

Mar
30
6 months ago
Activity icon

Replied to This Connection Is Not Private

The only solution I can find is to use anything Firefox and then import the Valet certificate. https://github.com/laravel/valet/issues/296

Activity icon

Replied to This Connection Is Not Private

I tried Firefox and chrome but same issue. I've un-secured the project and resecured and still the same Heres a more detaild error from firefox

myapp.test uses an invalid security certificate. The certificate is not trusted because the issuer certificate is unknown. The server might not be sending the appropriate intermediate certificates. An additional root certificate may need to be imported. Error code: SEC_ERROR_UNKNOWN_ISSUER
Activity icon

Started a new conversation This Connection Is Not Private

Hi. Im using Safari and in the last few days, not sure if there was an update or what, but all my .test sites I have which are served by valet are now showing "This Connection Is Not Private" warning.

I've done the usual thing and "trust All" for the certificates but nothing seems to work. I just cannot access any of my .test sites through Safari. I know i can use Firefox or Chrome but I just like Safari .

Anyone else had this issue.

Feb
20
7 months ago
Activity icon

Replied to Not Ordering OrderByRaw('SOUNDEX(username), LENGTH(username), Username Desc')

Ive tried several variations of

orderByRaw('SOUNDEX(username), LENGTH(username), username desc') 

but as an example If i am at user BT101 (last of the BT users) and then click previous, I would expect to get the last of the A users, so in this case A1476, but it doesnt. It jumps straight to A989 which is correct in terms of its the last user in that order if it was in numerical.

Feb
19
7 months ago
Activity icon

Started a new conversation Not Ordering OrderByRaw('SOUNDEX(username), LENGTH(username), Username Desc')

Hi.

I'm having an issue when trying to order the users by username and using as a next / previous button!

I am using view composer to populate a sidebar that has a previous and next button.

I then get the current id from the URL segment and find the current user.

How i want them ordered is by Username as follows :::

A001 A009 A110 A212 A330 A789 A982 A1012 A1234

BT001 BT009 BT110 BT212 BT330 BT789 BT982 BT1012 BT1234

SA001 SA009 SA110 SA112 SA330 SA789 SA982 SA1012 SA1234

etc...

But they're not showing up like this. They either go from A1500 to A150 or when it get to the next row of usernames it just goes back the the start.

Here's the code i have already:::

 $user = Auth::user();
        $id = request()->route('id');
        $customer = User::where('id', $id)->first();
        $mail_centre_id = MailCentreHelper::get_mail_centre_id();


          
        $previous = User::where('username', '<', $customer->username)
                ->findMailCentre($mail_centre_id)
                ->orderByRaw('SOUNDEX(username), LENGTH(username), username desc')
                ->status([1,2,3,4,5,6,9])
                ->pluck('id')
                ->first();

          $next = User::where('username', '>', $customer->username)
                ->findMailCentre($mail_centre_id)
                ->orderByRaw('SOUNDEX(username), LENGTH(username), username asc')
                ->status([1,2,3,4,5,6,9])
                ->pluck('id')
                ->first();

Any help or ideas would be grateful..

Many thanks

Feb
07
8 months ago
Activity icon

Replied to Urgent Help Needed, Even Google Couldn't Answer- Please Help. Laravel Test Fails..

Have you checked the test .env file. When you run tests, it creates a separate .env file to run.

You can create a .env.testing file to add your credentials etc for the test environment.

https://laravel.com/docs/5.7/testing

Thats my only idea on it i think. :)

Activity icon

Replied to QueryException In Connection.php Line 770:

Looking at the result it may be its not passing 'stream_id' through.

If you don't need the stream_id (which looks like you may do) then you can set it to null in the database or nullable() in the migration.

Jan
30
8 months ago
Activity icon

Replied to Looping Through A Json Object?

Sorry for the late reply. I don't seem to be getting any emails from Laracast!

I have done as you have here but I'm​ getting `Cannot use object of type stdClass as arr

The one thing which I need to try and get working is that telephone etc can change. I.e. it may be name or address etc Ive tried so many different things to try to get it to work that im at a loss.

I like the Accessors, I've ​learned​ something new :)

Jan
29
8 months ago
Activity icon

Replied to Looping Through A Json Object?

Ok im pretty confused.

Ive tried to access

{
"type":"account",
"old":{
    "telephone":"12345678",
    "email":"[email protected]"
},
"new":{
    "telephone":"12345678333",
    "email":"[email protected]"}
}

By using

// Get the record
$data = CustomerActivity::where('user_id', $user->id)->get();
$activities = json_decode($data);


// In blade
@foreach($activities as $activity)
<tr>
    <td>{{ \Carbon\Carbon::parse($activity->created_at)->format('d/m/Y H:i:s') }}</td>
    <td class="textLeft">
         <strong style="text-transform: capitalize;">Old</strong>:: {{ $activity->data }} <br>
        {{-- <strong style="text-transform: capitalize;">New</strong>:: {{ $activity->data['new']['telephone'] }} --}}
    </td>
</tr>
@endforeach 

// The dd output
array:1 [▼
  0 => {#822 ▼
    +"id": 29
    +"user_id": 447
    +"data": "{"type":"account","old":{"telephone":"123456783","email":"[email protected]"},"new":{"telephone":"123456783333","email":"[email protected]"}}"
    +"old": null
    +"new": null
    +"type": null
    +"created_at": "2019-01-28 15:27:32"
    +"updated_at": "2019-01-28 15:27:32"
  }
]


// What I have tried
{{ $activity->data->new['telephone'] }}
{{ $activity->data['new']['telephone'] }}
{{ $activity['data']['new']['telephone'] }}
{{ $activity['data']->new['telephone'] }}
// Also user the $activity[0] etc.. Cant remember what gave me the 'data'. I think it was if I returned the {{ $activity->data }} in the view when sending as a JSON object.


But none seem to work. I know in the grand scheme of it all it will need to be a $key, $val instead of the telephone as it will be dynamic, but if I can get it working then I'll have a bit of a chance.

Is there any Laracast videos which go into this in detail? Or can someone help with this.

Many thanks

Jan
28
8 months ago
Activity icon

Replied to Looping Through A Json Object?

Hi @mikemacdowell.

Thank you for your reply. I forgot to reword the post. I changed the database to grab the encoded json and add it all like so::

$data = json_encode([
            'type' => 'account',
            'old' => [
                'telephone' => Auth::user()->details->telephone,
                'email' => Auth::user()->email
            ],
            'new' => [
                'telephone' => $request->get('telephone'),
                'email' => $request->get('email')
            ]
        ]);

which produces {"type":"account","old":{"telephone":"12345678","email":"[email protected]"},"new":{"telephone":"12345678333","email":"[email protected]"}}

For whatever reason I cannot for the life of me get it to display the correct data.

Many thanks

Activity icon

Started a new conversation Looping Through A Json Object?

Hi., Sorry I don't do much with JSON and am trying to learn/use it more to learn.

I wanted to add a custom activity tracker to a small test project I have that tracks the old and new values from a webform. So if a user updates their phone number it logs the old value and the new one.

The way it works at the moment is that when an user saves their details, It grabs the old data and the new data and saves it to the database under data column::

public function saveActivity($request)
    {
       $data = json_encode([
            'type' => 'account',
            'old' => [
                'telephone' => Auth::user()->details->telephone,
                'email' => Auth::user()->email
            ],
            'new' => [
                'telephone' => $request->get('telephone'),
                'email' => $request->get('email')
            ]
        ]);
        $activity = Helpers::saveUserActivity($data);
    }

// Result

// {"type":"account","old":{"telephone":"12345678","email":"[email protected]"},"new":{"telephone":"12345678333","email":"[email protected]"}}

this saves the data into the data field along with the authenticated user id.

What I can quite get my head around is displaying it on a blade template.

The issue I think I'm going to get is if theres a different types which I want to filter and there will be different fields depending on the type.

Can someone point me in the right direction with this one.

Many thanks

Jan
24
8 months ago
Activity icon

Replied to Validation Issue?

Just checked and im not passing through the public $validator;

So should look like

public $validator;


**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'courier_id' => 'required_if:send_by,4|numeric',
        ];
    }

    /**
    * Overrid Handle a failed validation attempt.
    *
    * @param  \Illuminate\Contracts\Validation\Validator  $validator
    * @return void
    *
    * @throws \Illuminate\Validation\ValidationException
    */
    protected function failedValidation(\Illuminate\Contracts\Validation\Validator $validator)
    {
        $this->validator = $validator;
    }
Activity icon

Replied to Validation Issue?

Ah ok. Strange as it works on other validation. Ill have to go back and double check that its the same as the others and not been changed ...

Cheers

Activity icon

Started a new conversation Validation Issue?

Hi. Im getting an odd issue where I cannot validate inputs.

When trying to add a required_if attribute to the courier_id field it comes back ass a pass.

The strange thing is, if I make it a required field it also passes.

Controller (for testing)::

public function store(StoreDespatchRequest $request, User $user)
{
        if (isset($request->validator) && $request->validator->fails()) {
            Toaster::danger("It looks like there is a problem!!");
            return redirect()->back()->withErrors($validator)->withInput();
        }
        return $request->all();
}

StoreDespatchRequest::

**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'courier_id' => 'required_if:send_by,4|numeric',
        ];
    }

    /**
    * Overrid Handle a failed validation attempt.
    *
    * @param  \Illuminate\Contracts\Validation\Validator  $validator
    * @return void
    *
    * @throws \Illuminate\Validation\ValidationException
    */
    protected function failedValidation(\Illuminate\Contracts\Validation\Validator $validator)
    {
        $this->validator = $validator;
    }

View::

<div class="row despatchSection">
            <label class="inlinelabel">SEND BY</label>
            <select class="despatchSelect" name="send_by" id="send_by">
                @foreach($forwarding_by as $sent_by)
                <option value="{{ $sent_by->id }}" @if($customer->forwarding->forward_by_id == $sent_by->forward_by_id) selected @endif>{{ $sent_by->title }}</option>
                @endforeach
            </select>
        </div>

        <div class="row despatchSection" name="courier">
            <label class="inlinelabel">COURIER</label>
            <select class="despatchSelect" name="courier_id" id="courier">
                <option value=""></option>
                @foreach($delivers_by as $deliver_by)
                <option value="{{ $deliver_by->id }}">{{ $deliver_by->title }}</option>
                @endforeach
            </select>
        </div>

Response::

{
_token: "uXeep3ih8wZeifdq4NpB51syruMZpYjq3EySnPy8",
letters_out: "2",
large_letters_out: "0",
parcels_out: "0",
send_by: "4",
courier_id: null,
tracking_ref: null,
postage_cost: "1",
total: "3.80"
}

Any ideas on why its not picking up null and passing the request

Jan
09
9 months ago
Activity icon

Replied to Spatie Backup And Mysqldump

Hi @snapey. It's running under root. I'm presuming it has the correct rights to see the folder, its all set up using Forge. The rest of the crons work.

Activity icon

Replied to Spatie Backup And Mysqldump

Ye that command works perfectly. This is what's confusing me!

Activity icon

Replied to Spatie Backup And Mysqldump

Hi @dalma. Ye sure, In the config it has an array to specify a disk to backup to so

'destination' => [

         /*
          * The disk names on which the backups will be stored.
          */
         'disks' => [
             'local',
         ],
     ],

I have it set to ftp. and the connection is good and all works when running the backup via the console.

Activity icon

Started a new conversation Spatie Backup And Mysqldump

Hi. Im getting an error when backing up to an ftp server through a task schedule.

The error is ::

Exception message: The dump process failed with exitcode 127 : Command not found : sh: 1: /usr/bin/mysqldump: not found

Now i know its installed because, well I installed it and i can run it from /usr/bin/mysqldump and if i run the command to backup from ssh it also works fine. But when its scheduled it just keeps failing.

On my testing server which is an exact duplicate of the production server, it works perfectly!

Heres some of the code:::

Kernel.php

$schedule->command('backup:run --only-db')->everyThirtyMinutes()->environments(['production']); // set to 30min for testing...

config/database.php

'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
            'dump' => [
                'dump_binary_path' => '/usr/bin',
            ]
        ],

Any ideas. According to spatie its a server config issue but if I can run it via the command line on the server, surely it should work from the schedule...

Cheers

Jan
06
9 months ago
Activity icon

Replied to OrderBy Not Quite How I Want It!

Ah, thank you, guys. I'll try that in a bit and report back.

Jan
05
9 months ago
Activity icon

Replied to OrderBy Not Quite How I Want It!

Hi @snapey They go from A then BT, TF so Laravel is doing as it should but is there a way to order them by the string and numeric so its like so::

A101 A102 A111 A1101 BT101 BT134 TF455 TF456 etc.

whats happening at moment is

A101 A1001 A1002 A102 A1020

BT101 BT134 TF455 TF456

Cheers

Activity icon

Started a new conversation OrderBy Not Quite How I Want It!

Hi.

I have a search query which grabs all the users and orders them by username.

In the search i use ->orderBy('username', 'asc') which will order them to a point...

The issue I'm getting is if say username is, A100 and then there's A1000 its order is then A100, A1000, A1001, A1002 etc and later when it gets to A110 it then goes A1100 etc.

Is there a way to order them correctly.

Cheers

Jan
03
9 months ago
Activity icon

Replied to Strip .php From Url

Ok so after a lot of digging around and learning about Nginx i found a solution...

In the nginx config file i added ::

rewrite ^/registration.php /registration permanent;

This works perfectly.

Activity icon

Replied to Strip .php From Url

Sorry, Ive tried all sorts now and it fails on the Forge Digital ocean server using Nginx...

Locally it works perfect using Valet but as soon as its on the DO server i get No input file specified.

I cannot figure it out at all. Any ideas??

This is my middleware that catches all requests ::

public function handle($request, Closure $next)
    {
        if (str_contains($request->url(), '.php')) {
            $url = str_replace('.php', '', $request->url());
            return redirect($url);
        }
        return $next($request);
    }

Cheers

Dec
31
9 months ago
Activity icon

Replied to Strip .php From Url

Would that go in the

server {
$withoutExt = preg_replace('/\.[^.\s]{3,4}$/', '', $filename);
}

EDIT!!!! Sorry just clicked!!!!

Ill give that a go... Cheers

Activity icon

Replied to Strip .php From Url

Thank guys. Im using nginx on forge. Im not going to lie but ive not used nginx before and a liitle afraid of messing with it.

But as a fix for now, I made a middleware to process the request and check for the extention and remove it then redirect to the correct location

if (str_contains($request->url(), '.php')) {
            $url = str_replace('.php', '', $request->url());
            return redirect($url);
        }
Activity icon

Replied to Forward Non Www To Www In Forge?

Sorry. Ive got a workaround for now...

I created a middleware to deal with the request.

public function handle($request, Closure $next)
    {
        if (str_contains($request->url(), 'https://my-app.uk')) {
            return redirect('https://www.my-app.uk');
        }
        return $next($request);
    }

Happy new year everyone :)

Activity icon

Replied to Strip .php From Url

I have a URL on some old site links that at the moment usehttps://www.my-app.com/regestration.php, on the new app that should be going to https://www.my-app.com/regestration so by removing the .php from the end it will return the correct url.

Activity icon

Replied to Forward Non Www To Www In Forge?

Hi, thank you for the reply. I tried that but unfortunately due to restrictions to the way the servers and old app was set up, I have some code that distinguishes the environment then sets the subdomains.

if (App::environment('local')) {
    $sub = '';
    $domain = 'my-app';
    $tld = '.test';
} elseif (App::environment('testing')) {
    $sub = 'testing.';
    $domain = 'my-app';
    $tld = '.uk';
} elseif (App::environment('production')) {
    $sub = 'www.';
    $domain = 'my-app';
    $tld = '.uk';
}

Route::domain($sub . $domain . $tld)->group(function () {
    Route::get('/testing', 'TestsCo[email protected]');
    Route::post('/testing', '[email protected]');
    Route::middleware(['guest'])->group(function () {
        Route::get('/{page?}', 'Frontend\[email protected]');
    });
});

Makes it a little more interesting lol.

Activity icon

Started a new conversation Forward Non Www To Www In Forge?

Hi how do i forward requests to a certain routes file to www?

Many thanks