dancourse

dancourse

Member Since 4 Years Ago

at University of Warwick

Experience Points 3,485
Experience Level 1

1,515 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 40
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

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

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

09 Sep
2 years ago

dancourse left a reply on Subscription Renewal Without Notice

Cheers Nate @nate.a.johnson

I'll write up here if @jeffreyway responds

08 Sep
2 years ago

dancourse started a new conversation Subscription Renewal Without Notice

Hello @jefferyway

Laracasts has been an excellent tool for me and helped me no end in coding and understanding Laravel.

However I wasn't aware there was a renewal coming up and don't have that money (new 5 month old baby) or use the service right now.

Would you please cancel the renewal and refund the money please. I can't see how else to contact you about it expect through this forum?

Best, DanC

06 Nov
3 years ago

dancourse left a reply on How To Catch QueryException?

Any news on this one? I can't seem to catch mine either in Laravel 5.0

            try {
                $this->model->create($data);

            } catch (Illuminate\Database\QueryException $e) {
                dd($e);

            } catch (PDOException $e) {
                dd($e);
            }            
03 Nov
3 years ago

dancourse left a reply on Maximum Execution Time Of 30 Seconds Exceeded

Hi @Ci ,

There's a few ways to do it, (some borrowed from SO, http://stackoverflow.com/questions/7739870/increase-max-execution-time-for-php)

  1. Check if your script is doing something silly and taking ages when it shouldn't be, try dd($aVar);

  2. Increase the execution time at php.ini level, max_execution_time=300

  3. Use PHP at runtime to increase it, ini_set('max_execution_time', 300); //300 seconds = 5 minutes

  4. Use the .htaccess to increase it,

<IfModule mod_php5.c>
php_value max_execution_time 300
</IfModule>

#HTH

dancourse started a new conversation Testing Tips For Medium To Large Size Applications

Any good articles? Pro tips? Paid videos? Github links? Tutorials etc...?

The apps we're building are starting to reach a limit to how we are writing and maintaining tests in PHPunit and Behat.

We see lots of methods using the a pattern of tests (test their parameters only take certain types, check the types return are the types expected, test the results are ordered correctly, test they error when expected) and wondered if there's a way to speed that up. Because they take ages to write and don't totally seem to be following the DRY principle principle...

Also, we see that some tests PHPUnit are taking over 3000ms too, so any tips on slicking up setup and running would be great.

Basically, we've read articles and "gone at it" and now I think we need to see some better examples of good Laravel 5.0 / PHP testing setups.

Thanks for your help,

DanC

29 Oct
3 years ago

dancourse left a reply on How To Structure Model(s) With Many Similar Attributes?

Just a suggestion based on what I do.

I find certain groups of Models do share attributes, but they're also unique.

So I setup a file called App/ModelBase.php, with ModelBase extends Model. In that are my shared methods / attributes, then any similar Models I extend from that.

dancourse left a reply on Where Would You Fire An Event, In A Controller Or In A Repository?

I fire my events from within the repository method, then it's like. "YUP, that was created", then you don't have to remember to put the event EVERYwhere you use the create function.

Same with edit & destroy.

Then I use the EventServiceProvider to tie up any handlers from the event

14 Oct
3 years ago

dancourse left a reply on Stop The Daemon ! [URGENT]

Thanks @bashy so what you're saying is,

"Please know something you don't know before asking for help. I presume you didn't do enough work to solve this as it wouldn't have taken me long.

I've made an assumption you haven't tried to fix this yourself before posting to the board so will make sure you know you're dumb by suggesting, "a quick Google search", because I would have solved it quickly.

We're a friendly community that post a lot of articles about Linux."

Nice.

13 Oct
3 years ago

dancourse left a reply on Stop The Daemon ! [URGENT]

Thank you so much @ohffs ! You've totally helped me out

dancourse started a new conversation Stop The Daemon ! [URGENT]

Morning Laravel team,

Got a rather urgent issue I need resolving, I need to stop the --daemon Queue worker as the emails it is sending has a few issues!

