drewdan

PHP Engineer at Talkative Ltd

Member Since 1 Year Ago

Newport

Experience Points
50,850
Total
Experience

4,150 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
209
Lessons
Completed
Best Reply Awards
39
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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 11
50,850 XP
Aug
07
1 week ago
Activity icon

Replied to Filtering And Sorting A Collection

@silencebringer thank you for your answer, there were some issues as it only gave me the first value, not the entire series. But it got me to a solution.

@michaloravec - as always, perfect marks. Thank you kindly. I am still getting to grips with all of the collection methods.

Ta both :)

Activity icon

Started a new Conversation Filtering And Sorting A Collection

Hey guys, I have a Collection which looks like this:

Illuminate\Support\Collection {#1545 ▼
  #items: array:8 [▼
    0 => array:1 [▼
      "Colour" => "Pink/lwhite"
    ]
    1 => array:1 [▼
      "Colour" => "blue/white"
    ]
    2 => array:1 [▼
      "Colour" => "white/cream/green"
    ]
    3 => array:1 [▼
      "Colour" => "other (please specify)"
    ]
    4 => array:1 [▼
      "price" => "Standard"
    ]
    5 => array:1 [▼
      "price" => "Medium"
    ]
    6 => array:1 [▼
      "price" => "Large"
    ]
    7 => array:1 [▼
      "price" => "Extra Large"
    ]
  ]
}

The array has been built from some data sources and I was hoping to flatten it down just have an array with the two keys and the associated values. But I cannot seem to find a nice way to do it. Are there any collection helpers which might be a good fit to help me with this?

I thought mappingWithKeys() would do the trick, but I could not get it to work. Any tips and suggestions would be great.

Thanks, Andrew

Jul
07
1 month ago
Activity icon

Replied to How To Resolve "return Abort(401)" Issue

I think you could leave this functionality in. And then use the @can helper method in the blade files to hide or show elements you dont want your users to click on if they do not have permissions

@can('leave_request_create')
	//some html here which only people with permission will see
@endcan
Activity icon

Replied to Testing Artisan Command Fails To Resolve Mocks

Noted, thing this is one I won't forget :D Thanks again :)

Activity icon

Replied to Testing Artisan Command Fails To Resolve Mocks

I could kiss you right now! That was it, I have spent ages trying to figure this out, mocking in 10 different ways. Thank you so much :D

Activity icon

Started a new Conversation Testing Artisan Command Fails To Resolve Mocks

Hi Guys,

I have a Artisan test which mocks a class, when I run the command, Laravel does not resolve the mock from the service container.

public function testHandle() {
		$company = Company::whereName('durham-cc')->first();
		factory(Interaction::class, 10)->create(['company_id' => $company->id]);
		$mock = $this->mock(DataTransferClient::class)
			->shouldReceive('uploadFile')
			->withAnyArgs()
			->once();
		app()->offsetSet(DataTransferClient::class, $mock);
		$this->artisan('interaction:durham-transfer')
			->assertExitCode(0);
	}

The command gets called, and in the constructor:

public function __construct(DataTransferClient $client, InteractionLogService $interactionLogService) {
		$this->client = $client;
		$this->interactionLogService = $interactionLogService;
	}

I am resolving the DataTransferClient - but the real client gets resolved instead of the mock.

Any ideas?

Jul
06
1 month ago
Activity icon

Replied to Queue Events To Run Consecutively

Could you dispatch a job from the event, with a delay of a few minutes? Make sure the job serializes the model, so by the time the job fires, event 1 will be done, the model will be rehydrated, and the appointment can be associated with the order?

Activity icon

Replied to HTML5 Datalist Not Working

P.s apologies for the linting

Activity icon

Started a new Conversation HTML5 Datalist Not Working

Hey Guys, I am trying to use a datalist to give users suggestions when they complete a form, however, it does not seem to work:

@extends('layouts.app')
@section('content')
	<div class="container my-3">
		<div class="row justify-content-center">
			<div class="col-md-8">
				<div class="card">
					<div class="card-header">Register for an account</div>
					<div class="card-body">
						<div class="alert alert-info">
							<p>Before you can use our website to book events you must create an account. Registration is
								free
								and can be done by completing the form below.</p>
							<p>Once your account has been setup, you may apply for a "Club" account to book events and
								manage
								club subscriptions.</p>
							<p>If you are a parent, please use your name and contact details here. You will be able to
								add
								children into your bookings separately.</p>
						</div>
						<form method="POST" action="{{ route('register') }}">
							@csrf
							<div class="form-group row">
								<label for="name" class="col-md-4 col-form-label text-md-right">{{ __('Name') }}</label>

								<div class="col-md-6">
									<input id="name" type="text"
									       class="form-control @error('name') is-invalid @enderror" name="name"
									       value="{{ old('name') }}" required autocomplete="name" autofocus>

									@error('name')
									<span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
									@enderror
								</div>
							</div>

							<div class="form-group row">
								<label for="email"
								       class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>

								<div class="col-md-6">
									<input id="email" type="email"
									       class="form-control @error('email') is-invalid @enderror" name="email"
									       value="{{ old('email') }}" required autocomplete="email">

									@error('email')
									<span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
									@enderror
								</div>
							</div>

							<div class="form-group row">
								<label for="name" class="col-md-4 col-form-label text-md-right">Contact Number</label>

								<div class="col-md-6">
									<input id="name" type="text"
									       class="form-control @error('contact_number') is-invalid @enderror"
									       name="contact_number"
									       value="{{ old('contact_number') }}" required autocomplete="contact_number"
									       autofocus>

									@error('contact_number')
									<span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
									@enderror
								</div>
							</div>

							<div class="form-group row">
								<label for="club" class="col-md-4 col-form-label text-md-right">Club</label>

								<div class="col-md-6">
									<input
								        class="form-control @error('club') is-invalid @enderror"
								        name="club"
								        list="club_list"
								        autocomplete="off"
						            >

									<small>Start typing the name of your club, if it is already in our system, it will
										appear in the suggestions list below. If not, please try the full correct name
										for the club
										and we will add this club to our database.</small>
									<datalist id="club_list">
										<option value="test">Test</option>
									@foreach($clubs as $club)
										<option value="{{ $club->name }}">{{ $club->name }}</option>
									@endforeach
									</datalist>

									@error('club')
									<span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
									@enderror
								</div>
							</div>

							<div class="form-group row">
								<label for="password"
								       class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>

								<div class="col-md-6">
									<input id="password" type="password"
									       class="form-control @error('password') is-invalid @enderror" name="password"
									       required autocomplete="new-password">

									@error('password')
									<span class="invalid-feedback" role="alert">
                                        <strong>{{ $message }}</strong>
                                    </span>
									@enderror
								</div>
							</div>

							<div class="form-group row">
								<label for="password-confirm"
								       class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</label>

								<div class="col-md-6">
									<input id="password-confirm" type="password" class="form-control"
									       name="password_confirmation" required autocomplete="new-password">
								</div>
							</div>

							<div class="form-group row mb-0">
								<div class="col-md-6 offset-md-4">
									<button type="submit" class="btn btn-primary">
										{{ __('Register') }}
									</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
@endsection

This is essentially just a modified register.blade.php form. The datalist is being populated correctly. I just cannot work out where I am going wrong.

The form just shows the browser saved password prompts :/

Cheers Guys, Andrew

Activity icon

Replied to Queue Events To Run Consecutively

I do not believe you can. The idea behind queing events and jobs is that they should not be run in any sequence. Event 1 would have to be responsible for firing event 2 when event 1 completes.

Jun
18
1 month ago
Activity icon

Replied to Extending The Command Class

I did come across that one, but I lost the link lol. Thank you kindly :D

Activity icon

Replied to Extending The Command Class

Ah, did some more googling:

I can do it by making it an abstract class: https://www.php.net/manual/en/language.oop5.abstract.php

Activity icon

Started a new Conversation Extending The Command Class

Hey Guys,

I am about to add a new console command to my laravel application, the new command will be very similar to an existing command, so I thought it would be good to make another command called DataTransferCommand - this command would have functionality that both command classes would use, file transfer stuff. My plan was to then have both commands extending this base command however, when I try to run the command, the base command complains that it does not have a signature set. But I do not want to give it one as this class won't be run directly.

Any ideas as to what the best approach to this situation is? I was hoping to avoid using traits, but if thats the best way, I will go with that direction.

Cheers!

Jun
06
2 months ago
Activity icon

Replied to Vue Reactivity Issue

I think I have found the issue, and I have made it work, but done some really nasty hackiness stuff based on this article: https://logaretm.com/blog/2019-10-11-forcing-recomputation-of-computed-properties/

Bascially, the computed prop does not re-evaluate as nothing immediately has changed. So, if I give it something that I know will change, like iterating on a number, and everytime I remove something from the array, it causes the number to iterate then the computed prop will re-evaluate and update.

Its not my preferred solution, but will do the trick for now!

Thanks for your help @flor :)

Activity icon

Replied to Vue Reactivity Issue

This is the script inside the component:

<script>
	import { mapActions, mapGetters } from 'vuex';
	export default {
		props: {
			teamKey: {
				required: true,
				type: Number,
			},
		},
		data() {
			return {
				gymnast: {
					name: '',
					membership: '',
					dateOfBirth: '',
				}
			};
		},
		methods: {
			...mapActions([
				'addTeamMember',
				'deleteTeamMember',
			]),
			close() {
				this.$emit('close');
			},
			addGymnast() {
				this.addTeamMember({
					team: this.teamKey,
					gymnast: this.gymnast
				});
				this.gymnast = {};
			},
			deleteGymnast(gymnast) {
				this.deleteTeamMember({
					team: this.teamKey,
					gymnast: gymnast,
				});
			},
		},
		computed: {
			...mapGetters({
				teams: 'teams',
			}),
			team() {
				return this.teams[this.teamKey];
			},
		},
	};
</script>

so the computed getter is returning the teams from the state, and then the team() is getting the specific team using the key.

Open to suggestions of better ways, as I drew a blank when trying to put this together

Activity icon

Replied to Where To Store OAUTH Token

Gonna choose this as best answer, it makes the most sense and it is a good pattern to follow. Cheers for the advice :D

Activity icon

Replied to Vue Reactivity Issue

I tried that approach, but with no success I am afraid. It certainly updates the state, but the dom does not change to represent it still.

The initial state looks like this:

const state = {
	teams: [],
	leadCoach: null,
	coaches: [],
	judges: [],
	user: {},
};

Then a user adds a team, and then adds members to the team which gets this (copied from vue dev tools):

teams:Array[1]
0:Object
ageGroup:"mini"
level:"large"
members:Array[2]
0:Object
dateOfBirth:"2021-06-07"
membership:"123456789"
name:"Joe Blogs"
1:Object
dateOfBirth:"2019-05-05"
membership:"123456789"
name:"John Jones"
name:"Team Here"

The copy and paste is a bit iffy, but maybe this adds a little more context.

So I tried to update the entire object after splicing, but it just does not seem to like it

Activity icon

Started a new Conversation Vue Reactivity Issue

Hey Guys, I am trying to delete an element in a nested array in Vue/Vuex, and the array does not exist until after it is created dynamically:

DELETE_TEAM_MEMBER(state, { team, gymnast }) {
	state.teams[team].members.splice(gymnast, 1);
},

This works, and the element gets deleted, but the reactivity does not seem to work.

I know you can use Vue.set to add items where the reactivity does not happen by default, but if there a way to force reactivity when unsetting something?

Cheers Guys :)

Jun
03
2 months ago
Activity icon

Awarded Best Reply on Laravel Access Forbidden For Https

Have you setup a vhost entry for the ssl website on port 443? If memory serves you would need a second entry to map the ssl port and make sure it points to the correct directory.

Jun
02
2 months ago
Activity icon

Replied to Laravel Access Forbidden For Https

Have you setup a vhost entry for the ssl website on port 443? If memory serves you would need a second entry to map the ssl port and make sure it points to the correct directory.

May
29
2 months ago
Activity icon

Replied to Where To Store OAUTH Token

My thought was, the user would do this once, so it felt a bit clunky to store a token in the database, push something to GTM, and then keep the token. Surely if I needed it, I could just get them to reauth? Rather than saving it for something they may edit once a year, maybe a little more frequently.

May
28
2 months ago
Activity icon

Started a new Conversation Where To Store OAUTH Token

Hey Guys,

I am not sure of the best approach to take here.