On deployment, it is started with this, php artisan queue:work database --daemon; ` I wouldn't ever put URGENT in the title, but I really need to stop the Daemon!

Thanks very very much for what ever help you have.

Best,

Dan Course

06 Oct
3 years ago

dancourse left a reply on Stop Events Firing During Testing

Thanks again @pmall

Is there a version of that in Laravel 5.0 do you know?

Best, DanC

dancourse started a new conversation Stop Events Firing During Testing

Hello Team Laravel,

I'm running tests on a Repository methods, however some of the methods fire events which is slowing the tests (ie. email queue, write to log...)

Is there a way to kill all my Custom Events from the EventServiceProvider in the setup()? Or "Mock" the Events class so it's not real and never really fires?

Events::off() ? Events::sssshhh()?

Thanks,

DanC

23 Sep
3 years ago

dancourse left a reply on Gitlab CI, Homestead & Docker

You know, apparently after chatting with people here it turns

a) I did not understand docker, so I watched this, https://www.youtube.com/watch?v=pGYAg7TMmp0 b) I think you're right, the centos package does not install php by default, hence why it cannot see it

So you're marked as correct, but I hope people also read this for the YT video

11 Sep
3 years ago

dancourse started a new conversation Gitlab CI, Homestead & Docker

Hello Laravelians',

I'm trying to get Gitlab CI working for my Laravel 5.0 project but I'm a bit stuck! Anyone got an example Laravel gitlab-ci.yaml file they could share?

Here's one I'm trying but I'm a bit stuck, I think maybe I need to do something with with the image, however I keep just getting an error saying it doesn't know PHP?!

Thank you!

DanC

php -v
bash: line 27: php: command not found

Here's my script so far, I have tried some other docker images too, joostlaan/hhvm-laravel, dylanlindgren/docker-laravel-composer

image: centos7

before_script:
  - php -v
  - curl -s https://getcomposer.org/installer | php
  - cp ./config/pst.gitlab-ci.php ./config/pst.php
  - cp ./.env.gitlab-ci ./.env
  - php composer.phar install --prefer-dist --quiet
  - php composer.phar dump-autoload --quiet
  - php artisan key:generate
  - php artisan migrate --force
  - php artisan up

tests:
  script: "phpunit --stop-on-failure && behat -f progress --stop-on-failure"
31 Jul
3 years ago

dancourse left a reply on Why We Test… The Two Other Tests I’m Forgetting To Write

I know it's great! Total *ss saver :)

dancourse started a new conversation Why We Test… The Two Other Tests I’m Forgetting To Write

Hey Laracast peeps,

Just thought I'd share a couple of my simple testing thoughts. If I'd have written more thorough tests in my last sprint, it would have saved me like a few hours this morning. Hence why I'm sharing!

http://www.dancourse.co.uk/2015/07/why-we-test-the-two-other-tests-im-forgetting-to-write/

Any comments gladly received!

All the best,

DanC

17 Jun
3 years ago

dancourse left a reply on Middlware Logic Set To Manage Routes

Thanks @pmall for responding

09 Jun
3 years ago

dancourse started a new conversation Middlware Logic Set To Manage Routes

Ola' lara-peeps,

I have some routes that need to be covered by Middleware 'logic' to check if they're IsAdmin OR (IsProjectEditor && IsMyProject)

Is there a way of setting that up in Laravel with the routes.php?

    Route::group(['middleware'=>'IsAdmin || (IsProjectEditor && IsMyProject)'], function ()
    {
        Route::resource('project', 'ProjectController',       ['only' => ['edit', 'update']]);
    });

Thanks!

DanC

dancourse left a reply on Verify Item Ownership Middleware

Hey I just hit the same problem too.

I created a middleware class which I implement with the routes.php. Then I put the particular edit route to be covered by it. #HTH

    Route::group(['middleware'=>'IsMyProject'], function ()
    {
        Route::resource('project', 'ProjectController',       ['only' => ['edit', 'update']]);
    });
<?php namespace App\Http\Middleware;

// Custom Service for the App's particular needs
use App\Facades\Helper;
use App\Repositories\Interfaces\ProjectRepositoryInterface;
use Closure;
use Request;

class IsMyProjectMiddleware  {

    protected $projectRepo;

    public function __construct(ProjectRepositoryInterface $projectRepo)
    {
        $this->projectRepo = $projectRepo;
    }

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $project_id = Request::route()->parameter('project', null);

        $project = $this->projectRepo->findOrFail($project_id);

        if(true===Helper::isMyProject($project))
        {
            return $next($request);
        }

        $message = 'IsMyProjectMiddleware';
        return response(view('errors.not-authd', compact('message')), 403);
    }
}
01 Jun
3 years ago

dancourse left a reply on Save Logs Remotely To Logstash/graylog2

Hey @huglester

We've just installed logstash on a server to trial aggregating logs from our various e-learning laravel apps.

We've not got that far yet as I don't entirely understand the filters parts... like do we send 'syslog' messsage for a custom app error? Hoping this tool will be useful, http://grokdebug.herokuapp.com/patterns

Best, DanC

15 May
3 years ago

dancourse left a reply on ACL In Views

Cool, thanks @bestmomo so you find you can manage 1 view having different "internals" for different people?

14 May
3 years ago

dancourse started a new conversation ACL In Views

Hello Laravelliens,

How do you alter the view per. user role?

So, I'm using ACL in Middleware to restrict down routes. However, some routes are shared, ie. "project.create" so an admin can create a project and select which user owns it. But also, so can a standard muggle create a project, however they are automatically selected as the user.

So, the Admin user needs a select2 box of all the users on the form, however the muggle has a hidden field with their id in (and then validated with the Request Object that it's them...).

Do you create 2 views, one for each? Or do you let the view alter what to show based on the Auth'd user?

Cheers!

Dan Course

05 May
3 years ago

dancourse left a reply on Laravel 5.1 Commands To Jobs

Well explained, thank you very much.

DanC

dancourse started a new conversation Laravel 5.1 Commands To Jobs

Apparently, "Commands" are being re-named "Jobs" which for me is a bit confusing. I've been using Commands to create complex Models. ie, A user with related properties and models.

But as a "Job" it wouldn't quite make sense. Would this be better using a "Service Class" for creating the complex Users or is it actually a "Job"?

Any thoughts greatly appreciated,

dpc

01 May
3 years ago

dancourse started a new conversation Testing Strategy With Behat And UnitTests Separate...

Good morning,

I've got behat 3 working with Laravel 5, hurrah. However, now I've hit a confuddle as I gave Behat tests and PHPUnit tests separate?

So I've come to a feature, you can only ever add a new user to the system, if their University Id is unique. Would you write a Unit test to check the "create" command asserts the uniqueness, an acceptance test that the form won't allow you through or maybe a test on the FormRequest object!?!?

Thanks, any thoughts and theory appreciated :)

Best,

DanC

17 Apr
3 years ago

dancourse started a new conversation A Repo Per. Model, Or Per. Feature?

Ola' Laravelians',

So how do you structure your Repositories? Do you create one (and its Interface obv.) per. Model, like UserRepository, PostRepository and CommentRepository OR do you create one per. feature set, UserRepository and BlogRepository?

I've been doing per. Model, however I'm coming unstuck when I'm creating calls that cross more models. Like if I want to see all blog posts from a user, does it go in UserRepo->blogPosts() or Blog->usersPosts()?

Thanks again,

DanC

02 Apr
3 years ago

dancourse left a reply on Testing With Providers

So figured it, it's not really a Laravel question! It's more just PHPUnit, der... so it's exactly the same!

Here's a simple Gist to get anyone else started :)

https://gist.github.com/dancourse/5ee17a596223c10d5648

`class ScoringTest extends TestCase { /** * Some Grades */ public static function all_grades_provider() { return [ [100.00], [50.00], [0], ]; }

/**
 * Grade checks
 * @dataProvider   all_grades_provider
 * @return void
 */
public function test_grade_score_is_correct ($grade)
{
    // test our total is correct
    $this->assertEquals($grade, Score::someFunctionWhichAffectsGrade($grade));      
}

}`

30 Mar
3 years ago

dancourse started a new conversation Testing With Providers

Hello lara-lot,

Is there a laracast, blog post which describes how to run the same test but with different provided data?

I've come from a Zend Framework background where I'd write 1 test and set it up with a provider array. It would then run that test on ALL array items separately so I could test on something like price fails on 50, 60, and 70 with the same test.

Thanks in advance,

dpc

20 Feb
4 years ago

dancourse left a reply on Make A Throw New Not Stop Execution...

Thanks @deringer you're right. I had a moment last night where I face palmed and realised, I'm meant to catch it!

19 Feb
4 years ago

dancourse started a new conversation Make A Throw New Not Stop Execution...

Ola Lara-lovers,

This may be really obvious but I'm missing something,

When I run a command in the console, I want it to report a certain type of Exception has occurred, but not stop the execution.

But the throw new is causing the whole thing to stop? Maybe I'm tired and it's meant to, but I how do I make the exception less "IT'S ALL BROKE!!" and more, "oh this wasn't right, but we can carry on"

Thanks!

DanC


public function handle()
{
    $headersAll = array(1,2,3,4);
    $row = array(1);
                    // checks this row has the same amount as the header row
                    if(count($headersAll)!==count($row))
                    {
                        throw new ColumnsDoNotMatchException($this->filename, $row);
                    }
}

<?php namespace App\Exceptions;

use Log;

class ColumnsDoNotMatchException extends \Exception {
    public function __construct($filename, $data)
    {
        Log::info('Column headers count does not match row column count', ['filename' => $filename, 'row' => $data]);
    }
}


06 Feb
4 years ago

dancourse started a new conversation Json Or Webvew

Ola' laraviens,

I feel like this is painfully obvious but I'm clearly missing a coding principle, laravel cleverness or design pattern here.

All I want to do is have the same routing resource work from either,

Route::resource('auctions', 'AuctionsController')

  • auctions/1' sends back the blade webview for auction:id:1
  • auctions/1.json sends back the json object

However, it's proving a right faf and I can't seem to nail one solution properly. So it's possible I'm trying to do something stupid!

Thanks,

DanC

26 Jan
4 years ago

dancourse left a reply on Form Validation On Array

Cool thanks again

20 Jan
4 years ago

dancourse left a reply on Form Validation On Array

Great thanks all, so work arounds seem the best method. I may put something into the Laravel Feature requests and see if anyone else wants it

19 Jan
4 years ago

dancourse started a new conversation Form Validation On Array

Good afternoon Lara-lovers,

Anyone managed to handle an array validation with ANY id? Often you don't explicitly know the id you're validating.

```` @foreach ($auction->items as $auctionItem)

<input type="text" name="auctionItem[{{ $auctionItem->id }}]" />

@endforeach

<?php namespace Forms;

class CreateBidForm extends FormValidator {

/**
 * Validation rules for creating a new bid
 *
 * @var array
 */
protected $rules = [
        'auctionItem.#'     => array('numeric')
];

} ```