I am integrating with Google Tag Manager, and I am wondering what the best approach to take is.

I want the user to be able to login to their Google Account via OAUTH and then have their GTM configuration displayed. The goal is to add something to their GTM account specific to our application and then they no longer need to use the integration unless they wish to change something in future. For which I would want them to reauth.

So, my question is, how do I store the $token to use it during the configuration process. Should it be a session variable? Stored in the cache? I do not want to make a database change for this feature, so would rather not store it in the database.

Any thoughts or insight would be swell :)

Cheers Guys!

Activity icon

Replied to Google API With User Password Auth Rather Than Key

Worked a treat! Ta very much!

Activity icon

Replied to Google API With User Password Auth Rather Than Key

It is oauth2! I thought it was. I think 🙃

I'll have a good read through now. Thank you kindly :)

Activity icon

Replied to User Specific Slack Notifications

The $notifiable should be the current user being notified? And I guess you have the slack webhook url stored in the database for that user?

Is that what you are trying to do here?

Activity icon

Started a new Conversation Google API With User Password Auth Rather Than Key

Hey Guys,

I am trying to build an integration into Google Tag Manager.

Currently, the application I am working with integrates into many google services such as translate and we use the google credentials json file for this.

What I want, is the for the user to visit a page, and they will be presented with a google login prompt, this will then be authenticated and they will be presented with a list of their google tag manager containers and they go from here.

The idea is anyone can login and use this, without needing to have a google cloud account etc.

I am struggling to find documentation on how to do this, mainly because I think I am getting terminology confused. Has anyone seen any documentation/article/tutorials on doing such a thing please?

Cheers! :)

Activity icon

Replied to Import Excel With Value

Help you how? If you wanna show us the code you have written so far and tell us where you are stuck, we can help that way

May
27
2 months ago
Activity icon

Replied to Import Excel With Value

Have you tried using the Laravel Excel package? It's great for uploading and exporting excel spreadsheets

Activity icon

Replied to Https Redirection Is Not Working...

What URL does your app have in the .env file? Has that been set to HTTPS?

Activity icon

Replied to Javascript Stopped Working

Are you pulling in any external libraries? Could any of them have been updated? Maybe to a new major version which had breaking changes?

Activity icon

Replied to How Add Permission To Storage Directory ?

I think you need to change the owner of your storage folder. This error is because the blade files cannot be compiled and stored. It looks like root has ownership of the directory, I think it should be www-data. Are you doing this all in command line? Or do you have a gui to change owners and permissons?

May
26
2 months ago
Activity icon

Replied to I Have An Old Project Using Laravel 5.5 Should I Upgrade To 6.0 Or 7.x?

It's always good to be on the latest version, better security, access to the latest functionality. Enhancments for the latest PHP version too!

Activity icon

Replied to I Have An Old Project Using Laravel 5.5 Should I Upgrade To 6.0 Or 7.x?

Use the upgrade guides to upgrade to 6 and then upgrade to 7. Do it in steps to make it easier or use Laravel Shift - https://laravelshift.com/ it's only a small expense and it's handled form you :)

Activity icon

Replied to Mailable Timeout And Partial Delivery Issues?

It's tricky to diagnose without further information from the mail server. If it is timing out, I'd have expected some log entry on their mail server to say why it timed out.

Might be worth switching the mail provider to mailtrap and recreating the conditions in which the mail sending fails, if you cannot recreate it, then the onus is on their IT contracts to identify the issue then

Activity icon

Replied to Mailable Timeout And Partial Delivery Issues?

Ok, so in those emails, how many recipients are there? 3? Would that make your count higher?

I'm not sure what email server you are running, but on my postfix server, I have loads of strange limits, limit the amount of emails, the amount of client connections per minute, the amount of recipients per minute. So my server can handle large volumes of mail, just not all from the same user at once.

Normally with emails, it's to me a case of, I send it to the email server, if the email server gets it, happy days, that's my worries done, if it fails at this point it's the hardware guys issue. Of course we try catch the emails and if they fail because of something, we report that, but I've never known an email server to accept an email, send to the recipient and cc, but bomb out on the bcc.

Are you running postfix?

Activity icon

Replied to Trait Vs Hepler In Laravel