dancourse left a reply on Add Ruby To The Homestead Installed Packages

Nice one, thanks all for your help

13 Jan
4 years ago

dancourse started a new conversation Add Ruby To The Homestead Installed Packages

Good afternoon Lara-lovers,

My present app uses ruby and sass to compile, my er... SASS! However it's not in the default list of packages which are installed with Homestead.

Is there a way to amend the list of apps which homestead will install, or should I just include a ruby install with the setup/install script for the site?

Thanks,

DanC

09 Jan
4 years ago

dancourse started a new conversation Homestead And Phpunit, "The Program 'phpunit' Is Currently Not Installed"

Hi forum-ites,

I've got homestead working and it's great, however when I try to run my unit tests inside the homestead ssh with, phpunit they aren't running and it says.

"The program 'phpunit' is currently not installed"

Anyone seen this before? I've tried running "composer install --dev" and phpunit is definitely inside the vendor folder.

Thanks again,

DanC

dancourse left a reply on Basic PHP Question - Public Static Function()

We should probably copy StackOverflow's guidelines and any external links to materials, we should CP&Paste the material in, which protects us against another site disco-pearing!

http://verraes.net/2014/06/when-to-use-static-methods-in-php/

Some of the reactions to my last blog post on Named Constructors in PHP, originate from the notion that static methods are inherently bad and should never be used. This is rather overgeneralized.

Static methods are nothing more than namespaced global functions. Namespacing, I think we can all agree on, is great. As for global functions: We use those all the time. The native functions in PHP form our basic building blocks.

The problem to consider is shared global state. The example that I gave in my previous post, is referentially transparent:

<?php
$time = Time::from("11:45");

In other words, it is stateless, it is free of side effects, and as such, it is entirely predictable. You can call the exact same function with the exact same argument as often as you like, and you will always get the exact same result back (a Time instance with value 11:45), no matter the history of the system, no matter the context from which you call it.

Another example:

<?php $sum = Calculator::sum(1, 2);

Again, the outcome is predictable. Calculator::sum($x, $y) provides a service that is stateless, that doesn’t remember anything, and whose outcome can’t be influenced by anything other than the arguments you put in there. Furthermore, this service will never have polymorphic, or have different implementations. Returning anything other 3 would break the contract. Of course, you could come up with a more efficient algorithm for adding to numbers, but that would have no effect on any of the clients of Calculator.

For a counterexample, let’s look at a stateful service:

<?php Counter::increment(1); $count = Counter::getCount();

This is of course a simple example, but in more complex situations, it can be rather opaque to understand this statefullness. Imagine that one developer use the Counter in one part of the code, and another developer uses it in another part. They both test their code in isolation, and it works fine. As soon as the parts are integrated, the count becomes erratic, because they both share the same global state, instead of each owning a separate Counter. The solution is to have objects here:

<?php $myCounter = new Counter; $myCounter->increment(1); $count = $myCounter->getCount();

Abstractions You might still feel resistance against something like Calculator::sum($x, $y), because it can not be extended or mocked. Keep in mind however that we are at the lowest level of abstraction here. You can’t extend or mock the + operator either in PHP. Yet you’ve never felt the need for that. If you do need higher levels of abstraction, then composition is your friend. OOP composition is well known, but let’s look at FP really quickly. There is, in PHP, an interesting distinction between + and Calculator::sum($x, $y): the former can not be injected, the latter can:

<?php $result = array_reduce([1,2,3], 'Calculator::sum', 0); // $result = 6

I’m getting in the realm of higher-order programming now, which is rather out of scope, but let’s just agree that functions and static methods can be very useful, with the right mindset.

dancourse left a reply on Form Validation Or Model Validation?

I realise I was totally struggling with trying to make one size fit all, however, most forms are not 1:1 with the model. @jeff_way should totally do a vid on that. Maybe he would cover validating relations too, that was something I spent ages searching for when I first started on the "digging in" series. Cheers again.

dancourse left a reply on Form Validation Or Model Validation?

Holy cow this is a good forum! Thanks for your help all, everyone had some very good insight.

08 Jan
4 years ago

dancourse left a reply on See Watched History

Hurrah, thanks bud.

dancourse started a new conversation See Watched History

Not sure if I've missed a button, however I was watching a video yesterday and would really like to find it again as I didn't favourite.

Is there a History hidden anywhere of vid's I've watched?

Thanks!

DanC

dancourse started a new conversation Form Validation Or Model Validation?

So I've got a model with rules written into it. Should I be using those to validate form entry or creating a whole other Form Validation class to carry out the validation per. form?

Thanks!

DanC

public static $rules = [
        'name'      => array('required', 'min:5', 'max:30'),
        'email'     => array('required', 'min:5', 'max:90', 'email', 'unique:users'),
        'password'  => array('required', 'min:5', 'max:30'),
        'regions'   => 'max:4'
    ];