Yeh, what @martinbean said. I think that's pretty spot on

Activity icon

Replied to Mailable Timeout And Partial Delivery Issues?

How many emails are firing out at once? Could the mail server be getting overwhelmed?

Activity icon

Replied to Use 1 Facade For All Functions

You'd still have to use $this->theme every time you tried to return a view though wouldn't you. Though that is still better than making a custom facade :)

Activity icon

Replied to Use 1 Facade For All Functions

Excellent, yeh, it's just a more natural way to pull a theme depending on the env/config setting.

Glad I could help :)

Activity icon

Awarded Best Reply on Use 1 Facade For All Functions

Can't you just use config('ordx.THEME.FRONTENDTHEME') in your blade partials. I'd assume you have something like app.blade.php which your other blade files extend. So have different app.blade files and when you extend another blade file

@extend(config('ordx.THEME.FRONTENDTHEME');

I definitely don't think you need your own custom facade to return a view, you're trying to reinvent the wheel. You just need to change how you are using the wheel.

Activity icon

Replied to Use 1 Facade For All Functions

Can't you just use config('ordx.THEME.FRONTENDTHEME') in your blade partials. I'd assume you have something like app.blade.php which your other blade files extend. So have different app.blade files and when you extend another blade file

@extend(config('ordx.THEME.FRONTENDTHEME');

I definitely don't think you need your own custom facade to return a view, you're trying to reinvent the wheel. You just need to change how you are using the wheel.

Activity icon

Replied to How To Have Phpmyadmin On Nginx VirtualHost Ubuntu

This guide by digital ocean is really in depth and should step you through setting up a connection to your database with a selection of mysql clients :)

https://www.digitalocean.com/community/tutorials/how-to-connect-to-a-mysql-server-remotely-with-mysql-workbench

Activity icon

Replied to How To Have Phpmyadmin On Nginx VirtualHost Ubuntu

Do you currently access your server using secure shell with a public key?

Activity icon

Replied to Use 1 Facade For All Functions

Yeh, What?! What does your facade do differently to the View class?

Can you share your code with us?

Activity icon

Replied to Stripe Create Payment Method Client Side Vs Server Side

I'd recommend picking a convention and sticking with it. Personally I like doing stuff server side, seems a little more secure as people cannot see the code that's being executed, and you'd eventually need to hit the server to store some data too. So might as well do all of the grafting there.

I think the JavaScript library is more for non native web apps? And other front end focussed development. Though I'm not 100% sure on that

Activity icon

Replied to How To Have Phpmyadmin On Nginx VirtualHost Ubuntu

You would have to create another site, and install phpmyadmin into that directory. I guess there is probably an installer for it these days using composer.

Why not instead try using mysql community workbench and connect to your server with an SSH connection instead, it will be vastly more secure and one less thing to configure on your server

Activity icon

Replied to Question About Cache In Laravel 6 Or 7

The Facade is not a cache method, rather a way of accessing whichever Cache you are using without having to write code specific to that cache driver.

We use Redis, and we have a cache server of its own to handle cache data. In our case, without Caching, the database would not be able to cope with the massive amount of requests.

There are packages about to handle lots of caching for you - https://github.com/GeneaLabs/laravel-model-caching - this package for example will cache model queries, so if the same query is called, it will return the cached version, and the cache will automatically bust if the model changes.

Which one you should use it down to you. I have no experience with Memcache, but I think its much the same as Redis. Database just stores data in the database, this would only really be suitable for small applications, the idea being, it would reduce the amount of database calls, but a bigger call could be replaced with a smaller one.

Me personally, I use Redis in all my applications and would not bother with a database Cache unless I am working in a development environment.

Activity icon

Replied to How To Read Replies When Using Mailgun To Send Mails?

I always use mailgun for transactional email, typically, [email protected] Mailgun also suggests setting up a subdomain like mg.yourdomain.com to send mail from. Why do you need your visitors to reply? Is it something that needs to be tracked?

If it is not, I would just specify a reply to email in your email config, so when your users reply, it gets sent to a specific mailbox that you can monitor.

Activity icon

Replied to Laravel Testing - Can't Connect To DB On Unit Test (but Works Perfectly In Feature Test)?

Can you post a redacted version of your phpunit.xml file?